WebAPIサンプルプログラム mbedセミナー演習5
Dependencies: EthernetNetIf TextLCD mbed HTTPClient_ToBeRemoved
Fork of WebAPI_test_ by
Revision 0:5fdf32706674, committed 2012-08-11
- Comitter:
- jksoft
- Date:
- Sat Aug 11 14:26:14 2012 +0000
- Commit message:
- Rev2
Changed in this revision
diff -r 000000000000 -r 5fdf32706674 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Sat Aug 11 14:26:14 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r 5fdf32706674 HTTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Sat Aug 11 14:26:14 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPClient_ToBeRemoved/#d0be6af2d1db
diff -r 000000000000 -r 5fdf32706674 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Sat Aug 11 14:26:14 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 5fdf32706674 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 11 14:26:14 2012 +0000 @@ -0,0 +1,83 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "TextLCD.h" +#include "HTTPClient.h" + +TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 + +EthernetNetIf eth; +HTTPClient http; + +int j_paser( const char *buf , char *word , char *out ) +{ + int i = 0; + char *p; + char _word[64] = "\"\0"; + + strcat(_word , word ); + strcat(_word , "\"" ); + + p = strstr( (char*)buf , _word ) + 2 + strlen(_word); + + while( (p[i] != ',')&&(p[i] != '\n') ) + { + out[i] = p[i]; + i++; + } + out[i] = '\0'; + + return(i); +} + +int main(void) { + + char year[32]; + char month[32]; + char day[32]; + char hour[32]; + char usage[32]; + char capacity[32]; + + EthernetErr ethErr = eth.setup(); + if(ethErr) + { + lcd.locate(0,0); + lcd.printf("Ethernet err."); + return(-1); + } + + lcd.locate(0,0); + lcd.printf("Getting info."); + + HTTPText txt; + + HTTPResult r = http.get("http://tepco-usage-api.appspot.com/latest.json", &txt); + + if(r==HTTP_OK) + { + j_paser(txt.gets() , "year" , year); + j_paser(txt.gets() , "month" , month); + j_paser(txt.gets() , "day" , day); + j_paser(txt.gets() , "hour" , hour); + j_paser(txt.gets() , "usage" , usage); + j_paser(txt.gets() , "capacity" , capacity); + + lcd.locate(0,0); + lcd.printf("%s/%s/%s %sh",year,month,day,hour); + lcd.locate(0,1); + lcd.printf("%s/%s %3.1f%%",usage,capacity,(((float)atoi(usage)/(float)atoi(capacity))*100.0)); + } + else + { + lcd.locate(0,0); + lcd.printf("Http get err."); + return(-1); + } + + while(1) + { + + } + + return(0); +}
diff -r 000000000000 -r 5fdf32706674 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Aug 11 14:26:14 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912 \ No newline at end of file