mbed Sensor node for Instrumented Booth over ETH.
Dependencies: EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib
Fork of Trenton_Switch_LPC1768_ETH by
Revision 32:c957a1948ac1, committed 2014-12-11
- Comitter:
- erigow01
- Date:
- Thu Dec 11 17:15:04 2014 +0000
- Parent:
- 31:389416beb4c3
- Child:
- 33:d39c30e9264b
- Child:
- 34:5678fdb45d84
- Commit message:
- Updated for height.
Changed in this revision
--- a/MaxbotixDriver.lib Tue Dec 09 11:41:28 2014 +0000 +++ b/MaxbotixDriver.lib Thu Dec 11 17:15:04 2014 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ASE/code/MaxbotixDriver/#01c215cac993 +http://mbed.org/users/DanielC/code/MaxbotixDriver/#7e65f5077f5a
--- a/NSDL/nsdl_run.cpp Tue Dec 09 11:41:28 2014 +0000 +++ b/NSDL/nsdl_run.cpp Thu Dec 11 17:15:04 2014 +0000 @@ -18,7 +18,7 @@ /* Change this IP address to that of your NanoService Platform installation */ uint8_t NSP_address_bytes[] = NSP_IP_ADDRESS_BYTES; -uint8_t endpoint_name[30] = NODE_NAME; +uint8_t endpoint_name[30] = NODE_NAME; uint8_t ep_type[] = ENDPOINT_TYPE; uint8_t lifetime_ptr[] = LIFE_TIME;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Presence.lib Thu Dec 11 17:15:04 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ASE/code/Presence/#21320a151be0
--- a/Presence/Presence.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - Presence.cpp - presence sensor library - Developed by Andrea Corrado & Eric Gowland - - Connect to a hardware device that is boolean present/not present. Such as PIR or Rangefinder with appropriate signalling. - Also drives LED as presence indicator. -*/ - - -#include "mbed.h" -#include "Presence.h" - - - -Presence::Presence(PinName pin, bool true_on_rise, int debounce_time_ms):_myint(pin), _led1(LED1) -{ - debounce_ms = debounce_time_ms; - _true_on_rise = true_on_rise; -// if(true_on_rise) { -// _myint.rise(this, &Presence::presence_interrupt_off); -// _myint.fall(this, &Presence::presence_interrupt_on); -// } else { -// _myint.rise(this, &Presence::presence_interrupt_on); -// _myint.fall(this, &Presence::presence_interrupt_off); -// } - _detection=false; -// debounce_timer.start(); - _led1=1; - -} - -void Presence::presence_interrupt_off(){ - if(debounce_timer.read_ms() > debounce_ms) { - _detection=false; - _led1=1; - } -} - -void Presence::presence_interrupt_on() //Detection of motion. -{ - //Always trigger detection.. - _detection=true; - _led1=0; - debounce_timer.reset(); // Reset counter to 0... -} - -bool Presence::isPresent(){ -// if (debounce_timer.read_ms() > debounce_ms) { - //Poll the pin and update value... - _detection = (_true_on_rise && _myint == 1) || (!_true_on_rise && _myint == 0); - if(_detection) _led1 = 0; else _led1 = 1; -// } - return _detection; -} \ No newline at end of file
--- a/Presence/Presence.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - Presence.cpp - presence sensor library - Developed by Andrea Corrado & Eric Gowland - - Connect to a hardware device that is boolean present/not present. Such as PIR or Rangefinder with appropriate signalling. - Also drives LED as presence indicator. -*/ - -#ifndef MBED_PIR_H -#define MBED_PIR_H - -#include "mbed.h" - -class Presence{ - -public: - - Presence(PinName pin, bool true_on_rise, int debounce_time_ms); - bool isPresent(); - -private: - InterruptIn _myint; - DigitalOut _led1; - bool _detection; - bool _true_on_rise; - int debounce_ms; - Timer debounce_timer; - void presence_interrupt_on(); - void presence_interrupt_off(); - -}; - -#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources.lib Thu Dec 11 17:15:04 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ASE/code/Resources/#ad57a552e2f0
--- a/Resources/door_trip.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -// door_trip (from Sharpir) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" -#include "sensor_ctl.h" -#include "node_cfg.h" - -#define DOOR_TRIP_RES_ID "/sen/door/trip" -#define DOOR_TRIP_RES_RT "Door Trip" - - -#if NODE_DOOR_TRIP_STATION -extern bool current_door_trip_value; -static char door_trip_val[2]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -static uint8_t obs_number = 0; -static uint8_t *obs_token_ptr = NULL; -static uint8_t obs_token_len = 0; - - -//This is to be called from main program loop... it only sends report if door tripped. -void door_trip_report() { - if(obs_number != 0){ - obs_number++; - snprintf(door_trip_val,2,"%d" ,current_door_trip_value); - if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)door_trip_val, 1, &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) { - printf("Door Trip Observation Sending Failed\r\n"); - } else { - printf("Door Trip Observation Sent\r\n"); - } - } -} - - - -/* Only GET method allowed */ -static uint8_t door_trip_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; - snprintf(door_trip_val,2,"%d" ,current_door_trip_value); - printf("door_trip callback\r\n"); - printf("door_trip: %s\r\n", door_trip_val); - - 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(door_trip_val); - coap_res_ptr->payload_ptr = (uint8_t*)door_trip_val; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - - if(received_coap_ptr->token_ptr){ - 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++; - } - printf(" Send observation %d... \r\n", obs_number); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_door_trip_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - obs_number++; - nsdl_create_dynamic_resource(resource_ptr, sizeof(DOOR_TRIP_RES_ID)-1, (uint8_t*)DOOR_TRIP_RES_ID, sizeof(DOOR_TRIP_RES_RT)-1, (uint8_t*)DOOR_TRIP_RES_RT, 1, &door_trip_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/door_trip.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Door trip (from SHARPPIR) sensor resource implementation - -#ifndef DOOR_TRIP_H -#define DOOR_TRIP_H - -#include "nsdl_support.h" - -int create_door_trip_resource(sn_nsdl_resource_info_s *resource_ptr); -void door_trip_report(); -#endif // DOOR_TRIP
--- a/Resources/height.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -// height (from Maxbotix) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" -#include "sensor_ctl.h" -#include "node_cfg.h" - -#define HEIGHT_RES_ID "/sen/height" -#define HEIGHT_RES_RT "Height" - -#if NODE_HEIGHT_STATION -extern float current_height_value; -static char height_val[6]; -static uint8_t max_age = 0; -static uint8_t content_type = 50; - -/* 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; - - - -//This is to be called from main program loop... it only sends report if height taken. -void height_report() { - if(obs_number != 0){// && obs_token_ptr != NULL){ - obs_number++; - snprintf(height_val,6,"%2.2f" ,current_height_value); - if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)height_val, strlen(height_val), &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) { - printf("Height Observation Sending Failed\r\n"); - } else { - printf("Height Observation Sent\r\n"); - } - } -} - -/* Only GET method allowed */ -static uint8_t height_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; - snprintf(height_val,6,"%2.2f" ,current_height_value); - printf("height callback\r\n"); - printf("height: %s\r\n", height_val); - - 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(height_val); - coap_res_ptr->payload_ptr = (uint8_t*)height_val; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - - if(received_coap_ptr->token_ptr){ - 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++; - } - printf(" Send observation %d... \r\n", obs_number); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_height_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - obs_number++; - nsdl_create_dynamic_resource(resource_ptr, sizeof(HEIGHT_RES_ID)-1, (uint8_t*)HEIGHT_RES_ID, sizeof(HEIGHT_RES_RT)-1, (uint8_t*)HEIGHT_RES_RT, 1, &height_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/height.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Height (from Maxbotix) sensor resource implementation - -#ifndef HEIGHT_H -#define HEIGHT_H - -#include "nsdl_support.h" - -int create_height_resource(sn_nsdl_resource_info_s *resource_ptr); -void height_report(); -#endif // HEIGHT
--- a/Resources/presence_resource.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -// presence sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" - -#include "node_cfg.h" - -#define MOTION_RES_ID "/sen/presence" -#define MOTION_RES_RT "Presence" - -#if NODE_PIR_STATION || NODE_KIOSK_STATION -extern bool current_presence_value; //Either from Kiosk or PIR -static char motion_val[2]; -static uint8_t content_type = 50; - - -/* 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; - - -//This is to be called from main program loop... it only sends report if motion. -void presence_report() { - if(obs_number != 0){ - obs_number++; - snprintf(motion_val,2,"%d" ,current_presence_value); - if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)motion_val, 1, &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) { - printf("Presence Observation Sending Failed\r\n"); - } else { - printf("Presence Observation Sent\r\n"); - } - } -} - -/* Only GET method allowed */ -static uint8_t presence_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; - snprintf(motion_val,2,"%d" ,current_presence_value); - printf("presence callback\r\n"); - printf("presence: %s\r\n", motion_val); - - 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(motion_val); - coap_res_ptr->payload_ptr = (uint8_t*)motion_val; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - - if(received_coap_ptr->token_ptr){ - 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++; - } - printf(" Send observation %d... \r\n", obs_number); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_presence_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - obs_number++; - nsdl_create_dynamic_resource(resource_ptr, sizeof(MOTION_RES_ID)-1, (uint8_t*)MOTION_RES_ID, sizeof(MOTION_RES_RT)-1, (uint8_t*)MOTION_RES_RT, 1, &presence_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/presence_resource.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Motion (from PIR) sensor resource implementation - -#ifndef MOTION_H -#define MOTION_H - -#include "nsdl_support.h" - -int create_presence_resource(sn_nsdl_resource_info_s *resource_ptr); -void presence_report(); -#endif // MOTION
--- a/Resources/sound_level.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -// sound_level (from barometer) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" -#include "sensor_ctl.h" -#include "node_cfg.h" - - -#define SOUND_LEVEL_RES_ID "/sen/sound" -#define SOUND_LEVEL_RES_RT "Sound Level" - -#if NODE_SENSOR_STATION -static char sound_level_val[6]; -static uint8_t content_type = 50; - - -/* 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; - - - -//This is to be called from main program loop... it sends volume on request. -void sound_level_report() { - if(obs_number != 0){// && obs_token_ptr != NULL){ - obs_number++; - snprintf(sound_level_val,6,"%2.2f" ,current_ambient_noise_value); - printf("sound_level report\r\n"); - printf("sound_level: %s\r\n", sound_level_val); - if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)sound_level_val, strlen(sound_level_val), &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) { - printf("Sound Observation Sending Failed\r\n"); - } else { - printf("Sound Observation Sent\r\n"); - } - } -} - -/* Only GET method allowed */ -static uint8_t sound_level_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; - snprintf(sound_level_val,6,"%2.2f" ,current_ambient_noise_value); - printf("sound_level callback\r\n"); - printf("sound_level: %s\r\n", sound_level_val); - - 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(sound_level_val); - coap_res_ptr->payload_ptr = (uint8_t*)sound_level_val; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - - if(received_coap_ptr->token_ptr){ - 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++; - } - printf(" Send observation %d... \r\n", obs_number); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_sound_level_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - obs_number++; - nsdl_create_dynamic_resource(resource_ptr, sizeof(SOUND_LEVEL_RES_ID)-1, (uint8_t*)SOUND_LEVEL_RES_ID, sizeof(SOUND_LEVEL_RES_RT)-1, (uint8_t*)SOUND_LEVEL_RES_RT, 1, &sound_level_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/sound_level.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -// Sound Level (from MAX9814) sensor resource implementation - -#ifndef SOUND_LEVEL_H -#define SOUND_LEVEL_H - -#include "nsdl_support.h" - -int create_sound_level_resource(sn_nsdl_resource_info_s *resource_ptr); -void sound_level_report(); -#endif // SOUND_LEVEL
--- a/Resources/temperature.cpp Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -// temperature (from barometer) sensor resource implementation - -#include "mbed.h" -#include "nsdl_support.h" -#include "sensor_ctl.h" -#include "node_cfg.h" - - -#define TEMPERATURE_RES_ID "/sen/temp" -#define TEMPERATURE_RES_RT "Temperature" - -#if NODE_SENSOR_STATION -static uint8_t content_type = 50; - -/* 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 temperature_val[6]; - -//This is to be called from main program loop... sends temp on request. -void temperature_report() { - if(obs_number != 0){// && obs_token_ptr != NULL){ - obs_number++; - snprintf(temperature_val,6,"%2.2f" ,current_temperature_value); - if(sn_nsdl_send_observation_notification(obs_token_ptr, obs_token_len, (uint8_t*)temperature_val, strlen(temperature_val), &obs_number, 1, COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0) { - printf("Temperature Observation Sending Failed\r\n"); - } else { - printf("Temperature Observation Sent\r\n"); - } - } -} - -/* Only GET method allowed */ -static uint8_t temperature_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; - snprintf(temperature_val,6,"%2.2f", current_temperature_value); - printf("temperature callback\r\n"); - printf("temperature: %s\r\n", temperature_val); - - 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(temperature_val); - coap_res_ptr->payload_ptr = (uint8_t*)temperature_val; - - coap_res_ptr->content_type_ptr = &content_type; - coap_res_ptr->content_type_len = sizeof(content_type); - - - if(received_coap_ptr->token_ptr){ - 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++; - } - printf(" Send observation %d... \r\n", obs_number); - - sn_nsdl_send_coap_message(address, coap_res_ptr); - nsdl_free(coap_res_ptr->options_list_ptr); - coap_res_ptr->options_list_ptr = NULL; - coap_res_ptr->content_type_ptr = NULL;// parser_release below tries to free this memory - - } - - sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - - return 0; -} - -int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr) -{ - obs_number++; - nsdl_create_dynamic_resource(resource_ptr, sizeof(TEMPERATURE_RES_ID)-1, (uint8_t*)TEMPERATURE_RES_ID, sizeof(TEMPERATURE_RES_RT)-1, (uint8_t*)TEMPERATURE_RES_RT, 1, &temperature_resource_cb, (SN_GRS_GET_ALLOWED)); - return 0; -} -#endif
--- a/Resources/temperature.h Tue Dec 09 11:41:28 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -// Temperature (from Barometer) sensor resource implementation - -#ifndef TEMPERATURE_H -#define TEMPERATURE_H - -#include "nsdl_support.h" - -int create_temperature_resource(sn_nsdl_resource_info_s *resource_ptr); -void temperature_report(); -#endif // TEMPERATURE -
--- a/main.cpp Tue Dec 09 11:41:28 2014 +0000 +++ b/main.cpp Thu Dec 11 17:15:04 2014 +0000 @@ -91,7 +91,7 @@ Endpoint from; memset(&received_packet_address, 0, sizeof(sn_nsdl_addr_s)); received_packet_address.addr_ptr = received_address; - server.set_blocking(false, 1500); + server.set_blocking(false, 50); //Check incoming socket... int n = 0;
--- a/node_cfg.h Tue Dec 09 11:41:28 2014 +0000 +++ b/node_cfg.h Thu Dec 11 17:15:04 2014 +0000 @@ -10,24 +10,56 @@ //Which Sensors #define NODE_SENSOR_STATION 1 // use K64F platform. Base sensor platform. Includes Microphone, temperature. #define NODE_HEIGHT_STATION 1 // use K64F platform. This include door height sensor -#define NODE_KIOSK_STATION 0 // use K64F platform. This includes kiosk presence sensor -#define NODE_DOOR_TRIP_STATION 0 // use K64F platform. This includes door tripwire sensor +#define NODE_KIOSK_STATION 0 // use K64F platform. This includes kiosk presence sensor +#define NODE_DOOR_TRIP_STATION 1 // use K64F platform. This includes door tripwire sensor #define NODE_PIR_STATION 0 // use K64F platform. This includes pir motion sensor /*************** NODE PROFILE CONFIGURATION *****************/ -#define NODE_SHORT_ADDRESS 5 -#define NODE_MAC_ADDRESS {0,0,6,0x02,0x00,0x00,0x09,0x02} -#define NODE_NAME "mbed-sensor-station-height" +/** CES NODE DEFINITIONS **/ + +#if NODE_6LOWPAN +//6LoWPAN Sensors... +#define ENDPOINT_TYPE {"mbed-sensor-6LoWPAN"} + +//#define NODE_SHORT_ADDRESS 01 //mbed Meeting Room +//#define NODE_NAME "mbed-sensor-mbed" +//#define NODE_SHORT_ADDRESS 02 //Cortex Meeting Room +//#define NODE_NAME "mbed-sensor-Cortex" +//#define NODE_SHORT_ADDRESS 03 //Artisan Meeting Room +//#define NODE_NAME "mbed-sensor-Artisan" +//#define NODE_SHORT_ADDRESS 04 //Mali Meeting Room +//#define NODE_NAME "mbed-sensor-Mali" +//#define NODE_SHORT_ADDRESS 05 //Casual Seating Area 1 +//#define NODE_NAME "mbed-sensor-Casual-1" +//#define NODE_SHORT_ADDRESS 06 //Casual Seating Area 2 +//#define NODE_NAME "mbed-sensor-Casual-2" +//#define NODE_SHORT_ADDRESS 07 //Reception +//#define NODE_NAME "mbed-sensor-Reception" + +#define GENERATE_MAC_ADDRESS(short) {0,0,6,0x02,0x00,0x00,0x09,0x ## short ## } +#define NODE_MAC_ADDRESS GENERATE_MAC_ADDRESS(NODE_SHORT_ADDRESS) //{0,0,6,0x02,0x00,0x00,0x09,0x02} + +#else +//Ethernet Sensors... +#define ENDPOINT_TYPE {"mbed-sensor-Ethernet"} + +#define NODE_NAME "mbed-sensor-demo-door" +//#define NODE_NAME "mbed-sensor-demo-1" +//#define NODE_NAME "mbed-sensor-demo-2" +//#define NODE_NAME "mbed-sensor-demo-3" +//#define NODE_NAME "mbed-sensor-demo-4" -#define ENDPOINT_TYPE {"mbed-device"} +#endif //Node comms Type + #define LIFE_TIME {"600"} //seconds, extra char needed to avoid truncation + // **************************************************************************** // Ethernet Config... - +#if NODE_ETHERNET // Ethernet configuration /* Define this to enable DHCP, otherwise manual address configuration is used */ #define DHCP @@ -36,7 +68,7 @@ #define IP "192.168.1.10" #define MASK "255.255.255.0" #define GW "10.45.0.1" - +#endif //ETHERNET // **************************************************************************** @@ -46,11 +78,11 @@ #define NSP_IP_ADDRESS "192.168.1.100" //IPv4 -#ifdef NODE_6LOWPAN +#if NODE_6LOWPAN #define NSP_IP_ADDRESS_BYTES {0x20, 0x02, 0x0d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01} //IPv6 -#else +#else // Not NODE_6LOWPAN //Default to IPv4 #define NSP_IP_ADDRESS_BYTES {0xc0, 0xa8, 0x01, 0x64} //IPv4 -#endif // NODE_6LOW_PAN +#endif // NODE_ETHERNET #endif // NODE_CFG_H_ \ No newline at end of file
--- a/sensor_ctl.cpp Tue Dec 09 11:41:28 2014 +0000 +++ b/sensor_ctl.cpp Thu Dec 11 17:15:04 2014 +0000 @@ -32,7 +32,14 @@ SHARPIR sharpir(PTC11); //(AnalogIn required), for IR door trip #endif //NODE TRIP STATION #if NODE_HEIGHT_STATION -MAXBOTIX Sonar(PTC10, SW2); //(AnalogIn required, Leave as SW2.) +Timer sonarTimer; +Timer debounceHeight; +Sonar sonar(PTC10, sonarTimer); //(AnalogIn required, Leave as SW2.) + +#define DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM 150 +#define DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM 140 +#define DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT 2 +#define DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM 220 #endif //NODE HEIGHT STATION #endif //NODE_SENSOR_STATION @@ -48,8 +55,11 @@ //Door trip... float door_trip_starting_volts = 0; -float maxValue=0; -bool set=0; + +//Door Height... +float door_height_max_value = 0; +bool door_height_measuring = 0; +bool door_height_sample_count = 0; //Initialisation @@ -57,6 +67,9 @@ #if NODE_DOOR_TRIP_STATION door_trip_starting_volts = sharpir.volt(); #endif + #if NODE_HEIGHT_STATION + sonarTimer.start(); + #endif } #if NODE_SENSOR_STATION @@ -132,24 +145,25 @@ #if NODE_HEIGHT_STATION void handle_door_height_sample_timer(){ - - float height_sample = Sonar.data_conversion_m(); - printf("Height Sample: %2.2f \r\n", height_sample); - if(height_sample>1) { - if (height_sample>maxValue) { - maxValue = height_sample; - } - set=true; + int height_sample = DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM-sonar.read(); + if(height_sample > DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM) { + door_height_sample_count=0; + if (height_sample > door_height_max_value) { + door_height_max_value = height_sample; + } + door_height_measuring=true; } - if(height_sample<1 && set) { - current_height_value=maxValue; - maxValue=0,set=false; - printf("Height Update: %2.2f \r\n", current_height_value); - height_report(); + if((height_sample < DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM && door_height_measuring )){ + door_height_sample_count++; + if (door_height_sample_count > DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT){ + current_height_value=door_height_max_value; + door_height_max_value=0,door_height_measuring=false; + door_height_sample_count = 0; + height_report(); + } } - } +#endif //NODE HEIGHT STATION -#endif //NODE HEIGHT STATION #endif //NODE_SENSOR_STATION \ No newline at end of file