講習会用です

Dependencies:   EthernetInterface FiapV2 HTTPClientForSOAP NTPClient TextLCD mbed-rtos mbed spxml

Fork of temp_FIAP by Yasushi TAUCHI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "EthernetInterface.h"
00004 #include "NTPClient.h"
00005 #include "fiap.h"
00006 
00007 #define NTPServer "ntp.nict.jp"
00008 
00009 EthernetInterface eth;
00010 NTPClient ntp;
00011 Ticker timer1;
00012 time_t ctTime;
00013 
00014 TextLCD lcd(p24, p26, p27, p28, p29, p30);
00015 AnalogIn ain(p20);
00016 DigitalOut led(LED1);
00017 char timezone[] = "+09:00";  // JST
00018 char atemp[6];
00019 FIAP fiap("http://fiap-sandbox.gutp.ic.i.u-tokyo.ac.jp/axis2/services/FIAPStorage");
00020 struct fiap_element element[]= {
00021     {"http://giken9.jp/no_0/temp",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
00022 };
00023 
00024 
00025 void tick(void )
00026 {
00027     float temp;
00028     char buffer[9];
00029     led=!led;
00030     temp=ain*3.3*100.0;
00031     ctTime = time(NULL);
00032     strftime(buffer,9,"%X",localtime(&ctTime));
00033     lcd.locate(0,1);
00034     lcd.printf("%s %4.1fDeg",buffer,temp);
00035 // Save to FIAPStorage
00036     sprintf(atemp,"%4.1f",temp);
00037     struct tm t = *localtime(&ctTime);
00038     element[0].value=atemp;
00039     element[0].year=t.tm_year+1900;
00040     element[0].month=t.tm_mon+1;
00041     element[0].day=t.tm_mday;
00042     element[0].hour=t.tm_hour;
00043     element[0].minute=t.tm_min;
00044     element[0].second=t.tm_sec;
00045     fiap.post(element,1);
00046 }
00047 
00048 int main()
00049 {
00050 //Ethernet Initialize
00051     eth.init(); //Use DHCP
00052     eth.connect();
00053     lcd.cls();
00054     lcd.locate(0,0);
00055     lcd.printf("%s", eth.getIPAddress());
00056     printf("Trying to update time...\r\n");
00057     if (ntp.setTime(NTPServer) == 0) {
00058         printf("Set time successfully\r\n");
00059         time_t ctTime;
00060         ctTime = time(NULL);
00061         ctTime+=32400;
00062         set_time(ctTime);
00063         ctTime = time(NULL);
00064         printf("Time is set to (JST): %s\r\n", ctime(&ctTime));
00065         printf("finish \n");
00066     } else {
00067         lcd.locate(0,1);
00068         lcd.printf("Error");
00069         return -1;
00070     }
00071     //fiap.debug_mode=true;
00072     //eth.disconnect();
00073     while(true) {
00074         tick();
00075         wait(60);
00076     }
00077 }