LPC1768 hell world with LWM2M

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

Committer:
michaeljkoster
Date:
Tue Jul 22 23:58:23 2014 +0000
Revision:
0:9101343a70cd
Demo with lwm2m

Who changed what in which revision?

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