In contiki, i need to have two files, sender and receiver, the sender sends packets to the receiver. My problem is, the receiver is not outputting that the packets have been received.
I tried a while loop inside the receiving packet, i even tried to create a function, but still nothing has worked.
My sender.c file
#include "contiki.h"
#include "net/rime.h"
#include "random.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
PROCESS(sendReceive, "Hello There");
AUTOSTART_PROCESSES(&sendReceive);
PROCESS_THREAD(sendReceive, ev, data)
{
PROCESS_BEGIN();
static struct abc_conn abc;
static struct etimer et;
static const struct abc_callbacks abc_call;
PROCESS_EXITHANDLER(abc_close(&abc);)
abc_open(&abc, 128, &abc_call);
while(1)
{
/* Delay 2-4 seconds */
etimer_set(&et, CLOCK_SECOND * 2 + random_rand() % (CLOCK_SECOND * 2));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
packetbuf_copyfrom("Hello", 6);
abc_send(&abc);
printf("Message sent\n");
}
PROCESS_END();
}
my receiver.c file
#include "contiki.h"
#include "net/rime.h"
#include "random.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
PROCESS(sendReceive, "Receiving Message");
AUTOSTART_PROCESSES(&sendReceive);
PROCESS_THREAD(sendReceive, ev, data)
{
PROCESS_BEGIN();
{
printf("Message received '%s'\n", (char *)packetbuf_dataptr());
}
PROCESS_END();
}
The sender.c file is working, it is sending the packets correctly, the problem is the receiver seems not to output that it has been received.
While sending is simple - you just need to call a function -, receiving data in embedded system is in general more complicated. There needs to be a way for the operating system to let your code know that new data has arrived from outside. In Contiki that is internally done with events, and from user's perspective with callbacks.
So, implement a callback function:
In your receiver process, create and open an connection, passing the callback function's pointer as a parameter: