スマートコンセント(富士通 FX-5204PS)をIEEE1888 StorageにWRITEするサンプルプログラムです。
Dependencies: EthernetInterface FiapV2 HTTPClientForSOAP NTPClient TextLCD mbed-rtos mbed spxml
Fork of BlueUSB_f by
main.cpp
00001 /* 00002 Copyright (c) 2010 Peter Barrett 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 #ifndef OS_TICK 00023 #define OS_TICK 50000 00024 #endif 00025 #include "USBHost.h" 00026 #include "Utils.h" 00027 #include "TextLCD.h" 00028 #include "EthernetInterface.h" 00029 #include "NTPClient.h" 00030 #include "fiap.h" 00031 #include "mbed.h" 00032 00033 //#define NTPServer "ntp.nict.jp" 00034 #define NTPServer "ntp.cc.yamaguchi-u.ac.jp" 00035 00036 EthernetInterface eth; 00037 NTPClient ntp; 00038 Ticker timer1; 00039 time_t ctTime; 00040 char timezone[] = "+09:00"; // JST 00041 char atemp1[6],atemp2[6],avolt1[6],avolt2[6],afreq1[6],afreq2[6]; 00042 char apower_a1[6],apower_a2[6],apower_b1[6],apower_b2[6],apower_c1[6],apower_c2[6],apower_d1[6],apower_d2[6]; 00043 char atemp[6],avolt[6],afreq[6], apower1[6],apower2[6],apower3[6],apower4[6]; 00044 FIAP fiap("http://192.168.1.3/axis2/services/FIAPStorage"); 00045 struct fiap_element element[]= { 00046 {"http://www.gutp.jp/SmartTap1/temp",atemp1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00047 {"http://www.gutp.jp/SmartTap1/volt",avolt1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00048 {"http://www.gutp.jp/SmartTap1/freq",afreq1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00049 {"http://www.gutp.jp/SmartTap1/watt_1",apower_a1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00050 {"http://www.gutp.jp/SmartTap1/watt_2",apower_b1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00051 {"http://www.gutp.jp/SmartTap1/watt_3",apower_c1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00052 {"http://www.gutp.jp/SmartTap1/watt_4",apower_d1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00053 {"http://www.gutp.jp/SmartTap2/temp",atemp2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00054 {"http://www.gutp.jp/SmartTap2/volt",avolt2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00055 {"http://www.gutp.jp/SmartTap2/freq",afreq2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00056 {"http://www.gutp.jp/SmartTap2/watt_1",apower_a2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00057 {"http://www.gutp.jp/SmartTap2/watt_2",apower_b2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00058 {"http://www.gutp.jp/SmartTap2/watt_3",apower_c2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00059 {"http://www.gutp.jp/SmartTap2/watt_4",apower_d2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00060 {"http://www.gutp.jp/SmartTap1/temp",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00061 {"http://www.gutp.jp/SmartTap1/volt",avolt,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00062 {"http://www.gutp.jp/SmartTap1/freq",afreq,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00063 {"http://www.gutp.jp/SmartTap1/watt_1",apower1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00064 {"http://www.gutp.jp/SmartTap1/watt_2",apower2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00065 {"http://www.gutp.jp/SmartTap1/watt_3",apower3,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00066 {"http://www.gutp.jp/SmartTap1/watt_4",apower4,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, 00067 }; 00068 00069 /* 00070 Simple test shell to exercise mouse,keyboard,mass storage and hubs. 00071 Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it. 00072 */ 00073 00074 Serial pc(USBTX, USBRX); 00075 int GetConsoleChar() 00076 { 00077 if (!pc.readable()) 00078 return -1; 00079 char c = pc.getc(); 00080 pc.putc(c); // echo 00081 return c; 00082 } 00083 void InitUSPS(); 00084 void USPS_Refresh(); 00085 DigitalOut led1(LED1); 00086 DigitalOut led2(LED2); 00087 DigitalOut led3(LED3); 00088 DigitalOut led4(LED4); 00089 Timer t; 00090 Timer t2; 00091 Timer t3; 00092 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00093 extern float WattData1[],WattData2[],WattData3[],WattData4[]; 00094 extern int SerialNo[]; 00095 extern float TempData[]; 00096 extern float VoltData[]; 00097 extern float FreqData[]; 00098 int main() 00099 { 00100 int i; 00101 lcd.cls(); 00102 lcd.printf("Watting...."); 00103 00104 pc.baud(460800); 00105 00106 eth.init(); //Use DHCP 00107 eth.connect(); 00108 printf("%s", eth.getIPAddress()); 00109 printf("Trying to update time...\r\n"); 00110 if (ntp.setTime(NTPServer) == 0) { 00111 printf("Set time successfully\r\n"); 00112 time_t ctTime; 00113 ctTime = time(NULL); 00114 ctTime+=32400; 00115 set_time(ctTime); 00116 ctTime = time(NULL); 00117 printf("Time is set to (JST): %s\r\n", ctime(&ctTime)); 00118 printf("finish \n"); 00119 } else { 00120 lcd.locate(0,1); 00121 lcd.printf("Error"); 00122 return -1; 00123 } 00124 00125 InitUSPS(); 00126 USBInit(); 00127 fiap.debug_mode=1; 00128 t.start(); 00129 t2.start(); 00130 t3.start(); 00131 while(1) { 00132 USBLoop(); 00133 if(t>0.1 ) { 00134 t.start(); 00135 led4=!led4; 00136 USPS_Refresh(); 00137 } 00138 if(t2>1) { //Data to LCDText 00139 t2.start(); 00140 if(SerialNo[0]==0)led1=0;else led1=1; 00141 if(SerialNo[1]==0)led2=0;else led2=1; 00142 lcd.locate(0,0); 00143 lcd.printf("1:%4.0fW 2:%4.0fW",WattData1[0],WattData2[0]); 00144 lcd.locate(0,1); 00145 lcd.printf("3:%4.0fW 4:%4.0fW",WattData3[0],WattData4[0]); 00146 } 00147 if(t3>60) { //Data to FiapStorage 00148 led3=1; 00149 t3.start(); 00150 char buffer[9]; 00151 ctTime = time(NULL); 00152 strftime(buffer,9,"%X",localtime(&ctTime)); 00153 printf("Storage Store %s \r\n",buffer); 00154 // Save to FIAPStorage 00155 struct tm t = *localtime(&ctTime); 00156 for(i=0; i<14; i++) { 00157 element[i].year=t.tm_year+1900; 00158 element[i].month=t.tm_mon+1; 00159 element[i].day=t.tm_mday; 00160 element[i].hour=t.tm_hour; 00161 element[i].minute=t.tm_min; 00162 element[i].second=t.tm_sec; 00163 } 00164 for(i=0; i<2; i++) { 00165 switch(SerialNo[i]) { 00166 case 0x1737: 00167 sprintf(atemp1,"%4.1f",TempData[i]); 00168 sprintf(avolt1,"%4.1f",VoltData[i]); 00169 sprintf(afreq1,"%4.1f",FreqData[i]); 00170 sprintf(apower_a1,"%4.0f",WattData1[i]); 00171 sprintf(apower_b1,"%4.0f",WattData2[i]); 00172 sprintf(apower_c1,"%4.0f",WattData3[i]); 00173 sprintf(apower_d1,"%4.0f",WattData4[i]); 00174 break; 00175 case 0x1871: 00176 sprintf(atemp2,"%4.1f",TempData[i]); 00177 sprintf(avolt2,"%4.1f",VoltData[i]); 00178 sprintf(afreq2,"%4.1f",FreqData[i]); 00179 sprintf(apower_a2,"%4.0f",WattData1[i]); 00180 sprintf(apower_b2,"%4.0f",WattData2[i]); 00181 sprintf(apower_c2,"%4.0f",WattData3[i]); 00182 sprintf(apower_d2,"%4.0f",WattData4[i]); 00183 break; 00184 } 00185 } 00186 fiap.post(element,14); 00187 led3=0; 00188 00189 } 00190 } 00191 }
Generated on Tue Jul 12 2022 22:55:45 by
1.7.2
