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
Diff: api/DynamicResource.cpp
- Revision:
- 27:eb6818ad257a
- Parent:
- 25:1fc958ac14d1
- Child:
- 28:8fd9336edeb9
diff -r b06a19916f05 -r eb6818ad257a api/DynamicResource.cpp --- a/api/DynamicResource.cpp Fri Mar 20 05:55:22 2015 +0000 +++ b/api/DynamicResource.cpp Wed Mar 25 05:12:35 2015 +0000 @@ -255,10 +255,37 @@ // send the notification int DynamicResource::notify(uint8_t *data,int data_length) { - int status = sn_nsdl_send_observation_notification(this->m_obs_token_ptr,this->m_obs_token_len,data,data_length,&this->m_obs_number,1,COAP_MSG_TYPE_NON_CONFIRMABLE,0); + uint8_t *notify_data = NULL; + int notify_data_length = 0; + + // convert the string from the GET to something suitable for CoAP payloads + if (this->getDataWrapper() != NULL) { + // wrap the data... + this->getDataWrapper()->wrap((uint8_t *)data,data_length); + + // announce (after wrap) + this->logger()->log("Notify payload [%s]...",this->getDataWrapper()->get()); + + // fill notify + notify_data_length = this->getDataWrapper()->length(); + notify_data = this->getDataWrapper()->get(); + } + else { + // announce (no wrap) + this->logger()->log("Notify payload [%s]...",data); + + // do not wrap the data... + notify_data_length = data_length; + 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..."); } + + // return our status return status; }