Kansai Electric Power usage meter (Denki-yohou) for GainSpan Wi-Fi http://mbed.org/users/okini3939/notebook/denki-yohou/
Dependencies: mbed GSwifi (old)
Diff: main.cpp
- Revision:
- 1:beff52210994
- Parent:
- 0:d8a2cab7091c
- Child:
- 2:8646918ffff2
--- a/main.cpp Tue Jul 10 05:28:10 2012 +0000 +++ b/main.cpp Wed Sep 05 00:51:19 2012 +0000 @@ -4,8 +4,9 @@ #define HTTP_HOST "www.kepco.co.jp" #define HTTP_URI "/yamasou/juyo1_kansai.csv" -#define SSID "SSID" -#define PASS "pass1234567" +#define SSID "ROBOBA" +#define PASS "roboba1234567" +#define NTP_HOST "ntp1.sakura.ad.jp" #define VREF 3.3 #define B 3435 // thermistor B @@ -21,8 +22,8 @@ PwmOut led2(LED2), led3(LED3), led4(LED4); #elif defined(TARGET_LPC11U24) GSwifi gs(p9, p10, p21, p22); // TX, RX, CTS, RTS -DigitalOut gs_reset(P1_14), gs_wakeup(P1_3); -//DigitalOut gs_reset(p27), gs_wakeup(p28); +//DigitalOut gs_reset(P1_14), gs_wakeup(P1_3); +DigitalOut gs_reset(p15), gs_wakeup(p14); DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); #endif @@ -33,7 +34,7 @@ AnalogIn adtemp(p20); -void callback_http (int cid, int acid, int len) { +void callback_http (int cid, int len) { static int n = 0; // static char buf[1024], data[80]; static char buf[200], data[100]; @@ -101,7 +102,7 @@ } float get_temp () { - float ad, v, r, t; + float v, r, t; v = adtemp * VREF; r = v / ((VREF - v) / RU); @@ -117,8 +118,10 @@ int main() { int flg = 1, r; float denki_percentage = 0; - Host host; + Host host, ntp; int count = 0; + time_t time; + struct tm *t; initled(); #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) @@ -135,6 +138,11 @@ return -1; } + ntp.setName(NTP_HOST); + gs.ntpdate(ntp, 0); + wait(15); + gs.ntpdate(ntp, 3 * 60 * 60); + #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) pc.printf("Denki-yohou: %s\r\n", HTTP_HOST); #endif @@ -149,7 +157,7 @@ if (gs.getStatus() == GSSTAT_WAKEUP) { gs.wakeup(); } - + r = gs.httpGet(host, HTTP_URI, 0, &callback_http); if (r >= 0) { denki_percentage = (float)denki_usage / (float)denki_capacity * 100.0; @@ -172,17 +180,33 @@ } flg = 0; + wait(5); + time = gs.getTime() + (9 * 3600); + gs.standby(180000); } - count ++; - if (count > 4000) count = 0; // 10sec - if (count == 0) { // 0sec - writeled(denki_percentage * 100, 2, 0x0e); + // time + t = localtime(&time); + writeled(t->tm_hour * 100 + t->tm_min, 2, 0x0f, 0x0f); } else - if (count == 2000) { // 5sec - writeled(get_temp() * 10, 3, 0x07); + if (count > 0 && count < 4000) { + // time blink + if (count % 400 == 0) { // 0sec + writeled(t->tm_hour * 100 + t->tm_min, 2, 0x0f, 0x0f); + } else + if (count % 400 == 200) { // 0.1sec + writeled(t->tm_hour * 100 + t->tm_min, 0, 0x0f, 0x0f); + } + } else + if (count == 4000) { // 10sec + // denki yohou + writeled(denki_percentage * 100, 2, 0x0e, 0); + } else + if (count == 6000) { // 15sec + // temp. + writeled(get_temp() * 10, 3, 0x07, 0); } if (count % 400 == 0) { // 0sec @@ -190,8 +214,13 @@ } else if (count % 400 == 40) { // 0.1sec led1 = 0; + + time ++; } + count ++; + if (count >= 8000) count = 0; // 20sec + Sleep(); } }