temp_FIAP porting to FRDM-K64F
Dependencies: C12832 EthernetInterface FiapV2 HTTPClientForSOAP LM75B NTPClient mbed-rtos mbed spxml
Fork of temp_FIAP by
main.cpp
00001 #include "mbed.h" 00002 //#include "TextLCD.h" 00003 #include "C12832.h" 00004 #include "LM75B.h" 00005 00006 00007 #include "EthernetInterface.h" 00008 #include "NTPClient.h" 00009 #include "fiap.h" 00010 00011 #define NTPServer "ntp.nict.jp" 00012 00013 EthernetInterface eth; 00014 NTPClient ntp; 00015 Ticker timer1; 00016 time_t ctTime; 00017 00018 //TextLCD lcd(p24, p26, p27, p28, p29, p30); 00019 // Using Arduino pin notation 00020 C12832 lcd(D11, D13, D12, D7, D10); 00021 //AnalogIn ain(p15); 00022 DigitalOut led(LED1); 00023 LM75B sensor(D14,D15); 00024 00025 char timezone[] = "+09:00"; // JST 00026 char atemp[6]; 00027 FIAP fiap("http://192.168.1.3/axis2/services/FIAPStorage"); 00028 struct fiap_element element[]= { 00029 {"http://csse-tech.jp/temp_tauchi",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00030 }; 00031 00032 00033 void tick(void ) 00034 { 00035 float temp; 00036 char buffer[9]; 00037 led=!led; 00038 // temp=ain*3.3*100.0; 00039 temp=sensor.temp(); 00040 ctTime = time(NULL); 00041 strftime(buffer,9,"%X",localtime(&ctTime)); 00042 lcd.locate(0,1); 00043 lcd.printf("%s %4.1fDeg",buffer,temp); 00044 // Save to FIAPStorage 00045 sprintf(atemp,"%4.1f",temp); 00046 struct tm t = *localtime(&ctTime); 00047 element[0].value=atemp; 00048 element[0].year=t.tm_year+1900; 00049 element[0].month=t.tm_mon+1; 00050 element[0].day=t.tm_mday; 00051 element[0].hour=t.tm_hour; 00052 element[0].minute=t.tm_min; 00053 element[0].second=t.tm_sec; 00054 fiap.post(element,1); 00055 } 00056 00057 int main() 00058 { 00059 //Ethernet Initialize 00060 eth.init(); //Use DHCP 00061 eth.connect(); 00062 lcd.cls(); 00063 lcd.locate(0,0); 00064 lcd.printf("%s", eth.getIPAddress()); 00065 printf("Trying to update time...\r\n"); 00066 if (ntp.setTime(NTPServer) == 0) { 00067 printf("Set time successfully\r\n"); 00068 time_t ctTime; 00069 ctTime = time(NULL); 00070 ctTime+=32400; 00071 set_time(ctTime); 00072 ctTime = time(NULL); 00073 printf("Time is set to (JST): %s\r\n", ctime(&ctTime)); 00074 printf("finish \n"); 00075 } else { 00076 lcd.locate(0,1); 00077 lcd.printf("Error"); 00078 return -1; 00079 } 00080 //fiap.debug_mode=true; 00081 //eth.disconnect(); 00082 while(true) { 00083 tick(); 00084 wait(2); 00085 } 00086 }
Generated on Sun Jul 24 2022 08:11:39 by 1.7.2