diff --git a/projects/WEAtHeR/main.c b/projects/WEAtHeR/main.c index 54459dc9c4..aeb555fc97 100644 --- a/projects/WEAtHeR/main.c +++ b/projects/WEAtHeR/main.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "weather_routing.h" #include "weather_protocol.h" @@ -21,7 +23,7 @@ #define SECOND (1000 * 1000) #define MINUTE (60 * SECOND) -#define SENDING_INTERVAL (1 * SECOND) +#define DEFAULT_INTERVAL (60 * SECOND) /* size of weather data packet without hop list */ #define EMPTY_WDP_SIZE (sizeof(weather_data_pkt_t) - MAX_HOP_LIST) @@ -33,16 +35,23 @@ static uint8_t data_sink = 0; static uint8_t data_src = 0; +static uint32_t sending_interval = DEFAULT_INTERVAL; +extern uint8_t gossip_probability; + char shell_stack_buffer[SHELL_STACK_SIZE]; char ph_stack_buffer[PH_STACK_SIZE]; void weather_send(char* unused); void weather_sink(char* unused); +static void set_interval(char* interval); +static void set_probability(char* prob); shell_t shell; const shell_command_t sc[] = { {"sender", "Enables node as data source.", weather_send}, {"sink", "Enables node as data sink.", weather_sink}, + {"int", "Set the sending interval in seconds", set_interval}, + {"prob", "Set the gossiping probability", set_probability}, {NULL, NULL, NULL}}; void shell_runner(void) { @@ -73,6 +82,32 @@ void weather_sink(char* unused) { } } +static void set_interval(char* interval) { + uint16_t a; + + a = atoi(interval+4); + if (strlen(interval) > 4) { + printf("[WEAtHeR] Set interval to %u\n ", a); + sending_interval = a * SECOND; + } + else { + printf("[WEAtHeR] Current interval is %lu\n ", (sending_interval / SECOND)); + } +} + +static void set_probability(char* prob) { + uint16_t a; + + a = atoi(prob+4); + if (strlen(prob) > 4) { + printf("[WEAtHeR] Set probability to %hu\n ", a); + gossip_probability = a; + } + else { + printf("[WEAtHeR] Current probability is %hu\n ", gossip_probability); + } +} + static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { weather_packet_header_t *header = (weather_packet_header_t*) msg; @@ -80,6 +115,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { if (header->src == cc1100_get_address()) { return; } + /* printf("\n\t Pkt received from phy: %u (%u bytes)\n" "\t -> SEQ: %u | TYPE: %u | SRC: %hu \n\n", packet_info->phy_src, @@ -88,12 +124,13 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { header->type, header->src ); + */ /* while not acting as sink route the packet */ if (!data_sink) { if (header->type == WEATHER_DATA) { - weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; + //weather_data_pkt_t* wdp = (weather_data_pkt_t*) msg; /* ;;;;;;; */ - printf("%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + /* printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", header->src, 0, wdp->timestamp, @@ -102,10 +139,11 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { wdp->relhum, wdp->relhum_temp, wdp->energy); + */ + puts("Not for me, routing, baby!"); + route_packet(msg, msg_size); } - puts("Not for me, routing, baby!"); - route_packet(msg, msg_size); return; } @@ -130,7 +168,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { time_t local_time = rtc_time(NULL); uint8_t i; /* ;;;;;;; */ - printf("%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", + printf("$1;%hu;%u;%04lX;%04lX;%.2f;%.2f;%.2f;%.2f;", header->src, cc1100_get_address(), wdp->timestamp, @@ -146,7 +184,7 @@ static void handle_packet(void* msg, int msg_size, packet_info_t* packet_info) { break; } default: { - printf("Unknown packet type \"%i\" received.", header->type); + printf("Unknown packet type \"%i\" received.\n", header->type); } } } @@ -172,17 +210,19 @@ int main(void) { sht11_val_t sht11_val; uint8_t success = 0; + gossip_probability = FLOODING_PROB; wdp.header.seq_nr = 0; wdp.header.type = WEATHER_DATA; wdp.hop_counter = 1; - printf("EMPTY: %lu, WDP: %lu\n", EMPTY_WDP_SIZE, sizeof(weather_data_pkt_t)); + cc1100_set_channel(10); puts(""); puts("WEAtHeR: Wireless Energy-Aware mulTi-Hop sEnsor Reading."); /* ;;;;;;; */ puts("Printing \"node id of data source;node id of sink;timestamp of measurement;timestamp at data sink;temperature in °C;relative humidity;temperature compensated relative humidity;energy value\"."); puts(""); + printf("Sending interval: %lu\n", sending_interval); thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell"); @@ -195,6 +235,7 @@ int main(void) { rtc_enable(); while (1) { + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); if (data_src) { wdp.header.src = cc1100_get_address(); wdp.timestamp = rtc_time(NULL); @@ -222,7 +263,22 @@ int main(void) { else { LED_RED_TOGGLE; } - hwtimer_wait(SENDING_INTERVAL); + + if (!success) { + printf("error;error;error\n"); + } + else { + printf("$0;%hu;%hu;%04lX;%04X;%.2f;%.2f;%.2f;%.2f\n", + cc1100_get_address(), + 0, + rtc_time(NULL), + 0, + sht11_val.temperature, + sht11_val.relhum, + sht11_val.relhum_temp, + ltc4150_get_total_mAh()); + } + hwtimer_wait(sending_interval); } puts("Something went wrong."); } diff --git a/projects/WEAtHeR/protocol_msg_gateway.c b/projects/WEAtHeR/protocol_msg_gateway.c index 5501aff90c..6c32d3469a 100644 --- a/projects/WEAtHeR/protocol_msg_gateway.c +++ b/projects/WEAtHeR/protocol_msg_gateway.c @@ -8,6 +8,7 @@ #include #include "protocol_msg_gateway.h" +#include "weather_protocol.h" #define NUM_PROTOCOL_HANDLER_PIDS 8 @@ -16,7 +17,7 @@ static uint16_t protocol_handler_pid; static int packet_buffer_next = 0; packet_t packet_buffer[PACKET_BUFFER_SIZE]; -static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protocol, packet_info_t* packet_info) { +static void protocol_msg_gateway(void* payload, int msg_size, packet_info_t* packet_info) { msg_t m; if (protocol_handler_pid <= 0) { @@ -43,7 +44,7 @@ static void protocol_msg_gateway(void* payload, int msg_size, protocol_t protoco void init_protocol_msg_gateway() { puts("Init protocol msg gateway"); - cc1100_set_packet_monitor(protocol_msg_gateway); + cc1100_set_packet_handler(WEATHER_PROTOCOL_NR, protocol_msg_gateway); } int set_protocol_handler_thread(int pid) { diff --git a/projects/WEAtHeR/weather_routing.c b/projects/WEAtHeR/weather_routing.c index 139953cbb4..cce201a9e6 100644 --- a/projects/WEAtHeR/weather_routing.c +++ b/projects/WEAtHeR/weather_routing.c @@ -5,6 +5,8 @@ #include "weather_protocol.h" #include "weather_routing.h" +uint8_t gossip_probability; + static source_timestamp_t sources[MAX_SOURCES]; static uint8_t update_sources(uint8_t id, time_t timestamp) { @@ -48,7 +50,7 @@ void route_packet(void* msg, int msg_size) { } } - if ((100.0 * rand()/(double) RAND_MAX) <= FLOODING_PROB) { + if ((100.0 * rand()/(double) RAND_MAX) <= gossip_probability) { printf("Broadcasting packet..."); /* if broadcasting weather data, append current hop */ if (wdp != NULL) {