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: C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Diff: MQTTTransport.cpp
- Revision:
- 4:11f00b499106
- Parent:
- 3:3db076b9d380
- Child:
- 5:4ad5ec5802a2
--- a/MQTTTransport.cpp Tue Feb 25 22:11:11 2014 +0000
+++ b/MQTTTransport.cpp Tue Feb 25 22:49:39 2014 +0000
@@ -18,10 +18,11 @@
#include "MQTTTransport.h"
+ // Endpoint Support
#include "MBEDEndpoint.h"
- // String splitting support
- #include "splitstring.h"
+ // string splitter support
+ #include "Splitter.h"
// our transmitt instance
MQTTTransport *instance = NULL;
@@ -55,34 +56,34 @@
char *message_value = NULL;
char *message_opt = NULL;
char *endpoint_name = NULL;
- splitstring *str_payload = NULL;
MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint();
// DEBUG
this->logger()->log("MQTT Message: %s length=%d",payload,len);
// split the string by the delimiter
- str_payload = new splitstring(payload);
- vector<string> data = str_payload->split(':');
+ Splitter *splitter = new Splitter(payload,':');
+ char** data = splitter->split();
+ int count = splitter->size(data);
// format of the MQTT message: message_type:name:verb|Parameter_X:value|keyword:optional_data
/*
- if (data.size() > 0) message_type = data[0].c_str();
- if (data.size() > 1) message_name = data[1].c_str();
- if (data.size() > 2) message_verb = data[2].c_str();
- if (data.size() > 3) message_value = data[3].c_str();
- if (data.size() > 4) message_opt = data[4].c_str();
+ if (count > 0) message_type = data[0];
+ if (count > 1) message_name = data[1];
+ if (count > 2) message_verb = data[2];
+ if (count > 3) message_value = data[3];
+ if (count > 4) message_opt = data[4];
*/
// get our endpoint name
endpoint_name = endpoint->getEndpointName();
// XXX FIXUP until MQTT messages have endpoint_names in them
- if (data.size() > 0) message_type = (char *)data[0].c_str();
- message_name = endpoint->getEndpointName(); // if (data.size() > 1) message_name = (char *)data[1].c_str();
- if (data.size() > 1) message_verb = (char *)data[1].c_str();
- if (data.size() > 2) message_value = (char *)data[2].c_str();
- if (data.size() > 3) message_opt = (char *)data[3].c_str();
+ if (count > 0) message_type = data[0];
+ message_name = endpoint->getEndpointName(); // if (count > 1) message_name = (char *)data[1].c_str();
+ if (count > 1) message_verb = data[1];
+ if (count > 2) message_value = data[2];
+ if (count > 3) message_opt = data[3];
// DEBUG
this->logger()->log("Type: %s Name: %s Verb: %s Value: %s",message_type,message_name,message_verb,message_value);
@@ -165,8 +166,11 @@
this->logger()->log("MQTT Message: %s not for us: %s... ignoring...",payload,endpoint_name);
}
+ // clean up the array
+ if (data != NULL) splitter->clear(data);
+
// clean up
- if (str_payload != NULL) delete str_payload;
+ if (splitter != NULL) delete splitter;
}
void MQTTTransport::sendResourceValue(char *endpoint_name,char *parameter_name,char *value) {