mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Revision:
57:8335946f2c67
Parent:
56:aaf84e56c422
Child:
60:167e8f021e30
diff -r aaf84e56c422 -r 8335946f2c67 api/DynamicResource.cpp
--- a/api/DynamicResource.cpp	Tue Apr 14 22:29:53 2015 +0000
+++ b/api/DynamicResource.cpp	Fri May 22 15:44:00 2015 +0000
@@ -337,6 +337,7 @@
 int DynamicResource::notify(uint8_t *data,int data_length) {
     uint8_t *notify_data = NULL;
     int notify_data_length = 0;
+    int status = 0;
     
     // convert the string from the GET to something suitable for CoAP payloads          
     if (this->getDataWrapper() != NULL) {
@@ -359,13 +360,21 @@
         notify_data = data;
     }
     
-    // send the observation...
-    int status = sn_nsdl_send_observation_notification(this->m_obs_token_ptr,this->m_obs_token_len,notify_data,notify_data_length,&this->m_obs_number,1,COAP_MSG_TYPE_NON_CONFIRMABLE,0);
-    if (status == 0) {
-        this->logger()->log("ERROR: resource(NOTIFY) send failed...");
+    // check if we have something to send... if we do, then send it...
+    if (notify_data != NULL && notify_data_length > 0) {
+        // send the observation...
+        status = sn_nsdl_send_observation_notification(this->m_obs_token_ptr,this->m_obs_token_len,notify_data,notify_data_length,&this->m_obs_number,1,COAP_MSG_TYPE_NON_CONFIRMABLE,0);
+        if (status == 0) {
+            this->logger()->log("ERROR: resource(NOTIFY) send failed...");
+        }
+        else {
+            ++(this->m_obs_number);
+        }
     }
     else {
-        ++(this->m_obs_number);
+        // nothing to send... so ignore silently
+        //this->logger()->log("resource(NOTIFY): nothing to notify (OK)...");
+        status = 1;
     }
     
     // return our status