mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/
Dependencies: EthernetNetIf SDHCFileSystem I2CLEDDisp Agentbed NTPClient_NetServices mbed BMP085 HTTPClient ConfigFile I2CLCD
Diff: main.cpp
- Revision:
- 1:86d4b7431fbe
- Parent:
- 0:4265d973a98f
- Child:
- 2:4125fe2283ef
--- a/main.cpp Fri Dec 10 17:15:15 2010 +0000 +++ b/main.cpp Mon Dec 13 15:28:59 2010 +0000 @@ -3,8 +3,9 @@ * Copyright (c) 2010 Hiroshi Suga * Released under the MIT License: http://mbed.org/license/mit */ -/** mbed Weather Platform - * @auther Suga koubou Co.,Ltd. + +/** @file + * @brief mbed Weather Platform */ #include "mbed.h" #include "BMP085.h" @@ -18,7 +19,6 @@ #include "HTTPClient.h" #define VERSION "mbed Weather Platform 0.1a (C) 2010 Suga koubou Co.,Ltd." -#define TIMEZONE 9 //#define NONBLOCKING @@ -26,7 +26,7 @@ int seq = 0; char filename[20]; ConfigFile conf; -DigitalOut led1(LED1), led2(LED2), led3(LED3); +DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); SDFileSystem sd(p5, p6, p7, p8, "sd"); // Sensors @@ -41,10 +41,15 @@ // Ethernet EthernetNetIf *eth; NTPClient *ntp; -HTTPClient *clientP; +HTTPClient *clientP, *clientT; DigitalOut led_g(p25), led_y(p26); DigitalIn eth_link(P1_25), eth_speed(P1_26); +void writefile (char *); +void pachube (char *); +void twitter (); +void ntpdate (); +int check_action (char); float get_photo (AnalogIn &ain) { float f; @@ -67,72 +72,27 @@ return f / 0.000384; // mW/cm2 } -void writefile (char *buf) { - FILE *fp; - - led3 = 1; - fp = fopen(filename, "a"); - if (fp) { - fprintf(fp, buf); - fclose(fp); - } else { - led2 = 0; - conf.filetype = 0; +void action (char *buf) { + if (check_action('H')) { +pc.putc('H'); + led4 = 1; } - led3 = 0; -} - -void cb_clientP (HTTPResult status) { - if (status != HTTP_OK) { - pc.printf("Pachube failure (%d)\r\n", status); -// pc.printf("Pachube failure (%d, %d)\r\n", status, clientP->getHTTPResponseCode()); + if (check_action('L')) { +pc.putc('L'); + led4 = 0; } -} - -void pachube (char *buf) { - char uri[100]; - HTTPText csvContent("text/csv"); - - led3 = 1; - clientP->setRequestHeader("X-PachubeApiKey", conf.pachube_apikey); - csvContent.set(buf); - strcpy(uri, "http://api.pachube.com/v1/feeds/"); - strcat(uri, conf.pachube_feedid); - strcat(uri, ".csv?_method=put"); -#ifdef NONBLOCKING - Net::poll(); - clientP->post(uri, csvContent, NULL, &cb_clientP); - Net::poll(); -#else - clientP->post(uri, csvContent, NULL); -#endif - led3 = 0; -} - -void cb_settime (NTPResult status) { - if (status == NTP_OK) { - time_t sec = time(NULL) + (60 * 60 * TIMEZONE); - set_time(sec); - pc.printf("Ntp success: %s\r\n", ctime(&sec)); - } else { - pc.printf("Ntp failure (%d)\r\n", status); + if (check_action('P')) { + if (conf.ipaddr[0] && conf.pachube_apikey[0] && conf.pachube_feedid[0]) { +pc.putc('P'); + pachube(buf); + } } -// ntp->close(); -} - -void ntpdate () { - ntp = new NTPClient; - Host ntpserver(IpAddr(), 123, conf.ntpserver); - -#ifdef NONBLOCKING - Net::poll(); - ntp->setTime(ntpserver, &cb_settime); - Net::poll(); -#else - ntp->setTime(ntpserver); - time_t sec = time(NULL) + (60 * 60 * TIMEZONE); - set_time(sec); -#endif + if (check_action('T')) { + if (conf.ipaddr[0] && conf.twitter_user[0] && conf.twitter_pwd[0]) { +pc.putc('T'); + twitter(); + } + } } void init () { @@ -174,6 +134,7 @@ if (conf.ipaddr[0]) { clientP = new HTTPClient; + clientT = new HTTPClient; } } @@ -203,7 +164,6 @@ } int main () { - int i; Timer timer; time_t sec; char buf[100]; @@ -261,18 +221,9 @@ // csv writefile(buf); } + + action(&buf[20]); /* - if (actionscount) { - // pin action - i = check_action(); - if (i == 0) { - outpin = 0; - } else - if (i == 1) { - outpin = 1; - } - } -*/ if (conf.ipaddr[0]) { if (conf.pachube_apikey[0] && conf.pachube_feedid[0]) { // pachube @@ -280,9 +231,10 @@ } if (conf.twitter_user[0] && conf.twitter_pwd[0]) { // twitter +// twitter(); } } - +*/ led1 = 1; while (timer.read() < conf.interval) {