adding resources firmware and 1/0/8
Dependencies: Beep C12832_lcd EthernetInterface EthernetNetIf HTTPClient LM75B MMA7660 mbed-rtos mbed nsdl_lib
Fork of LWM2M_NanoService_Ethernet by
light.cpp
00001 // Light resource implementation 00002 00003 #include "mbed.h" 00004 #include "nsdl_support.h" 00005 #include "light.h" 00006 00007 #define LIGHT_RES_ID "311/0/5851" 00008 00009 extern Serial pc; 00010 static PwmOut led2(LED2); 00011 static PwmOut led3(LED3); 00012 00013 00014 /* Only GET and PUT method allowed */ 00015 static uint8_t light_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) 00016 { 00017 sn_coap_hdr_s *coap_res_ptr = 0; 00018 static float led_dimm = 0; 00019 int led_state = 0; 00020 char led_dimm_temp[4]; 00021 00022 pc.printf("light callback\r\n"); 00023 00024 if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET) 00025 { 00026 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT); 00027 00028 led_state = led_dimm * 100; 00029 sprintf(led_dimm_temp, "%d", led_state); 00030 00031 coap_res_ptr->payload_len = strlen(led_dimm_temp); 00032 coap_res_ptr->payload_ptr = (uint8_t*)led_dimm_temp; 00033 sn_nsdl_send_coap_message(address, coap_res_ptr); 00034 } 00035 else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT) 00036 { 00037 memcpy(led_dimm_temp, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len); 00038 00039 led_dimm_temp[received_coap_ptr->payload_len] = '\0'; 00040 00041 led_dimm = atof(led_dimm_temp); 00042 led_dimm = led_dimm/100; 00043 00044 led2.write(led_dimm); 00045 led3.write(led_dimm); 00046 00047 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); 00048 sn_nsdl_send_coap_message(address, coap_res_ptr); 00049 } 00050 00051 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); 00052 return 0; 00053 } 00054 00055 int create_light_resource(sn_nsdl_resource_info_s *resource_ptr) 00056 { 00057 nsdl_create_dynamic_resource(resource_ptr, sizeof(LIGHT_RES_ID)-1, (uint8_t*)LIGHT_RES_ID, 0, 0, 0, &light_resource_cb, (SN_GRS_GET_ALLOWED | SN_GRS_PUT_ALLOWED)); 00058 return 0; 00059 }
Generated on Sat Jul 16 2022 02:03:09 by 1.7.2