sho hashimoto
/
sensor_http_post
posted data are here => http://shokai.mag.keio.ac.jp/sensor-storage/shokai/cds/recent
Revision 0:969bf1c3d310, committed 2010-04-24
- Comitter:
- shokai
- Date:
- Sat Apr 24 16:01:03 2010 +0000
- Child:
- 1:f2d0019c7d6f
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Sat Apr 24 16:01:03 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/lwip/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Apr 24 16:01:03 2010 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "HTTPClient.h" +#include <string> +using namespace std; + +Serial pc(USBTX, USBRX); + +DigitalOut led1(LED1); // blink +DigitalOut led2(LED2); // blink when http-post +DigitalOut led3(p11); // represent ADC value + +AnalogIn adc(p15); +float ain; + +HTTPClient http; // use DHCP + +const string api_uri = "http://shokai.mag.keio.ac.jp/sensor-storage/"; +const string mbed_name = "shokai-mbed01"; +const string sensor_name = "CdS"; + +void blink_led(DigitalOut led, int num){ + for(int i=0; i < num*2; i++){ + led = !led; + wait(0.1); + } +} + +void post_sensor_value(){ + blink_led(led2, 2); + char query[256] = ""; + char result[4096] = ""; // 4kb + sprintf(query, "name=%s&%s=%f", mbed_name.c_str(), sensor_name.c_str(), (float)ain); + pc.printf("post:%s => %s\n", query, api_uri.c_str()); + http.post(api_uri.c_str(), query, result, 4096); + pc.printf("%s\n", result); + blink_led(led2, 2); +} + +int main(void){ + led1 = 1; + int count = 0; + while(1) { + ain = adc; + pc.printf("sensor:%f\n", float(ain)); + led1 = !led1; // blink LED + if(ain > 0.1) led3 = 0; // represent CdS value + else led3 = 1; + if(count > 20){ + post_sensor_value(); + count = 0; + } + count++; + wait(0.5); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Apr 24 16:01:03 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0