Project with example IPSO resources for LED bar, Gas Sensor, and Light Sensor

Dependencies:   EthernetInterface LED_Bar mbed-rtos mbed nsdl_lib

Files at this revision

API Documentation at this revision

Comitter:
michaeljkoster
Date:
Wed Oct 22 22:25:14 2014 +0000
Parent:
2:7afc089e3bf3
Child:
4:69ea903414fe
Commit message:
Added max-age=0 to LED bar for read-back from other client

Changed in this revision

resources/LEDbar.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/resources/LEDbar.cpp	Mon Oct 20 02:51:16 2014 +0000
+++ b/resources/LEDbar.cpp	Wed Oct 22 22:25:14 2014 +0000
@@ -13,6 +13,9 @@
 
 LED_Bar bar(D7, D6);
 
+uint8_t ledbar_max_age = 0; 
+uint8_t ledbar_content_type = 0;
+
 void set_leds(char *leds)
 {
 int i;
@@ -38,7 +41,25 @@
 
         coap_res_ptr->payload_len = strlen(leds);
         coap_res_ptr->payload_ptr = (uint8_t*)leds;
+        
+        coap_res_ptr->content_type_ptr = &ledbar_content_type;
+        coap_res_ptr->content_type_len = sizeof(ledbar_content_type);
+        
+        coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s));
+        if(!coap_res_ptr->options_list_ptr)
+            {
+            pc.printf("cant alloc option list for max-age\r\n");
+            coap_res_ptr->options_list_ptr = NULL; //FIXME report error and recover
+            }
+        memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
+        coap_res_ptr->options_list_ptr->max_age_ptr = &ledbar_max_age;
+        coap_res_ptr->options_list_ptr->max_age_len = sizeof(ledbar_max_age);
+
         sn_nsdl_send_coap_message(address, coap_res_ptr);
+        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
+
     }
     else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
     {