diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76ace3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.map +*.z1 +*symbols.c +*symbols.h +*.a +obj_z1/ \ No newline at end of file diff --git a/gateway/Makefile b/gateway/Makefile index 92ec1ba..b91c031 100755 --- a/gateway/Makefile +++ b/gateway/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = herd_monitor_gateway all: $(CONTIKI_PROJECT) -CONTIKI = ../.. +CONTIKI = ../../.. CONTIKI_WITH_RIME = 1 include $(CONTIKI)/Makefile.include diff --git a/node/Makefile b/node/Makefile index 05d74ad..493f6d8 100755 --- a/node/Makefile +++ b/node/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = herd_monitor_node all: $(CONTIKI_PROJECT) -CONTIKI = ../.. +CONTIKI = ../../.. CONTIKI_WITH_RIME = 1 include $(CONTIKI)/Makefile.include diff --git a/node/node.c b/node/node.c index 22a5157..33ad37c 100644 --- a/node/node.c +++ b/node/node.c @@ -12,16 +12,44 @@ #include #define TMP102_READ_INTERVAL (CLOCK_SECOND) // Poll the sensor every second +#define NUMBER_OF_COWS 15 //Number of cows PROCESS (herd_monitor_node, "Herd monitor - node"); AUTOSTART_PROCESSES (&herd_monitor_node); +static void +broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) +{ + int cow_id = from->u8[1]; + printf("broadcast message received from cow %d: '%s'\n", + from->u8[1], (char *)packetbuf_dataptr()); +} + +static const struct broadcast_callbacks broadcast_call = {broadcast_recv}; +static struct broadcast_conn broadcast; + +static int neighbour_list[NUMBER_OF_COWS - 1]; + PROCESS_THREAD (herd_monitor_node, ev, data) { + static struct etimer et; + + PROCESS_EXITHANDLER(broadcast_close(&broadcast);) + PROCESS_BEGIN(); - { - - } + + broadcast_open(&broadcast, 129, &broadcast_call); + while(1) { + /* Delay 2-4 seconds */ + etimer_set(&et, CLOCK_SECOND * 4 + random_rand() % (CLOCK_SECOND * 4)); + + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + packetbuf_copyfrom("Hello", 6); + broadcast_send(&broadcast); + printf("broadcast message sent\n"); + } + PROCESS_END (); } \ No newline at end of file