Skip to content

Commit

Permalink
Fixed communication problems. Lists of neighbours are successfully se…
Browse files Browse the repository at this point in the history
…nt to the gateway.
  • Loading branch information
Nejc Bizjak committed Apr 24, 2016
1 parent 3a03144 commit 269cd79
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 41 deletions.
19 changes: 13 additions & 6 deletions gateway/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ static void bsort(int arr[][2]) {
static void init_power_received(struct unicast_conn *c, const linkaddr_t *from)
{
int cow_id = from->u8[0];
int *test = (int *)packetbuf_dataptr();
int * test = (int *)packetbuf_dataptr();

int i;
printf("Init message received from cow %d :", cow_id);

for (i = 0; i < NUMBER_OF_COWS; i++) {
RSSIarray[cow_id - 1][i] = *(test + i);
printf("Init message received from cow %d : %d \n",from->u8[0], *(test + i));
RSSIarray[cow_id - 2][i] = *(test + i);
printf("%d -> %d ; ", i, *(test + i));
}

printf("\n");

char *ack = "Ack";
packetbuf_copyfrom(ack, sizeof(ack));
unicast_send(c, from);
}

static const struct unicast_callbacks unicast_callbacks = {init_power_received};
Expand All @@ -66,10 +73,10 @@ PROCESS_THREAD (herd_monitor_gateway, ev, data)
{
PROCESS_EXITHANDLER(unicast_close(&uc);)

static struct etimer et;

PROCESS_BEGIN();


static struct etimer et;
unicast_open(&uc, 146, &unicast_callbacks);
printf("GATEWAY is waiting....\n");

Expand Down
42 changes: 24 additions & 18 deletions node/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
PROCESS (herd_monitor_node, "Herd monitor - node");
AUTOSTART_PROCESSES (&herd_monitor_node);

static int8_t neighbour_list[NUMBER_OF_COWS + 1];
static int neighbour_list[NUMBER_OF_COWS + 1];

static void reset_neighbour_list()
{
printf("Reseting list... \n");
int i;

for (i = 0; i < NUMBER_OF_COWS; i++) {
Expand All @@ -35,20 +36,20 @@ static void reset_neighbour_list()
static void init_broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
int cow_id = from->u8[0];
int8_t rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI);
neighbour_list[cow_id - 1] = rssi;
int rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI);
neighbour_list[cow_id - 2] = rssi;

/*printf("broadcast message received from cow %d.%d with rssi %d : '%s'\n",
from->u8[0],from->u8[1], rssi, (char *)packetbuf_dataptr());
*/
printf("broadcast message received from cow %d with rssi %d \n",
cow_id, rssi);

}

static void init_send_to_gateway(struct unicast_conn *c)
{
static linkaddr_t addr;
addr.u8[0] = 1;
addr.u8[1] = 0;
packetbuf_copyfrom(neighbour_list, 5);
packetbuf_copyfrom(neighbour_list, sizeof(neighbour_list));
unicast_send(c, &addr);

printf("Neighbour list sent to the gateway\n");
Expand All @@ -61,16 +62,23 @@ static void init_ack_received()
init_timedout = false;
}

static void test_list()
{
printf("List: ");
int i;
for (i = 0; i < 15; i++) {
printf("%d -> %d;", i, neighbour_list[i]);
}
printf("\n");
}


PROCESS_THREAD (herd_monitor_node, ev, data)
{
static struct etimer et;

reset_neighbour_list();

//PROCESS_EXITHANDLER(broadcast_close(&broadcast);)

PROCESS_BEGIN();
reset_neighbour_list();


/**********************************************************
Expand All @@ -94,7 +102,6 @@ PROCESS_THREAD (herd_monitor_node, ev, data)
}
broadcast_close(&broadcast);
printf("initialization broadcasting completed\n");

// WAIT 5 SECONDS TO SEND GATHERED RSSI VALUES
etimer_set(&et, CLOCK_SECOND * 5);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
Expand All @@ -104,16 +111,15 @@ PROCESS_THREAD (herd_monitor_node, ev, data)
PROCESS_EXITHANDLER(unicast_close(&uc);)

unicast_open(&uc, 146, &unicast_callbacks);
static linkaddr_t addr;
addr.u8[0] = 1;
addr.u8[1] = 0;
packetbuf_copyfrom(neighbour_list, 5);
unicast_send(&uc, &addr);

init_send_to_gateway(&uc);

int retryCount;
for (retryCount = 0; retryCount < 15; retryCount++) {
etimer_set(&et, CLOCK_SECOND * 3);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
if (init_ack_received) {
break;
}
printf("Failed to send neighbour_list. Retrying....\n");
init_send_to_gateway(&uc);
}
Expand Down
54 changes: 37 additions & 17 deletions simulation.csc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,32 @@
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
</motetype>
<motetype>
org.contikios.cooja.mspmote.Z1MoteType
<identifier>z13</identifier>
<description>Z1 - Unicast</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/rime/example-unicast.c</source>
<commands EXPORT="discard">make example-unicast.z1 TARGET=z1</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/rime/example-unicast.z1</firmware>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspButton</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDefaultSerial</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>61.073558288932624</x>
<y>13.85165049173941</y>
<x>80.77398167403715</x>
<y>57.46967673705475</y>
<z>0.0</z>
</interface_config>
<interface_config>
Expand All @@ -82,8 +102,8 @@
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>97.6801509807386</x>
<y>78.22011704654204</y>
<x>111.82708380308215</x>
<y>83.87889017547946</y>
<z>0.0</z>
</interface_config>
<interface_config>
Expand All @@ -100,8 +120,8 @@
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>46.07487715597834</x>
<y>7.233647151771752</y>
<x>87.22959082097778</x>
<y>71.79510421373963</y>
<z>0.0</z>
</interface_config>
<interface_config>
Expand Down Expand Up @@ -136,8 +156,8 @@
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>90.10592992447995</x>
<y>80.15716584187881</y>
<x>71.58630877523021</x>
<y>18.425095344379656</y>
<z>0.0</z>
</interface_config>
<interface_config>
Expand All @@ -154,8 +174,8 @@
<breakpoints />
<interface_config>
org.contikios.cooja.interfaces.Position
<x>53.78607935206482</x>
<y>10.48596658916789</y>
<x>71.30888134116846</x>
<y>1.1015536195247577</y>
<z>0.0</z>
</interface_config>
<interface_config>
Expand Down Expand Up @@ -184,23 +204,23 @@
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.AddressVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<viewport>5.1304213940246575 0.0 0.0 5.1304213940246575 -186.16247388862877 13.524705532088301</viewport>
<viewport>3.887768514255855 0.0 0.0 3.887768514255855 -102.3941790870374 65.49042473354797</viewport>
</plugin_config>
<width>400</width>
<z>2</z>
<z>0</z>
<height>497</height>
<location_x>1</location_x>
<location_y>1</location_y>
<location_x>52</location_x>
<location_y>107</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.LogListener
<plugin_config>
<filter />
<filter>ID:1</filter>
<formatted_time />
<coloring />
</plugin_config>
<width>1520</width>
<z>1</z>
<z>2</z>
<height>240</height>
<location_x>400</location_x>
<location_y>160</location_y>
Expand Down Expand Up @@ -240,7 +260,7 @@
<plugin>
org.contikios.cooja.plugins.SimControl
<width>280</width>
<z>0</z>
<z>1</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
Expand Down

0 comments on commit 269cd79

Please sign in to comment.