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:
MACRUM
Date:
Mon May 12 06:02:52 2014 +0000
Revision:
8:f5f58eb0af34
Parent:
2:7e489126fe7a
Initial release

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 "relay.h"
bogdanm 2:7e489126fe7a 6 #include "Beep.h"
bogdanm 2:7e489126fe7a 7
bogdanm 2:7e489126fe7a 8 #define RELAY_RES_ID "beep/0/on"
bogdanm 2:7e489126fe7a 9
bogdanm 2:7e489126fe7a 10 extern Serial pc;
bogdanm 2:7e489126fe7a 11 static Beep buzzer(p26);
bogdanm 2:7e489126fe7a 12
bogdanm 2:7e489126fe7a 13 /* Only GET and PUT method allowed */
bogdanm 2:7e489126fe7a 14 static uint8_t relay_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
bogdanm 2:7e489126fe7a 15 {
bogdanm 2:7e489126fe7a 16 sn_coap_hdr_s *coap_res_ptr = 0;
bogdanm 2:7e489126fe7a 17 static uint8_t relay_state = '0';
bogdanm 2:7e489126fe7a 18
bogdanm 2:7e489126fe7a 19 pc.printf("relay callback\r\n");
bogdanm 2:7e489126fe7a 20
bogdanm 2:7e489126fe7a 21 if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
bogdanm 2:7e489126fe7a 22 {
bogdanm 2:7e489126fe7a 23 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
bogdanm 2:7e489126fe7a 24
bogdanm 2:7e489126fe7a 25 coap_res_ptr->payload_len = 1;
bogdanm 2:7e489126fe7a 26 coap_res_ptr->payload_ptr = &relay_state;
bogdanm 2:7e489126fe7a 27 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 28 }
bogdanm 2:7e489126fe7a 29 else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
bogdanm 2:7e489126fe7a 30 {
bogdanm 2:7e489126fe7a 31 if(received_coap_ptr->payload_len)
bogdanm 2:7e489126fe7a 32 {
bogdanm 2:7e489126fe7a 33 if(*(received_coap_ptr->payload_ptr) == '1')
bogdanm 2:7e489126fe7a 34 {
bogdanm 2:7e489126fe7a 35 buzzer.beep(1000,0);
bogdanm 2:7e489126fe7a 36 relay_state = '1';
bogdanm 2:7e489126fe7a 37
bogdanm 2:7e489126fe7a 38 }
bogdanm 2:7e489126fe7a 39 else if(*(received_coap_ptr->payload_ptr) == '0')
bogdanm 2:7e489126fe7a 40 {
bogdanm 2:7e489126fe7a 41 buzzer.nobeep();
bogdanm 2:7e489126fe7a 42 relay_state = '0';
bogdanm 2:7e489126fe7a 43 }
bogdanm 2:7e489126fe7a 44 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
bogdanm 2:7e489126fe7a 45 sn_nsdl_send_coap_message(address, coap_res_ptr);
bogdanm 2:7e489126fe7a 46 }
bogdanm 2:7e489126fe7a 47 }
bogdanm 2:7e489126fe7a 48
bogdanm 2:7e489126fe7a 49 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
bogdanm 2:7e489126fe7a 50
bogdanm 2:7e489126fe7a 51 return 0;
bogdanm 2:7e489126fe7a 52 }
bogdanm 2:7e489126fe7a 53
bogdanm 2:7e489126fe7a 54 int create_relay_resource(sn_nsdl_resource_info_s *resource_ptr)
bogdanm 2:7e489126fe7a 55 {
bogdanm 2:7e489126fe7a 56 nsdl_create_dynamic_resource(resource_ptr, sizeof(RELAY_RES_ID)-1, (uint8_t*)RELAY_RES_ID, 0, 0, 0, &relay_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED));
bogdanm 2:7e489126fe7a 57 return 0;
bogdanm 2:7e489126fe7a 58 }