MBED_DEMOS / Mbed 2 deprecated mbed_mqtt_endpoint_nxp

Dependencies:   C12832_lcd EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed

Revision:
18:214698dbcdfa
Parent:
17:84ab108ed670
Child:
19:956b694f6542
--- a/MBEDEndpoint.cpp	Thu Feb 27 06:28:42 2014 +0000
+++ b/MBEDEndpoint.cpp	Thu Feb 27 07:11:53 2014 +0000
@@ -31,6 +31,7 @@
  
  // JSON serialization support
  #include "MbedJSONValue.h"
+ #include <string>
  
  // shutdown endpoint reference
  extern void closedown(int code);
@@ -254,7 +255,7 @@
      ResourceFactory *factory = light->getResourceFactory();
       
      // JSON factory
-     MbedJSONValue json;
+     MbedJSONValue json_generator;
      
      // loop through the resources and build a JSON representation for the payload
      for(int i=0;i<factory->numResources();++i) {
@@ -263,26 +264,31 @@
          
          // 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",name,resource->getValue());
-         
-         json[name] = resource->getValue();
+         this->logger()->log("Name: %s Value: %s",str_name.c_str(),str_value.c_str());
+         json_generator[str_name] = str_value;
      }
      
      // Special Case: STARTDATETIME
+     json_generator["STARTDATETIME"] = "2014-02-27T03:35:55.940Z";
      
      // Special Case: ENDDATETIME
+     json_generator["ENDDATETIME"] = "2017-02-27T03:35:55.940Z";
      
      // Speical Case: LOCATION
+     json_generator["LOCATION"] = "Point(65.017210,25.492411)";
      
      // now convert to JSON
-     //std::string str_json = json.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));
+     strncpy(data,str_json.c_str(),this->min(str_json.length(),data_length));
           
      // DEBUG
-     //this->logger()->log("Loading Payload: %s",data);
+     this->logger()->log("Loading Payload: %s",data);
      
      // return the payload
      return data;