![](/media/cache/group/arm_mbed.PNG.50x50_q85.png)
Demo starter application to connect WiGo to NSP and expose on-board sensors
Dependencies: NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed nsdl_lib TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger
This is the mbed project for the IoT World Hackathon event, June 17th and 18th in Palo Also.
The setup instructions for participants are at the Setup page of this wiki:
resources/altitude.cpp@18:11b9d98ecae2, 2014-07-09 (annotated)
- Committer:
- michaeljkoster
- Date:
- Wed Jul 09 04:35:49 2014 +0000
- Revision:
- 18:11b9d98ecae2
- Parent:
- 9:6501da9e384e
Checkpoint
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michaeljkoster | 9:6501da9e384e | 1 | // altitude sensor resource implementation |
michaeljkoster | 5:bacf25e9419b | 2 | |
michaeljkoster | 5:bacf25e9419b | 3 | #include "mbed.h" |
michaeljkoster | 5:bacf25e9419b | 4 | #include "nsdl_support.h" |
michaeljkoster | 5:bacf25e9419b | 5 | #include "Wi-Go_eCompass_Lib_V3.h" |
michaeljkoster | 5:bacf25e9419b | 6 | |
michaeljkoster | 5:bacf25e9419b | 7 | #define ALT_RES_ID "3307/0/5700" |
michaeljkoster | 5:bacf25e9419b | 8 | |
michaeljkoster | 5:bacf25e9419b | 9 | extern Serial pc; |
michaeljkoster | 5:bacf25e9419b | 10 | extern axis6_t axis6; |
michaeljkoster | 5:bacf25e9419b | 11 | char alt[7]; |
michaeljkoster | 5:bacf25e9419b | 12 | |
michaeljkoster | 5:bacf25e9419b | 13 | /* Only GET method allowed */ |
michaeljkoster | 5:bacf25e9419b | 14 | static uint8_t alt_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) |
michaeljkoster | 5:bacf25e9419b | 15 | { |
michaeljkoster | 5:bacf25e9419b | 16 | sn_coap_hdr_s *coap_res_ptr = 0; |
michaeljkoster | 5:bacf25e9419b | 17 | sprintf(alt,"%d", axis6.alt); |
michaeljkoster | 5:bacf25e9419b | 18 | pc.printf("altitude callback\r\n"); |
michaeljkoster | 5:bacf25e9419b | 19 | pc.printf("altitude %s\r\n", alt); |
michaeljkoster | 5:bacf25e9419b | 20 | |
michaeljkoster | 5:bacf25e9419b | 21 | if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) |
michaeljkoster | 5:bacf25e9419b | 22 | { |
michaeljkoster | 5:bacf25e9419b | 23 | coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); |
michaeljkoster | 5:bacf25e9419b | 24 | |
michaeljkoster | 5:bacf25e9419b | 25 | coap_res_ptr->payload_len = strlen(alt); |
michaeljkoster | 5:bacf25e9419b | 26 | coap_res_ptr->payload_ptr = (uint8_t*)alt; |
michaeljkoster | 5:bacf25e9419b | 27 | sn_nsdl_send_coap_message(address, coap_res_ptr); |
michaeljkoster | 5:bacf25e9419b | 28 | } |
michaeljkoster | 5:bacf25e9419b | 29 | |
michaeljkoster | 5:bacf25e9419b | 30 | sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); |
michaeljkoster | 5:bacf25e9419b | 31 | |
michaeljkoster | 5:bacf25e9419b | 32 | return 0; |
michaeljkoster | 5:bacf25e9419b | 33 | } |
michaeljkoster | 5:bacf25e9419b | 34 | |
michaeljkoster | 5:bacf25e9419b | 35 | int create_alt_resource(sn_nsdl_resource_info_s *resource_ptr) |
michaeljkoster | 5:bacf25e9419b | 36 | { |
michaeljkoster | 5:bacf25e9419b | 37 | nsdl_create_dynamic_resource(resource_ptr, sizeof(ALT_RES_ID)-1, (uint8_t*)ALT_RES_ID, 0, 0, 0, &alt_resource_cb, (SN_GRS_GET_ALLOWED)); |
michaeljkoster | 5:bacf25e9419b | 38 | return 0; |
michaeljkoster | 5:bacf25e9419b | 39 | } |