Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetServices RPCInterface mbed picojson xbee_api
Revision 3:2f263c4517e2, committed 2014-01-26
- Comitter:
- ammanvedi
- Date:
- Sun Jan 26 11:12:36 2014 +0000
- Parent:
- 2:86f64948da0f
- Child:
- 4:fe02d3c20559
- Commit message:
- v1
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jan 25 22:15:06 2014 +0000
+++ b/main.cpp Sun Jan 26 11:12:36 2014 +0000
@@ -4,10 +4,14 @@
#include "NTPClient.h"
#include "HTTPServer.h"
#include "RPCFunction.h"
-#include "HTTPResult.h"
+#include <sstream>
+
#define HOSTNAME "HUB-01"
+#define DEVICENAME "ADAM"
+
+
EthernetNetIf eth(HOSTNAME);
HTTPClient http;
@@ -36,18 +40,26 @@
IpAddr ethIp = eth.getIp();
printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
+ char ip_buffer[20];
+ sprintf(ip_buffer, "%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
+
//the hub will register itself with the server
HTTPMap msg;
-
+
+ stringstream url;
+ url << "192.168.0.4:3000/hubconnect?h_id=" << HOSTNAME << "&h_name=" << DEVICENAME << "&h_ip=" << ip_buffer;
+ const std::string uri = url.str();
+
+ printf("query server : %s \n", uri);
- HTTPResult r1 = http.post("192.168.0.4:3000/hubconnect?h_id=mbed&h_name=ADAM&h_ip=192.168.0.1",msg,NULL);
+ HTTPResult r1 = http.post(uri.c_str(),msg,NULL);
if( r1 == HTTP_OK )
{
- printf("Hub %s registered with server\n", HOSTNAME);
+ printf("Hub %s registered with server (code : %d )\n", HOSTNAME, r1);
}
else
{
- printf("Couls not register, error : %d\n", r1);
+ printf("Could not register, error : %d\n", r1);
}
@@ -57,7 +69,7 @@
HTTPText txt;
HTTPResult r = http.get("192.168.0.4:3000/devices", &txt);
if (r==HTTP_OK) {
- printf("Result ok : %s\n", txt.gets());
+ printf("Result ok : %s (code : %d )\n", txt.gets(), r);
} else {
printf("Error %s\n", txt.gets());
}