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: C12832_lcd EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Diff: MBEDEndpoint.cpp
- Revision:
- 19:956b694f6542
- Parent:
- 18:214698dbcdfa
- Child:
- 21:d1ce325d1d32
--- a/MBEDEndpoint.cpp Thu Feb 27 07:11:53 2014 +0000
+++ b/MBEDEndpoint.cpp Thu Feb 27 07:47:20 2014 +0000
@@ -197,20 +197,21 @@
// DEBUG
this->logger()->log("Sending Light: %s to the IOC...",light->getName());
-
- return true;
-
+
// issue the request
success = this->m_transports[LOAD_TRANSPORT]->loadEndpoint((char *)payload,strlen(payload),(char *)result,IOC_RESULT_LEN);
// DEBUG
- this->logger()->log("Saving IOC ID for Light: %s...",light->getName());
+ if (success) this->logger()->log("Saving IOC ID for Light: %s...",light->getName());
// update the IOC ID if found
if (success) this->saveIOCID(result);
// DEBUG
- this->logger()->log("Light: %s IOC ID=%d...",light->getName(),this->getIOCID());
+ if (success) this->logger()->log("Light: %s IOC ID=%d...",light->getName(),this->getIOCID());
+
+ // DEBUG
+ if (!success) this->logger()->log("Loading Light: %s FAILED",light->getName());
// return our status
return success;
@@ -255,7 +256,10 @@
ResourceFactory *factory = light->getResourceFactory();
// JSON factory
- MbedJSONValue json_generator;
+ //MbedJSONValue json_generator;
+
+ // accumulator string
+ std::string str_json("{");
// loop through the resources and build a JSON representation for the payload
for(int i=0;i<factory->numResources();++i) {
@@ -265,24 +269,38 @@
// add to the JSON payload
char *name = this->getMap()->endpointNameToIOCName(resource->getName());
char *value = resource->getValue();
- std::string str_name(name);
- std::string str_value(value);
- this->logger()->log("Name: %s Value: %s",str_name.c_str(),str_value.c_str());
- json_generator[str_name] = str_value;
+ // Skip Location
+ if (strcmp(name,"LOCATION") != 0) {
+ std::string str_name(name);
+ std::string str_value(value);
+
+ this->logger()->log("Name: %s Value: %s",str_name.c_str(),str_value.c_str());
+ //json_generator[str_name] = str_value;
+
+ str_json += std::string("\"") + str_name + std::string("\":\"") + str_value + std::string("\"");
+
+ if (i<(factory->numResources()-1)) str_json += std::string(",");
+ }
}
// Special Case: STARTDATETIME
- json_generator["STARTDATETIME"] = "2014-02-27T03:35:55.940Z";
+ //json_generator["STARTDATETIME"] = "2014-02-27T03:35:55.940Z";
+ str_json += std::string("\"STARTDATETIME\":\"2014-02-27T03:35:55.940Z\"");
// Special Case: ENDDATETIME
- json_generator["ENDDATETIME"] = "2017-02-27T03:35:55.940Z";
+ //json_generator["ENDDATETIME"] = "2017-02-27T03:35:55.940Z";
+ str_json += std::string("\"ENDDATETIME\":\"2015-02-27T03:35:55.940Z\"");
// Speical Case: LOCATION
- json_generator["LOCATION"] = "Point(65.017210,25.492411)";
+ //json_generator["LOCATION"] = "Point(65.017210,25.492411)";
+ str_json += std::string("\"LOCATION\":\"Point(65.017210,25.492411)\"");
+
+ // complete
+ str_json += std::string("}");
// now convert to JSON
- std::string str_json = json_generator.serialize();
+ //std::string str_json = json_generator.serialize();
// copy over to the buffer
strncpy(data,str_json.c_str(),this->min(str_json.length(),data_length));
@@ -299,6 +317,8 @@
// JSON factory
MbedJSONValue parser;
+ this->logger()->log("Load Result: %s",json);
+
// parse the result
parse(parser,json);