Code for an ethernet-enabled mbed that calls to a web api, and reasons with JSON resonses
Dependencies: NetServices RPCInterface mbed picojson xbee_api
Diff: main.cpp
- Revision:
- 2:86f64948da0f
- Parent:
- 1:7485d913aaf5
- Child:
- 3:2f263c4517e2
--- a/main.cpp Sat Jan 25 16:57:03 2014 +0000 +++ b/main.cpp Sat Jan 25 22:15:06 2014 +0000 @@ -4,6 +4,8 @@ #include "NTPClient.h" #include "HTTPServer.h" #include "RPCFunction.h" +#include "HTTPResult.h" + #define HOSTNAME "HUB-01" @@ -13,10 +15,6 @@ using namespace std; -class device -{ -} - int main() { @@ -37,7 +35,23 @@ IpAddr ethIp = eth.getIp(); printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]); - printf("Check router DHCP table for name : %s\n", eth.getHostname()); + + //the hub will register itself with the server + HTTPMap msg; + + + HTTPResult r1 = http.post("192.168.0.4:3000/hubconnect?h_id=mbed&h_name=ADAM&h_ip=192.168.0.1",msg,NULL); + if( r1 == HTTP_OK ) + { + printf("Hub %s registered with server\n", HOSTNAME); + } + else + { + printf("Couls not register, error : %d\n", r1); + } + + + printf("\nHTTPClient get...\n"); HTTPText txt; @@ -45,7 +59,7 @@ if (r==HTTP_OK) { printf("Result ok : %s\n", txt.gets()); } else { - printf("Error %d\n", r); + printf("Error %s\n", txt.gets()); }