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:
- 13:25448d92c205
- Parent:
- 9:ff877db53cfd
- Child:
- 14:0a6497a380a4
--- a/MQTTTransport.cpp Thu Feb 27 00:23:30 2014 +0000
+++ b/MQTTTransport.cpp Thu Feb 27 04:05:41 2014 +0000
@@ -104,15 +104,15 @@
//this->logger()->log("Type: %s Name: %s Verb: %s Value: %s",message_type,message_name,message_verb,message_value);
// load endpoints
- if (message_type != NULL && strcmp(message_type,"Endpoint") == 0) {
- if (message_name != NULL && strcmp(message_name,"all") == 0) {
- if (message_verb != NULL && strcmp(message_verb,"load") == 0) {
- // load up our endpoint
- endpoint->loadEndpoint();
+ if (message_type != NULL && strcmp(message_type,IOC_ENDPOINT_VERB) == 0) {
+ if (message_name != NULL && strcmp(message_name,IOC_ENDPOINT_ALL_VERB) == 0) {
+ if (message_verb != NULL && strcmp(message_verb,IOC_REQUEST_LOAD_ALL_VERB) == 0) {
+ // load up our endpoints
+ endpoint->loadEndpoints();
}
- if (message_verb != NULL && strcmp(message_verb,"Update") == 0) {
- // update our endpoint
- endpoint->updateEndpoint();
+ if (message_verb != NULL && strcmp(message_verb,IOC_REQUEST_UPDATE_ALL_VERB) == 0) {
+ // update our endpoints
+ endpoint->updateEndpoints();
}
}
else {
@@ -121,9 +121,9 @@
if (message_name != NULL) {
index = endpoint->indexOfLight((char *)message_name);
if (index >= 0) {
- if (message_verb != NULL && strcmp(message_verb,"Update") == 0) {
+ if (message_verb != NULL && strcmp(message_verb,IOC_REQUEST_UPDATE_ALL_VERB) == 0) {
// update our endpoint
- endpoint->updateEndpoint();
+ endpoint->updateEndpoints(index);
}
}
}
@@ -131,7 +131,7 @@
}
// change a resource value
- if (message_type != NULL && strcmp(message_type,"Change") == 0) {
+ if (message_type != NULL && strcmp(message_type,IOC_CHANGE_VERB) == 0) {
if (message_name != NULL) {
// destined for our lights?
int index = endpoint->indexOfLight((char *)message_name);
@@ -154,14 +154,14 @@
}
// get a resource value
- if (message_type != NULL && strcmp(message_type,"Get") == 0) {
+ if (message_type != NULL && strcmp(message_type,IOC_REQUEST_VALUE_VERB) == 0) {
if (message_name != NULL) {
// destined for our lights?
int index = endpoint->indexOfLight((char *)message_name);
if (index >= 0) {
if (message_verb != NULL) {
// map the parameter to one of ours
- char *mapped_resource = this->mapEndpointResourceToIOCResource((char *)message_verb);
+ char *mapped_resource = this->mapIOCResourceToEndpointResource((char *)message_verb);
if (mapped_resource != NULL) {
EmulatedResourceFactory *factory = (EmulatedResourceFactory *)endpoint->getResources(index);
message_value = factory->getResourceValue((char *)mapped_resource);
@@ -194,8 +194,8 @@
this->logger()->log("Sending Response back to MQTT...");
char message[MAX_MQTT_MESSAGE_LENGTH+1];
memset(message,0,MAX_MQTT_MESSAGE_LENGTH+1);
- char *str_success = "OK"; if (!success) str_success = "FAILED";
- sprintf(message,"response:{ENDPOINT=%s RESOURCE=%s VALUE=%s}:%s",endpoint_name,resource_name,value,str_success);
+ char *str_success = IOC_RESPONSE_OK; if (!success) str_success = IOC_RESPONSE_FAILED;
+ sprintf(message,IOC_RESPONSE_TEMPLATE,IOC_RESPONSE_VERB,endpoint_name,resource_name,value,str_success);
bool sent = this->m_mqtt->publish(this->getTopic(),message,strlen(message));
if (sent) {
this->logger()->log("Result sent successfully");
@@ -211,7 +211,7 @@
}
}
- char *MQTTTransport::mapEndpointResourceToIOCResource(char *ioc_name) { return this->m_map->getMBEDMappedName(ioc_name); }
+ char *MQTTTransport::mapIOCResourceToEndpointResource(char *ioc_name) { return this->m_map->iocNameToEndpointName(ioc_name); }
char *MQTTTransport::makeID(char *id_template,char *buffer) {
srand(time(0));