MBED MQTT Lighting Endpoint for NXP LPC1768+AppBoard
Dependencies: C12832_lcd EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Revision 163:392f89530162, committed 2014-03-21
- Comitter:
- ansond
- Date:
- Fri Mar 21 05:55:23 2014 +0000
- Parent:
- 162:c9e9926cdc79
- Child:
- 164:f824e14df376
- Commit message:
- updates
Changed in this revision
--- a/Definitions.h Fri Mar 21 05:44:05 2014 +0000 +++ b/Definitions.h Fri Mar 21 05:55:23 2014 +0000 @@ -112,7 +112,7 @@ // MQTT connect information #define MQTT_HOSTNAME "iocana.bcu.ac.uk" // IOC MQTT Broker Host - iocana.bcu.ac.uk #define MQTT_HOSTPORT 1883 // IOC MQTT Broker Port -#define MQTT_ENDPOINT_ID "mbed%d" // IOC MQTT Endpoint ID template +#define MQTT_ENDPOINT_ID "mbed%d%d" // IOC MQTT Endpoint ID template #define MQTT_MAXID_VALUE 99 // IOC MQTT Endpoint ID maximum integer value #define MQTT_ENDPOINT_IDLEN 64 // IOC MQTT Endpoint ID length (max) #define MQTT_IOC_TOPIC "ARM/sensinode/control/%s" // IOC MQTT Topic
--- a/MBEDEndpoint.cpp Fri Mar 21 05:44:05 2014 +0000 +++ b/MBEDEndpoint.cpp Fri Mar 21 05:55:23 2014 +0000 @@ -39,6 +39,7 @@ // default constructor MBEDEndpoint::MBEDEndpoint(ErrorHandler *error_handler,EthernetInterface *ethernet) { bool success = true; + this->m_instance_id = 0; this->m_preferences = NULL; memset(this->m_lcd_status,0,TEMP_BUFFER_LEN+1); memset(this->m_gw_address,0,PREFERENCE_VALUE_LEN+1); @@ -150,14 +151,17 @@ // Initialize the Endpoint Name - will be the first Light resource name (and there must be one...) void MBEDEndpoint::initEndpointName() { - int index = this->preferences()->getIntPreference("endpoint_id",LIGHT_NAME_INDEX); + this->m_instance_id = this->preferences()->getIntPreference("endpoint_id",LIGHT_NAME_INDEX); memset(this->m_endpoint_name,0,LIGHT_NAME_LEN+1); - sprintf(this->m_endpoint_name,LIGHT_NAME,index); + sprintf(this->m_endpoint_name,LIGHT_NAME,this->m_instance_id); } // get our endpoint name char *MBEDEndpoint::getEndpointName() { return this->m_endpoint_name; } + // get our instance id + int MBEDEndpoint::getInstanceID() { return this->m_instance_id; } + // initialize a specific transport bool MBEDEndpoint::initializeTransport(int index,char *key,Transport *transport) { bool success = false;
--- a/MBEDEndpoint.h Fri Mar 21 05:44:05 2014 +0000 +++ b/MBEDEndpoint.h Fri Mar 21 05:55:23 2014 +0000 @@ -52,6 +52,7 @@ Preferences *m_preferences; // preference support char m_lcd_status[TEMP_BUFFER_LEN+1]; // LCD status buffer char m_gw_address[PREFERENCE_VALUE_LEN+1]; // GW address buffer + int m_instance_id; // instance ID for this endpoint public: MBEDEndpoint(ErrorHandler *error_handler,EthernetInterface *ethernet); @@ -71,6 +72,8 @@ Preferences *preferences(); char *getLCDStatus(); + + int getInstanceID(); MBEDToIOCResourceMap *getMap();
--- a/MQTTTransport.cpp Fri Mar 21 05:44:05 2014 +0000 +++ b/MQTTTransport.cpp Fri Mar 21 05:55:23 2014 +0000 @@ -283,9 +283,12 @@ char *MQTTTransport::mapIOCResourceToEndpointResource(char *ioc_name) { return this->getMap()->iocNameToEndpointName(ioc_name); } char *MQTTTransport::makeID(char *id_template,char *buffer) { + MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint(); + int instance_id = rand()%100; + if (endpoint != NULL) instance_id = endpoint->getInstanceID(); srand(time(0)); srand(rand()); - sprintf(buffer,id_template,rand()%MQTT_MAXID_VALUE); + sprintf(buffer,id_template,rand()%MQTT_MAXID_VALUE,instance_id); return buffer; }