Sensinode NSDL demo with WiFi interface

Dependencies:   Beep C12832_lcd LM75B MMA7660 WiflyInterface mbed-rtos mbed nsdl_lib

Fork of NSDL_HelloWorld by Sensinode

Committer:
bogdanm
Date:
Tue Oct 15 12:45:46 2013 +0000
Revision:
2:7e489126fe7a
Code refactoring.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 2:7e489126fe7a 1 // GPS resource implementation
bogdanm 2:7e489126fe7a 2
bogdanm 2:7e489126fe7a 3 #include "mbed.h"
bogdanm 2:7e489126fe7a 4 #include "nsdl_support.h"
bogdanm 2:7e489126fe7a 5 #include "gps.h"
bogdanm 2:7e489126fe7a 6
bogdanm 2:7e489126fe7a 7 #define GPS_RES_ID "gps/loc"
bogdanm 2:7e489126fe7a 8
bogdanm 2:7e489126fe7a 9 extern Serial pc;
bogdanm 2:7e489126fe7a 10 static uint8_t res_gps_val[] = {"52.182382,0.178849"};
bogdanm 2:7e489126fe7a 11
bogdanm 2:7e489126fe7a 12 /* Only GET method allowed */
bogdanm 2:7e489126fe7a 13 static uint8_t gps_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
bogdanm 2:7e489126fe7a 14 {
bogdanm 2:7e489126fe7a 15 sn_coap_hdr_s *coap_res_ptr = 0;
bogdanm 2:7e489126fe7a 16 static float led_dimm = 0;
bogdanm 2:7e489126fe7a 17 int led_state = 0;
bogdanm 2:7e489126fe7a 18 char led_dimm_temp[4];
bogdanm 2:7e489126fe7a 19
bogdanm 2:7e489126fe7a 20 pc.printf("gps callback\r\n");
bogdanm 2:7e489126fe7a 21
bogdanm 2:7e489126fe7a 22 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
bogdanm 2:7e489126fe7a 23
bogdanm 2:7e489126fe7a 24 led_state = led_dimm * 100;
bogdanm 2:7e489126fe7a 25 sprintf(led_dimm_temp, "%d", led_state);
bogdanm 2:7e489126fe7a 26
bogdanm 2:7e489126fe7a 27 coap_res_ptr->payload_len = sizeof(res_gps_val)-1;
bogdanm 2:7e489126fe7a 28 coap_res_ptr->payload_ptr = (uint8_t*)res_gps_val;
bogdanm 2:7e489126fe7a 29
bogdanm 2:7e489126fe7a 30 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 31
bogdanm 2:7e489126fe7a 32 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
bogdanm 2:7e489126fe7a 33
bogdanm 2:7e489126fe7a 34 return 0;
bogdanm 2:7e489126fe7a 35 }
bogdanm 2:7e489126fe7a 36
bogdanm 2:7e489126fe7a 37 int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr)
bogdanm 2:7e489126fe7a 38 {
bogdanm 2:7e489126fe7a 39 nsdl_create_dynamic_resource(resource_ptr, sizeof(GPS_RES_ID)-1, (uint8_t*)GPS_RES_ID, 0, 0, 0, &gps_resource_cb, SN_GRS_GET_ALLOWED);
bogdanm 2:7e489126fe7a 40 return 0;
bogdanm 2:7e489126fe7a 41 }