Project with example IPSO resources for LED bar, Gas Sensor, and Light Sensor
Dependencies: EthernetInterface LED_Bar mbed-rtos mbed nsdl_lib
Diff: resources/IPSO_presence.cpp
- Revision:
- 7:3f52b52ef2ad
- Parent:
- 6:4fa917ca6aa4
--- a/resources/IPSO_presence.cpp Sat Oct 25 03:31:06 2014 +0000 +++ b/resources/IPSO_presence.cpp Sat Oct 25 04:07:58 2014 +0000 @@ -16,31 +16,29 @@ static uint8_t pres_obs_token_len = 0; DigitalIn presenceSensor(D2); -bool presence = 0; -bool last_presence = 0; -char presenceString[2]; +uint8_t presence = 0; +uint8_t last_presence = 0; +char presenceString[1]; static void pres_observe_thread(void const *args) -{ - //int32_t time = 0; + { while (true) - { + { wait(.1); - //time++; - //sn_nsdl_exec(time); presence = presenceSensor.read(); if((presence != last_presence) && pres_obs_number != 0 && pres_obs_token_ptr != NULL) - { + { last_presence = presence; + pc.printf("presence: %d\r\n", presence); pres_obs_number++; sprintf(presenceString,"%d", presence); - if(sn_nsdl_send_observation_notification(pres_obs_token_ptr, pres_obs_token_len, (uint8_t*)presenceString, sizeof((uint8_t*)presenceString)-1, &pres_obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) + if(sn_nsdl_send_observation_notification(pres_obs_token_ptr, pres_obs_token_len, (uint8_t*)presenceString, strlen(presenceString), &pres_obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) pc.printf("Presence observation sending failed\r\n"); else pc.printf("Presence observation\r\n"); + } } } -} /* Only GET method allowed */ @@ -53,7 +51,7 @@ pc.printf("presence state %s\r\n", presenceString); if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) - { + { coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); coap_res_ptr->payload_len = strlen(presenceString); @@ -90,8 +88,6 @@ if(received_coap_ptr->options_list_ptr->observe) { - //coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); - //memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); coap_res_ptr->options_list_ptr->observe_ptr = &pres_obs_number; coap_res_ptr->options_list_ptr->observe_len = 1; pres_obs_number++; @@ -101,8 +97,7 @@ nsdl_free(coap_res_ptr->options_list_ptr); coap_res_ptr->options_list_ptr = NULL; coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } + } sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);