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:
Revision 6:b542b2a759e8, committed 2014-06-14
- Comitter:
- michaeljkoster
- Date:
- Sat Jun 14 08:34:18 2014 +0000
- Parent:
- 5:bacf25e9419b
- Child:
- 7:01d01c5cf409
- Commit message:
- add resources and register
Changed in this revision
--- a/nsdl_run.cpp Sat Jun 14 08:00:41 2014 +0000
+++ b/nsdl_run.cpp Sat Jun 14 08:34:18 2014 +0000
@@ -8,6 +8,7 @@
#include "light.h"
#include "temperature.h"
#include "altitude.h"
+#include "slider.h"
extern Serial pc;
@@ -110,6 +111,7 @@
create_light_resource(resource_ptr);
create_temp_resource(resource_ptr);
create_alt_resource(resource_ptr);
+ create_slider_resource(resource_ptr);
/* Register with NSP */
endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/slider.cpp Sat Jun 14 08:34:18 2014 +0000
@@ -0,0 +1,41 @@
+// battery resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "TSISensor.h"
+
+#define SLIDER_RES_ID "3300/1/5700"
+
+extern Serial pc;
+char sliderPct[5];
+extern TSISensor tsi;
+int slider_position;
+
+/* Only GET method allowed */
+static uint8_t slider_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
+{
+ sn_coap_hdr_s *coap_res_ptr = 0;
+ slider_position = tsi.readPercentage() * 100;
+ sprintf(sliderPct,"%d", slider_position);
+ pc.printf("slider callback\r\n");
+ pc.printf("slider percent %s\r\n", sliderPct);
+
+ if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
+ {
+ coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
+
+ coap_res_ptr->payload_len = strlen(sliderPct);
+ coap_res_ptr->payload_ptr = (uint8_t*)sliderPct;
+ sn_nsdl_send_coap_message(address, coap_res_ptr);
+ }
+
+ sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+ return 0;
+}
+
+int create_slider_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+ nsdl_create_dynamic_resource(resource_ptr, sizeof(SLIDER_RES_ID)-1, (uint8_t*)SLIDER_RES_ID, 0, 0, 0, &slider_resource_cb, (SN_GRS_GET_ALLOWED));
+ return 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources/slider.h Sat Jun 14 08:34:18 2014 +0000 @@ -0,0 +1,10 @@ +// Battery resource implementation + +#ifndef SLIDER_H +#define SLIDER_H + +#include "nsdl_support.h" + +int create_slider_resource(sn_nsdl_resource_info_s *resource_ptr); + +#endif