There are a lot of methods for communicating among Contiki-NG motes. To show how to communicate among Contiki motes, we use broadcast via UDP
protocol in Contiki-NG OS. UDP
is a communication stack that provides a set of lightweight communication primitives ranging from local-area broadcast to reliable network flooding.
For this demo, we need at least two Contiki-NG motes. One mote will act as a sender and the other mote will be a receiver.
Our demo scenario is that a mote sends data to all motes. If a mote receives data, it will be shown in Terminal. We use a program sample from Contiki-NG.
Sending Broadcast Messages
The objective of a mote sender is to broadcast data to other motes. For this demo, we use the simple-udp
module that is located in the <contiki-ng-root>/os/net
folder. We can use the simple_udp_sendto()
function to broadcast a message. This method is defined in the simple-udp.h
header file:
1 | int simple_udp_sendto_port(struct simple_udp_connection *c, |
simple_udp_connection
issimple-udp
objectdata
is data that will be sentdatalen
is length of datato
isip
address of targetto_port
is the port of the target
For instance, we send data to a specific IP address: simple_udp_sendto(&udp_c onn, &count, sizeof(count), &dag->dag_id);
Receiving Broadcast Messages
A mote receiver listens for an incoming message that is sent by a mote sender. To build a mote receiver, we can listen for broadcast messages by creating a callback/event function. We can use simple_udp_register()
to register our callback function.
For instance, we listen for incoming broadcast messages using this code:
1 | static void |