Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface PololuLedStripx mbed-rtos mbed nanoservice_client_1_12_X
Fork of LPC1768_LWM2M_Client by
Revision 1:09a525977925, committed 2014-09-27
- Comitter:
- michaeljkoster
- Date:
- Sat Sep 27 21:53:28 2014 +0000
- Parent:
- 0:9101343a70cd
- Child:
- 2:4166c3e5b321
- Commit message:
- Client for Tech Con demo, resource stub
Changed in this revision
--- a/Beep.lib Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/shimniok/code/Beep/#3eb39e374fc3
--- a/C12832_lcd.lib Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- a/EthernetInterface.lib Tue Jul 22 23:58:23 2014 +0000 +++ b/EthernetInterface.lib Sat Sep 27 21:53:28 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#e6b79f0ccd95 +http://mbed.org/users/mbed_official/code/EthernetInterface/#6ca542f6c58d
--- a/LM75B.lib Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
--- a/MMA7660.lib Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
--- a/main.cpp Tue Jul 22 23:58:23 2014 +0000
+++ b/main.cpp Sat Sep 27 21:53:28 2014 +0000
@@ -1,15 +1,10 @@
#include "mbed.h"
#include "EthernetInterface.h"
-#include "C12832_lcd.h"
#include "nsdl_support.h"
#include "dbg.h"
-// Include various resources
-#include "temperature.h"
+// Include resources
#include "light.h"
-#include "gps.h"
-#include "relay.h"
-static C12832_LCD lcd;
Serial pc(USBTX, USBRX); // tx, rx
// ****************************************************************************
@@ -20,19 +15,19 @@
#define DHCP
/* Manual IP configurations, if DHCP not defined */
-#define IP "10.45.0.206"
+#define IP "10.0.0.199"
#define MASK "255.255.255.0"
-#define GW "10.45.0.1"
+#define GW "10.0.0.1"
// NSP configuration
/* Change this IP address to that of your NanoService Platform installation */
//static const char* NSP_ADDRESS = "217.140.101.20"; /* public mbed demo server */
-static const char* NSP_ADDRESS = "192.168.1.220"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/
-//static const char* NSP_ADDRESS = "192.168.1.200"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/
+static const char* NSP_ADDRESS = "23.99.99.252"; // barista.cloudapp.net
+//static const char* NSP_ADDRESS = "192.168.1.200";
static const int NSP_PORT = 5683;
-char endpoint_name[16] = "mbed-";
+char endpoint_name[24] = "mbed-LED-booth-1";
uint8_t ep_type[] = {"mbed_device"};
-uint8_t lifetime_ptr[] = {"1200"};
+uint8_t lifetime_ptr[] = {"60"};
// ****************************************************************************
// Ethernet initialization
@@ -41,25 +36,19 @@
static void ethernet_init()
{
- char mbed_uid[33]; // for creating unique name for the board
/* Initialize network */
#ifdef DHCP
NSDL_DEBUG("DHCP in use\r\n");
eth.init();
+ NSDL_DEBUG("eth.init\r\n");
#else
eth.init(IP, MASK, GW);
+ NSDL_DEBUG("eth.init\r\n");
#endif
if(eth.connect(30000) == 0)
pc.printf("Connect OK\n\r");
- mbed_interface_uid(mbed_uid);
- mbed_uid[32] = '\0';
- strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
-
- lcd.locate(0,11);
- lcd.printf("IP:%s", eth.getIPAddress());
-
NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
}
@@ -79,8 +68,6 @@
NSDL_DEBUG("name: %s", endpoint_name);
NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
- lcd.locate(0,22);
- lcd.printf("EP name:%s\n", endpoint_name);
}
// ****************************************************************************
@@ -112,10 +99,7 @@
nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0, (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
// Dynamic resources
- create_temperature_resource(resource_ptr);
create_light_resource(resource_ptr);
- create_gps_resource(resource_ptr);
- create_relay_resource(resource_ptr);
/* Register with NSP */
endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
@@ -135,9 +119,6 @@
int main()
{
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("mbed NanoService demo");
NSDL_DEBUG("mbed NanoService Example App 0.1\n");
// Initialize Ethernet interface first
--- a/mbed-rtos.lib Tue Jul 22 23:58:23 2014 +0000 +++ b/mbed-rtos.lib Sat Sep 27 21:53:28 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#ff95651f53c7 +http://mbed.org/users/mbed_official/code/mbed-rtos/#631c0f1008c3
--- a/mbed.bld Tue Jul 22 23:58:23 2014 +0000 +++ b/mbed.bld Sat Sep 27 21:53:28 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nanoservice_client_1_12_X.lib Sat Sep 27 21:53:28 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/michaeljkoster/code/nanoservice_client_1_12_X/#2b79bf135ec2
--- a/nsdl_lib.lib Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Sensinode/code/nsdl_lib/#388450b1e776
--- a/nsdl_support.cpp Tue Jul 22 23:58:23 2014 +0000
+++ b/nsdl_support.cpp Sat Sep 27 21:53:28 2014 +0000
@@ -5,26 +5,47 @@
#include "mbed.h"
#include "rtos.h"
#include "EthernetInterface.h"
+#include "UDPSocket.h"
+#include "Endpoint.h"
+
+/* __heapvalid((__heapprt)fprintf,stdout, 1);\*/
+#define MEM_VALID(x) \
+ int s##x=0;\
+ int *h##x = new int [1];\
+ std::printf("[stack]0x%08x\t[heap]0x%08x\t[memory avail]%d bytes \tLine: %d %s\r\n", &s##x, h##x, &s##x-h##x, __LINE__, __FILE__);\
+ if (h##x > &s##x)\
+ printf("collision\n");\
+ else\
+ delete [] h##x;\
+ __nop()
extern Serial pc;
-extern EthernetInterface eth;
extern Endpoint nsp;
extern UDPSocket server;
-extern char endpoint_name[16];
+extern char endpoint_name[24];
extern uint8_t ep_type[];
extern uint8_t lifetime_ptr[];
+char null_ep_name[] = "";
+uint8_t null_ep_type[] = "";
+uint8_t null_lifetime_ptr[] = "";
+bool nsdl_reg_update_needed = false;
/* The number of seconds between NSP registration messages */
-#define RD_UPDATE_PERIOD 60
+#define RD_UPDATE_PERIOD 30
void *nsdl_alloc(uint16_t size)
{
- return malloc(size);
+ void *buf = malloc(size);
+// printf("alloc\r\n");
+// MEM_VALID(0);
+ return buf;
}
void nsdl_free(void* ptr_to_free)
{
free(ptr_to_free);
+// printf("de-alloc\r\n");
+// MEM_VALID(0);
}
/*
@@ -73,7 +94,7 @@
endpoint_structure->type_ptr = typename_ptr;
endpoint_structure->type_len = strlen((char*)typename_ptr);
endpoint_structure->lifetime_ptr = lifetime_ptr;
- endpoint_structure->lifetime_len = strlen((char*)lifetime_ptr);
+ endpoint_structure->lifetime_len = strlen((char*)lifetime_ptr);
}
return endpoint_structure;
}
@@ -100,6 +121,21 @@
static uint8_t rx_cb(sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *address_ptr)
{
pc.printf("RX callback!\r\n");
+ pc.printf("msg_code: %d \r\n", coap_packet_ptr->msg_code);
+ pc.printf("Payload length: %d bytes\r\n", coap_packet_ptr->payload_len);
+ int i;
+ pc.printf("Payload:'");
+ for (i=0; i < coap_packet_ptr->payload_len; i++)
+ pc.printf("%c", *(coap_packet_ptr->payload_ptr + i));
+ pc.printf("' \r\n");
+ if (coap_packet_ptr->options_list_ptr && coap_packet_ptr->options_list_ptr->location_path_ptr)
+ {
+ pc.printf("Location: /");
+ int i;
+ for (i=0; i < coap_packet_ptr->options_list_ptr->location_path_len; i++) pc.printf("%c", (char)(coap_packet_ptr->options_list_ptr->location_path_ptr[i]));
+ pc.printf(" \r\n");
+ }
+ //sn_coap_packet_debug(coap_packet_ptr);
return 0;
}
@@ -110,8 +146,10 @@
while(true)
{
wait(RD_UPDATE_PERIOD);
- endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
- if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
+ //endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
+ //if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
+ endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)null_ep_name, null_ep_type, null_lifetime_ptr);
+ if(sn_nsdl_update_registration(endpoint_ptr) != 0)
pc.printf("NSP re-registering failed\r\n");
else
pc.printf("NSP re-registering OK\r\n");
@@ -134,7 +172,7 @@
/* Set nsp address for library */
set_NSP_address(nsp_addr, 5683, SN_NSDL_ADDRESS_TYPE_IPV4);
-}
+}
void nsdl_event_loop()
{
--- a/resources/gps.cpp Tue Jul 22 23:58:23 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-// GPS resource implementation
-
-#include "mbed.h"
-#include "nsdl_support.h"
-#include "gps.h"
-
-#define GPS_RES_ID "gps/loc"
-
-extern Serial pc;
-static uint8_t res_gps_val[] = {"52.182382,0.178849"};
-
-/* Only GET method allowed */
-static uint8_t gps_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;
- static float led_dimm = 0;
- int led_state = 0;
- char led_dimm_temp[4];
-
- pc.printf("gps callback\r\n");
-
- coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
-
- led_state = led_dimm * 100;
- sprintf(led_dimm_temp, "%d", led_state);
-
- coap_res_ptr->payload_len = sizeof(res_gps_val)-1;
- coap_res_ptr->payload_ptr = (uint8_t*)res_gps_val;
-
- sn_nsdl_send_coap_message(address, coap_res_ptr);
-
- sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
-
- return 0;
-}
-
-int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr)
-{
- nsdl_create_dynamic_resource(resource_ptr, sizeof(GPS_RES_ID)-1, (uint8_t*)GPS_RES_ID, 0, 0, 0, &gps_resource_cb, SN_GRS_GET_ALLOWED);
- return 0;
-}
\ No newline at end of file
--- a/resources/gps.h Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// GPS resource implementation - -#ifndef GPS_H -#define GPS_H - -#include "nsdl_support.h" - -int create_gps_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif
--- a/resources/light.cpp Tue Jul 22 23:58:23 2014 +0000
+++ b/resources/light.cpp Sat Sep 27 21:53:28 2014 +0000
@@ -4,51 +4,41 @@
#include "nsdl_support.h"
#include "light.h"
-#define LIGHT_RES_ID "lt/0/dim"
+#define LIGHT_RES_ID "11100/0/5900"
extern Serial pc;
-//PwmOut led1(LED1);
-static PwmOut led2(LED2);
-static PwmOut led3(LED3);
-//PwmOut led4(LED4);
+char led_color[] = {"00000000"};
/* Only GET and PUT method allowed */
static uint8_t light_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;
- static float led_dimm = 0;
- int led_state = 0;
- char led_dimm_temp[4];
- pc.printf("light callback\r\n");
+ pc.printf("LED Strip callback\r\n");
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);
- led_state = led_dimm * 100;
- sprintf(led_dimm_temp, "%d", led_state);
-
- coap_res_ptr->payload_len = strlen(led_dimm_temp);
- coap_res_ptr->payload_ptr = (uint8_t*)led_dimm_temp;
+ coap_res_ptr->payload_len = strlen(led_color);
+ coap_res_ptr->payload_ptr = (uint8_t*)led_color;
sn_nsdl_send_coap_message(address, coap_res_ptr);
}
else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
{
- memcpy(led_dimm_temp, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
-
- led_dimm_temp[received_coap_ptr->payload_len] = '\0';
-
- led_dimm = atof(led_dimm_temp);
- led_dimm = led_dimm/100;
+ pc.printf("PUT: %d bytes\r\n", received_coap_ptr->payload_len);
+ if(received_coap_ptr->payload_len == 8)
+ {
+ memcpy(led_color, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
- //led1.write(led_dimm);
- led2.write(led_dimm);
- led3.write(led_dimm);
- //led4.write(led_dimm);
+ led_color[received_coap_ptr->payload_len] = '\0';
+ pc.printf("PUT: %s\r\n",led_color);
- coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
- sn_nsdl_send_coap_message(address, coap_res_ptr);
+ //call LED strup update function here
+
+ coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
+ sn_nsdl_send_coap_message(address, coap_res_ptr);
+ }
}
sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
--- a/resources/relay.cpp Tue Jul 22 23:58:23 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-// GPS resource implementation
-
-#include "mbed.h"
-#include "nsdl_support.h"
-#include "relay.h"
-#include "Beep.h"
-
-#define RELAY_RES_ID "beep/0/on"
-
-extern Serial pc;
-static Beep buzzer(p26);
-
-/* Only GET and PUT method allowed */
-static uint8_t relay_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;
- static uint8_t relay_state = '0';
-
- pc.printf("relay callback\r\n");
-
- 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 = 1;
- coap_res_ptr->payload_ptr = &relay_state;
- sn_nsdl_send_coap_message(address, coap_res_ptr);
- }
- else if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_PUT)
- {
- if(received_coap_ptr->payload_len)
- {
- if(*(received_coap_ptr->payload_ptr) == '1')
- {
- buzzer.beep(1000,0);
- relay_state = '1';
-
- }
- else if(*(received_coap_ptr->payload_ptr) == '0')
- {
- buzzer.nobeep();
- relay_state = '0';
- }
- coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
- sn_nsdl_send_coap_message(address, coap_res_ptr);
- }
- }
-
- sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
-
- return 0;
-}
-
-int create_relay_resource(sn_nsdl_resource_info_s *resource_ptr)
-{
- 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));
- return 0;
-}
\ No newline at end of file
--- a/resources/relay.h Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Relay resource implementation - -#ifndef RELAY_H -#define RELAY_H - -#include "nsdl_support.h" - -int create_relay_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif
--- a/resources/temperature.cpp Tue Jul 22 23:58:23 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-// Temperature resource implementation
-
-#include "mbed.h"
-#include "rtos.h"
-#include "LM75B.h"
-#include "nsdl_support.h"
-#include "temperature.h"
-
-#define TEMP_RES_ID "sen/temp"
-
-static LM75B tmp(p28,p27);
-/* stored data for observable resource */
-static uint8_t obs_number = 0;
-static uint8_t *obs_token_ptr = NULL;
-static uint8_t obs_token_len = 0;
-static char temp_val[5];
-extern Serial pc;
-
-/* Thread for calling libNsdl exec function (cleanup, resendings etc..) */
-/* Node updates temperature every 10 seconds. Notification sending is done here. */
-static void exec_call_thread(void const *args)
-{
- int32_t time = 0;
- while (true)
- {
- wait(1);
- time++;
- sn_nsdl_exec(time);
- if((!(time % 10)) && obs_number != 0 && obs_token_ptr != NULL)
- {
- obs_number++;
- sprintf(temp_val,"%2.2f" ,tmp.read());
- if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)temp_val, 5, &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0)
- pc.printf("Observation sending failed\r\n");
- else
- pc.printf("Observation\r\n");
- }
- }
-}
-
-/* Only GET method allowed */
-/* Observable resource */
-static uint8_t temp_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
-{
- sprintf(temp_val,"%2.2f" ,tmp.read());
- sn_coap_hdr_s *coap_res_ptr = 0;
-
- pc.printf("temp callback\r\n");
- coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
-
- coap_res_ptr->payload_len = 5;
- coap_res_ptr->payload_ptr = (uint8_t*)temp_val;
-
- if(received_coap_ptr->token_ptr)
- {
- pc.printf("Token included\r\n");
- if(obs_token_ptr)
- {
- free(obs_token_ptr);
- obs_token_ptr = 0;
- }
- obs_token_ptr = (uint8_t*)malloc(received_coap_ptr->token_len);
- if(obs_token_ptr)
- {
- memcpy(obs_token_ptr, received_coap_ptr->token_ptr, received_coap_ptr->token_len);
- obs_token_len = received_coap_ptr->token_len;
- }
- }
-
- if(received_coap_ptr->options_list_ptr->observe)
- {
- coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
- memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s));
- coap_res_ptr->options_list_ptr->observe_ptr = &obs_number;
- coap_res_ptr->options_list_ptr->observe_len = 1;
- obs_number++;
- }
-
- sn_nsdl_send_coap_message(address, coap_res_ptr);
-
- coap_res_ptr->options_list_ptr->observe_ptr = 0;
- sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
- return 0;
-}
-
-int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr)
-{
- static Thread exec_thread(exec_call_thread);
-
- nsdl_create_dynamic_resource(resource_ptr, sizeof(TEMP_RES_ID)-1, (uint8_t*)TEMP_RES_ID, 0, 0, 1, &temp_resource_cb, SN_GRS_GET_ALLOWED);
- return 0;
-}
\ No newline at end of file
--- a/resources/temperature.h Tue Jul 22 23:58:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Temperature resource implementation - -#ifndef TEMPERATURE_H -#define TEMPERATURE_H - -#include "nsdl_support.h" - -int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr); - -#endif
