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:
- 21:d1ce325d1d32
- Parent:
- 19:956b694f6542
- Child:
- 22:f1002e5993c5
--- a/MBEDEndpoint.cpp Thu Feb 27 15:20:30 2014 +0000
+++ b/MBEDEndpoint.cpp Thu Feb 27 22:07:45 2014 +0000
@@ -254,10 +254,7 @@
char *MBEDEndpoint::buildIOCPayload(char *data,int data_length,Light *light) {
// construct the payload for Load/Updates
ResourceFactory *factory = light->getResourceFactory();
-
- // JSON factory
- //MbedJSONValue json_generator;
-
+
// accumulator string
std::string str_json("{");
@@ -270,38 +267,31 @@
char *name = this->getMap()->endpointNameToIOCName(resource->getName());
char *value = resource->getValue();
- // Skip Location
+ // Handle LOCATION a special way
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(",");
- }
+ str_json += "\"" + std::string(name) + "\":\"" + std::string(value) + "\",";
+ }
+ else {
+ // IOC expects "Point(X,Y)" for LOCATION
+ str_json += "\"" + std::string(name) + "\":\"Point(" + std::string(value) + ")\",";
+ }
}
// Special Case: STARTDATETIME
- //json_generator["STARTDATETIME"] = "2014-02-27T03:35:55.940Z";
- str_json += std::string("\"STARTDATETIME\":\"2014-02-27T03:35:55.940Z\"");
+ str_json += "\"STARTDATETIME\":\"2014-02-27T22:03:06.973Z\",";
// Special Case: ENDDATETIME
- //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)";
- str_json += std::string("\"LOCATION\":\"Point(65.017210,25.492411)\"");
+ str_json += "\"ENDDATETIME\":\"2015-02-27T03:35:55.940Z\",";
+
+ // Special Case: NAME
+ str_json += "\"NAME\":\"" + std::string(light->getName()) + "\",";
- // complete
- str_json += std::string("}");
+ // Special Case: TIMEZONEOFFSET
+ str_json += "\"TIMEZONEOFFSET\":\"+2:00\"";
- // now convert to JSON
- //std::string str_json = json_generator.serialize();
-
+ // close
+ str_json += "}";
+
// copy over to the buffer
strncpy(data,str_json.c_str(),this->min(str_json.length(),data_length));