1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 22:43:50 +01:00

[projects WEAtHeR]

* some bugfixing
This commit is contained in:
Oliver Hahm 2011-04-06 15:50:31 +02:00
parent 0661ce2f7f
commit 71f10ed8e6
3 changed files with 71 additions and 12 deletions

View File

@ -13,6 +13,8 @@
#include <rtc.h>
#include <lpc2387-rtc.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#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;
/* <node_id_source>;<node_id_sink>;<timestamp_source>;<timestamp_sink>;<temperature>;<humidity_relative>;<humitidy_absolut>;<energy_counter> */
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;
/* <node_id_source>;<node_id_sink>;<timestamp_source>;<timestamp_sink>;<temperature>;<humidity_relative>;<humitidy_absolut>;<energy_counter> */
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.");
/* <node_id_source>;<node_id_sink>;<timestamp_source>;<timestamp_sink>;<temperature>;<humidity_relative>;<humitidy_absolut>;<energy_counter> */
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.");
}

View File

@ -8,6 +8,7 @@
#include <board.h>
#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) {

View File

@ -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) {