![](/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/accelerometer.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 | // accelerometer resource implementation |
michaeljkoster | 9:6501da9e384e | 2 | |
michaeljkoster | 9:6501da9e384e | 3 | #include "mbed.h" |
michaeljkoster | 9:6501da9e384e | 4 | #include "nsdl_support.h" |
michaeljkoster | 9:6501da9e384e | 5 | #include "Wi-Go_eCompass_Lib_V3.h" |
michaeljkoster | 9:6501da9e384e | 6 | |
michaeljkoster | 9:6501da9e384e | 7 | #define ACCEL_X_RES_ID "3313/0/0" |
michaeljkoster | 9:6501da9e384e | 8 | #define ACCEL_Y_RES_ID "3313/0/1" |
michaeljkoster | 9:6501da9e384e | 9 | #define ACCEL_Z_RES_ID "3313/0/2" |
michaeljkoster | 9:6501da9e384e | 10 | |
michaeljkoster | 9:6501da9e384e | 11 | extern Serial pc; |
michaeljkoster | 9:6501da9e384e | 12 | extern axis6_t axis6; |
michaeljkoster | 9:6501da9e384e | 13 | char x[7]; |
michaeljkoster | 9:6501da9e384e | 14 | char y[7]; |
michaeljkoster | 9:6501da9e384e | 15 | char z[7]; |
michaeljkoster | 9:6501da9e384e | 16 | |
michaeljkoster | 9:6501da9e384e | 17 | /* Only GET method allowed */ |
michaeljkoster | 9:6501da9e384e | 18 | |
michaeljkoster | 9:6501da9e384e | 19 | static uint8_t accel_x_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) |
michaeljkoster | 9:6501da9e384e | 20 | { |
michaeljkoster | 9:6501da9e384e | 21 | sn_coap_hdr_s *coap_res_ptr = 0; |
michaeljkoster | 9:6501da9e384e | 22 | sprintf(x,"%1.2f", axis6.fGax); |
michaeljkoster | 9:6501da9e384e | 23 | pc.printf("accel x callback\r\n"); |
michaeljkoster | 9:6501da9e384e | 24 | pc.printf("accel x %s\r\n", x); |
michaeljkoster | 9:6501da9e384e | 25 | |
michaeljkoster | 9:6501da9e384e | 26 | if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) |
michaeljkoster | 9:6501da9e384e | 27 | { |
michaeljkoster | 9:6501da9e384e | 28 | coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); |
michaeljkoster | 9:6501da9e384e | 29 | |
michaeljkoster | 9:6501da9e384e | 30 | coap_res_ptr->payload_len = strlen(x); |
michaeljkoster | 9:6501da9e384e | 31 | coap_res_ptr->payload_ptr = (uint8_t*)x; |
michaeljkoster | 9:6501da9e384e | 32 | sn_nsdl_send_coap_message(address, coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 33 | } |
michaeljkoster | 9:6501da9e384e | 34 | |
michaeljkoster | 9:6501da9e384e | 35 | sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 36 | |
michaeljkoster | 9:6501da9e384e | 37 | return 0; |
michaeljkoster | 9:6501da9e384e | 38 | } |
michaeljkoster | 9:6501da9e384e | 39 | |
michaeljkoster | 9:6501da9e384e | 40 | static uint8_t accel_y_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) |
michaeljkoster | 9:6501da9e384e | 41 | { |
michaeljkoster | 9:6501da9e384e | 42 | sn_coap_hdr_s *coap_res_ptr = 0; |
michaeljkoster | 9:6501da9e384e | 43 | sprintf(y,"%1.2f", axis6.fGay); |
michaeljkoster | 9:6501da9e384e | 44 | pc.printf("accel y callback\r\n"); |
michaeljkoster | 9:6501da9e384e | 45 | pc.printf("accel y %s\r\n", y); |
michaeljkoster | 9:6501da9e384e | 46 | |
michaeljkoster | 9:6501da9e384e | 47 | if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) |
michaeljkoster | 9:6501da9e384e | 48 | { |
michaeljkoster | 9:6501da9e384e | 49 | coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); |
michaeljkoster | 9:6501da9e384e | 50 | |
michaeljkoster | 9:6501da9e384e | 51 | coap_res_ptr->payload_len = strlen(y); |
michaeljkoster | 9:6501da9e384e | 52 | coap_res_ptr->payload_ptr = (uint8_t*)y; |
michaeljkoster | 9:6501da9e384e | 53 | sn_nsdl_send_coap_message(address, coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 54 | } |
michaeljkoster | 9:6501da9e384e | 55 | |
michaeljkoster | 9:6501da9e384e | 56 | sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 57 | |
michaeljkoster | 9:6501da9e384e | 58 | return 0; |
michaeljkoster | 9:6501da9e384e | 59 | } |
michaeljkoster | 9:6501da9e384e | 60 | |
michaeljkoster | 9:6501da9e384e | 61 | static uint8_t accel_z_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) |
michaeljkoster | 9:6501da9e384e | 62 | { |
michaeljkoster | 9:6501da9e384e | 63 | sn_coap_hdr_s *coap_res_ptr = 0; |
michaeljkoster | 9:6501da9e384e | 64 | sprintf(z,"%1.2f", axis6.fGaz); |
michaeljkoster | 9:6501da9e384e | 65 | pc.printf("accel z callback\r\n"); |
michaeljkoster | 9:6501da9e384e | 66 | pc.printf("accel z %s\r\n", z); |
michaeljkoster | 9:6501da9e384e | 67 | |
michaeljkoster | 9:6501da9e384e | 68 | if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) |
michaeljkoster | 9:6501da9e384e | 69 | { |
michaeljkoster | 9:6501da9e384e | 70 | coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); |
michaeljkoster | 9:6501da9e384e | 71 | |
michaeljkoster | 9:6501da9e384e | 72 | coap_res_ptr->payload_len = strlen(z); |
michaeljkoster | 9:6501da9e384e | 73 | coap_res_ptr->payload_ptr = (uint8_t*)z; |
michaeljkoster | 9:6501da9e384e | 74 | sn_nsdl_send_coap_message(address, coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 75 | } |
michaeljkoster | 9:6501da9e384e | 76 | |
michaeljkoster | 9:6501da9e384e | 77 | sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); |
michaeljkoster | 9:6501da9e384e | 78 | |
michaeljkoster | 9:6501da9e384e | 79 | return 0; |
michaeljkoster | 9:6501da9e384e | 80 | } |
michaeljkoster | 9:6501da9e384e | 81 | |
michaeljkoster | 9:6501da9e384e | 82 | int create_accel_resource(sn_nsdl_resource_info_s *resource_ptr) |
michaeljkoster | 9:6501da9e384e | 83 | { |
michaeljkoster | 9:6501da9e384e | 84 | nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_X_RES_ID)-1, (uint8_t*)ACCEL_X_RES_ID, 0, 0, 0, &accel_x_resource_cb, (SN_GRS_GET_ALLOWED)); |
michaeljkoster | 9:6501da9e384e | 85 | nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_Y_RES_ID)-1, (uint8_t*)ACCEL_Y_RES_ID, 0, 0, 0, &accel_y_resource_cb, (SN_GRS_GET_ALLOWED)); |
michaeljkoster | 9:6501da9e384e | 86 | nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_Z_RES_ID)-1, (uint8_t*)ACCEL_Z_RES_ID, 0, 0, 0, &accel_z_resource_cb, (SN_GRS_GET_ALLOWED)); |
michaeljkoster | 9:6501da9e384e | 87 | return 0; |
michaeljkoster | 9:6501da9e384e | 88 | } |