MBED MQTT Lighting Endpoint for NXP LPC1768+AppBoard

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

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Mon Mar 17 17:05:49 2014 +0000
Parent:
135:662f96c35bfa
Child:
137:6577dd23f6ed
Commit message:
updates

Changed in this revision

Definitions.h Show annotated file Show diff for this revision Revisions of this file
MQTTTransport.cpp Show annotated file Show diff for this revision Revisions of this file
endpoint_core.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Definitions.h	Mon Mar 17 05:07:39 2014 +0000
+++ b/Definitions.h	Mon Mar 17 17:05:49 2014 +0000
@@ -26,8 +26,8 @@
 #include "CommonDefinitions.h"
 
 // Until we get HTTPS with BasicAuth working in MBED...
-//#define GW_IPADDRESS                "192.168.1.191"     // work
-#define GW_IPADDRESS                "192.168.1.220"     // home - vm
+#define GW_IPADDRESS                "192.168.1.191"     // work
+//#define GW_IPADDRESS                "192.168.1.220"     // home - vm
 //#define GW_IPADDRESS                "10.1.0.27"         // home
 #define GW_REDIRECT_URL             "http://%s:8888/NSP-IOC-Gateway/IOCRestAPI"
 #define USE_GW_HTTP_REDIRECTOR      true                            // true - make http calls to IOC via GW, false - make http calls directly to IOC
@@ -45,7 +45,7 @@
 #define ENDPOINT_VERSION_ANNOUNCE "\r\nMBED IMPACT(MQTT) Endpoint v1.0"
 
 // our MAC address
-#define MAC_ADDRESS                   0x00,0x12,0xAB,0xE3,0x4F,0x56
+#define MAC_ADDRESS                   0xa0,0x12,0xAB,0xE3,0x4F,0x56
 
 // Light Configuration
 #define LIGHT_NAME                  "light-mqtt-%d"                 // name of each light in this endpoint
--- a/MQTTTransport.cpp	Mon Mar 17 05:07:39 2014 +0000
+++ b/MQTTTransport.cpp	Mon Mar 17 17:05:49 2014 +0000
@@ -16,6 +16,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
  
+ #include "mbed.h"
+ #include "rtos.h"
+ 
  #include "MQTTTransport.h"
  
  // Endpoint Support
@@ -23,6 +26,9 @@
  
  // EmulatedResourceFactory support
  #include "EmulatedResourceFactory.h"
+ 
+ // Network mutex
+ extern Mutex *network_mutex;
   
  // our transmitt instance 
  MQTTTransport *_mqtt_instance =  NULL;
@@ -254,7 +260,9 @@
          memset(message,0,MAX_MQTT_MESSAGE_LENGTH+1);
          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);
+         if (network_mutex != NULL) network_mutex->lock();
          bool sent = this->m_mqtt->publish(this->getTopic(),message,strlen(message));
+         if (network_mutex != NULL) network_mutex->unlock();
          if (sent) {
              this->logger()->log("Result sent successfully");
              this->logger()->blinkTransportTxLED();
@@ -334,7 +342,9 @@
      
      // send the message over the ping/pong topic
      //this->logger()->log("Sending PING: counter=%d",this->m_ping_counter);
+     if (network_mutex != NULL) network_mutex->lock();
      sent = this->m_mqtt->publish(MQTT_PING_SEND_TOPIC,message,strlen(message));
+     if (network_mutex != NULL) network_mutex->unlock();
      if (sent) {
          // send succeeded
          //this->logger()->log("PING %d sent successfully",this->m_ping_counter);
@@ -359,6 +369,7 @@
  
  // connect up MQTT
  bool MQTTTransport::connect() {
+     if (network_mutex != NULL) network_mutex->lock();
      char mqtt_id[MQTT_ENDPOINT_IDLEN+1];
      memset(mqtt_id,0,(MQTT_ENDPOINT_IDLEN+1));
      if (this->m_connected == false) {
@@ -394,6 +405,7 @@
      else {
          this->logger()->log("MQTT already connected (OK)");
      }
+     if (network_mutex != NULL) network_mutex->unlock();
      return this->m_connected;
  }
  
@@ -401,7 +413,9 @@
  bool MQTTTransport::disconnect() {
      if (this->m_mqtt != NULL) {
          this->logger()->log("MQTT Unsubscribing from: %s...",this->getTopic());
+         if (network_mutex != NULL) network_mutex->lock();
          this->m_mqtt->unsubscribe(this->getTopic());
+         if (network_mutex != NULL) network_mutex->unlock();
          this->logger()->log("MQTT Disconnecting...");
          this->m_mqtt->disconnect();
      }
@@ -416,7 +430,9 @@
  void MQTTTransport::checkAndProcess() {
      // process any MQTT messages
      if (this->m_mqtt != NULL && this->m_connected == true) {
+         if (network_mutex != NULL) network_mutex->lock();
          bool connected = this->m_mqtt->loop();
+         if (network_mutex != NULL) network_mutex->unlock();
          if (connected) {
             this->logger()->blinkTransportRxLED();
          }
--- a/endpoint_core.lib	Mon Mar 17 05:07:39 2014 +0000
+++ b/endpoint_core.lib	Mon Mar 17 17:05:49 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/ansond/code/endpoint_core/#c69550ced194
+http://mbed.org/users/ansond/code/endpoint_core/#dac439bf902b