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:
- 22:f1002e5993c5
- Parent:
- 15:e44d75d95b38
- Child:
- 23:793b2898522e
--- a/MQTTTransport.cpp Thu Feb 27 22:07:45 2014 +0000
+++ b/MQTTTransport.cpp Thu Feb 27 23:33:24 2014 +0000
@@ -72,7 +72,7 @@
vector<string> data = tmp->split('/');
if (data.size() > 0) {
char *ep = (char *)data[data.size()-1].c_str();
- strncpy(this->m_endpoint_name,ep,strlen(ep));
+ if (ep != NULL) strncpy(this->m_endpoint_name,ep,strlen(ep));
}
if (tmp != NULL) delete tmp;
return this->m_endpoint_name;
@@ -242,8 +242,15 @@
if (this->m_mqtt->connect(id)) {
this->logger()->log("MQTT Subscribe: Topic: %s...",this->getTopic());
if (this->m_mqtt->subscribe(this->getTopic())) {
- this->logger()->log("MQTT CONNECTED.");
- this->m_connected = true;
+ if (this->m_mqtt->subscribe(MQTT_IOC_ANNOUNCE_TOPIC)) {
+ this->logger()->log("MQTT CONNECTED.");
+ this->m_connected = true;
+ }
+ else {
+ this->logger()->log("MQTT Subscribe: Topic(ANNOUNCE): %s FAILED",this->getTopic());
+ this->logger()->turnLEDRed();
+ this->m_connected = false;
+ }
}
else {
this->logger()->log("MQTT Subscribe: Topic: %s FAILED",this->getTopic());
@@ -274,6 +281,7 @@
if (this->m_mqtt != NULL) {
this->logger()->log("MQTT Unsubscribing from: %s...",this->getTopic());
this->m_mqtt->unsubscribe(this->getTopic());
+ this->m_mqtt->unsubscribe(MQTT_IOC_ANNOUNCE_TOPIC);
this->logger()->log("MQTT Disconnecting...");
this->m_mqtt->disconnect();
}