mqtt specific components for the impact mbed endpoint library

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_mqtt_endpoint_nxp

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Mon Apr 07 03:15:02 2014 +0000
Parent:
28:6cdbaf2aa697
Child:
30:00ff5fe192f0
Commit message:
sunday

Changed in this revision

EmulatedLightResourceFactory.cpp Show annotated file Show diff for this revision Revisions of this file
MBEDEndpoint.cpp Show annotated file Show diff for this revision Revisions of this file
MBEDEndpoint.h Show annotated file Show diff for this revision Revisions of this file
MQTTDefinitions.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
--- a/EmulatedLightResourceFactory.cpp	Thu Apr 03 01:55:19 2014 +0000
+++ b/EmulatedLightResourceFactory.cpp	Mon Apr 07 03:15:02 2014 +0000
@@ -77,7 +77,11 @@
  void EmulatedLightResourceFactory::initGPSCoords() {
      memset(this->m_gps_coords,0,PREFERENCE_VALUE_LEN+1);
      MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint();
-     endpoint->preferences()->getPreference("coords",this->m_gps_coords,PREFERENCE_VALUE_LEN,ENDPOINT_GPS_COORDS);
+     if (endpoint != NULL && endpoint->preferences() != NULL)
+        endpoint->preferences()->getPreference("coords",this->m_gps_coords,PREFERENCE_VALUE_LEN,ENDPOINT_GPS_COORDS);
+     else
+        strcpy(this->m_gps_coords,ENDPOINT_GPS_COORDS);
+     for(int i=0;i<strlen(this->m_gps_coords);++i) if (this->m_gps_coords[i] == ',') this->m_gps_coords[i] = ' ';
  }
  
  // get our GPS coords from preferences
--- a/MBEDEndpoint.cpp	Thu Apr 03 01:55:19 2014 +0000
+++ b/MBEDEndpoint.cpp	Mon Apr 07 03:15:02 2014 +0000
@@ -51,29 +51,40 @@
      if (getUbloxConnectStatus() != 0) success = false;
 #endif
      if (success) this->initPreferences();
+     this->logger()->log("DOUG1");
      if (success) this->initEndpointName();
+     this->logger()->log("DOUG2");
      if (success) this->logger()->turnLEDBlue();
+     this->logger()->log("DOUG3");
 #ifdef MAC_ADDRESS
      extern char fmt_mac[RESOURCE_VALUE_LEN+1];
      if (success)this->logger()->log("%s (MAC: %s)",ENDPOINT_VERSION_ANNOUNCE,fmt_mac);
 #else
      if (success)this->logger()->log(ENDPOINT_VERSION_ANNOUNCE);
 #endif
+     this->logger()->log("DOUG4");
      if (success) this->initGWAddress();
-     if (success) this->logger()->log("IOC GW IP: %s",GW_IPADDRESS);
+     this->logger()->log("DOUG5");
+     if (success) this->logger()->log("IOC GW IP: %s",this->m_gw_address);
      if (PL_ENABLE && success) this->logger()->log("Philips Light ID: %d Philips Gateway IP: %s",PL_LIGHT_ID,PL_GW_ADDRESS);
 #ifdef CELLULAR_NETWORK
      this->m_cellular_modem = NULL;
      this->m_gps = NULL;
+     this->logger()->log("initializing Cellular Modem...");
      if (success) success = this->initializeCellularModem(transport,pinouts);
+     this->logger()->log("initializing GPS Receiver...");
      if (success) success = this->initializeGPSReceiver(pinouts);
 #else
      if (success) success = this->initializeEthernet((EthernetInterface *)transport);
 #endif
      if (success) this->logger()->turnLEDYellow();
+     this->logger()->log("initializing resource map...");
      if (success)this->m_map = new MBEDToIOCResourceMap(error_handler); 
+     this->logger()->log("initializing transports...");
      if (success) success = this->initializeTransports();
+     this->logger()->log("initializing personalities...");
      if (success) success = this->initializePersonalities();  
+     this->logger()->log("initialization complete for endpoint...");
      if (success) this->logger()->turnLEDOrange();
      this->logger()->lcdStatusOnly(true);
      if (!success) closedown(2);
@@ -116,8 +127,10 @@
  // initialize the GW address from the configuration
  void MBEDEndpoint::initGWAddress() {
      memset(this->m_gw_address,0,PREFERENCE_VALUE_LEN+1);
-     this->preferences()->getPreference("gw_address",this->m_gw_address,PREFERENCE_VALUE_LEN,GW_IPADDRESS);
-     this->logger()->log("GW IP: %s",this->getGWAddress());
+     strcpy(this->m_gw_address,GW_IPADDRESS);
+     if (this->m_preferences != NULL)
+        this->m_preferences->getPreference("gw_address",this->m_gw_address,PREFERENCE_VALUE_LEN,GW_IPADDRESS);
+     this->logger()->log("GW IP: %s",this->m_gw_address);
  }
  
  // get our GW address
@@ -150,7 +163,8 @@
  
  // initialize the Lights
  bool MBEDEndpoint::initializeLights() {
-     int index = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX); 
+     int index = PERSONALITY_NAME_INDEX;
+     if (this->m_preferences != NULL) index = this->m_preferences->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX); 
      this->logger()->log("Initializing Lights...");
      for(int i=0;i<NUM_PERSONALITY_INSTANCES;++i) {
          this->m_personalities[i] = new MBEDLight(this->logger(),this->m_transports,i+index,this);
@@ -196,8 +210,10 @@
  
  // Initialize the Endpoint Name - will be the first Light resource name (and there must be one...)
  void MBEDEndpoint::initEndpointName() {
-     this->m_instance_id = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX);
+     this->m_instance_id = PERSONALITY_NAME_INDEX;
      memset(this->m_endpoint_name,0,PERSONALITY_NAME_LEN+1);
+     if (this->m_preferences != NULL) 
+        this->m_instance_id = this->m_preferences->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX);
      sprintf(this->m_endpoint_name,PERSONALITY_NAME,this->m_instance_id);
  }
  
@@ -255,7 +271,7 @@
      bool success = false;
      
      // initialize
-     if (this->m_gps == NULL) this->m_gps = new MBEDUbloxGPS(this->logger(),this,(C027  *)pinouts);
+     if (this->m_gps == NULL) this->m_gps = new MBEDUbloxGPS(this->logger(),(void *)this,(C027  *)pinouts);
      if (this->m_gps != NULL) success = this->m_gps->connect();
      
      // return our status
--- a/MBEDEndpoint.h	Thu Apr 03 01:55:19 2014 +0000
+++ b/MBEDEndpoint.h	Mon Apr 07 03:15:02 2014 +0000
@@ -83,7 +83,6 @@
         
         char *getEndpointName();
         char *getGWAddress();
-        Preferences *preferences();
         
         char *getLCDStatus();
         
@@ -91,6 +90,8 @@
                 
         MBEDToIOCResourceMap *getMap();
     
+        Preferences *preferences();
+         
     protected:
     
     private:
--- a/MQTTDefinitions.h	Thu Apr 03 01:55:19 2014 +0000
+++ b/MQTTDefinitions.h	Mon Apr 07 03:15:02 2014 +0000
@@ -86,7 +86,7 @@
 #define MQTT_HOSTPORT               1883                            // IOC MQTT Broker Port
 #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_ENDPOINT_IDLEN         20                              // IOC MQTT Endpoint ID length (max)
 #define MQTT_IOC_TOPIC              "ARM/sensinode/control/%s"      // IOC MQTT Topic 
 #define MQTT_IOC_ALL_TOPIC          "ARM/sensinode/control/all"     // IOC MQTT Topic (broadcast)
 #define MQTT_PING_SEND_TOPIC        "ARM/sensinode/ping"            // IOC MQTT Ping Send Topic
--- a/MQTTTransport.cpp	Thu Apr 03 01:55:19 2014 +0000
+++ b/MQTTTransport.cpp	Mon Apr 07 03:15:02 2014 +0000
@@ -378,16 +378,17 @@
      return sent;
  }
  
+ static char _mqtt_id[MQTT_ENDPOINT_IDLEN+1];
+ 
  // 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));
+     memset(_mqtt_id,0,(MQTT_ENDPOINT_IDLEN+1));
+     //if (network_mutex != NULL) network_mutex->lock();
      if (this->m_connected == false) {
          this->logger()->log("MQTT Init: %s:%d...",MQTT_HOSTNAME,MQTT_HOSTPORT);
          this->m_mqtt = &_mqtt;
          if (this->m_mqtt != NULL) {
-             char *id = this->makeID(MQTT_ENDPOINT_ID,mqtt_id);
+             char *id = this->makeID(MQTT_ENDPOINT_ID,_mqtt_id);
              this->logger()->log("MQTT Connect: ID: %s...",id);
              if (this->m_mqtt->connect(id)) {
                  this->logger()->log("MQTT Subscribe: Topic: %s...",this->getTopic());
@@ -423,7 +424,7 @@
      else {
          this->logger()->log("MQTT already connected (OK)");
      }
-     if (network_mutex != NULL) network_mutex->unlock();
+     //if (network_mutex != NULL) network_mutex->unlock();
      return this->m_connected;
  }