Difference between revisions of "Broadcast Example"

From Contiki
Jump to: navigation, search
 
(26 intermediate revisions by 7 users not shown)
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
=== Introduction ===
+
== Introduction ==
  
This exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet.  
+
This exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.
  
=== You will learn ===
+
== You will learn ==
  
 
* How to program the Broadcast communication found within the Rime stack
 
* How to program the Broadcast communication found within the Rime stack
 
* How to encapsulate data in packets
 
* How to encapsulate data in packets
  
=== Connect the Tmote Sky ===
+
== Connect the Tmote Sky ==
 
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.
 
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.
  
Line 19: Line 19:
 
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type  
 
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type  
  
<code><nowiki> cd contiki-2.7/examples/rime </nowiki></code>
+
  cd contiki-2.7/examples/rime
  
 
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.
 
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.
Line 27: Line 27:
 
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:
 
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:
  
<code><nowiki> gedit example-broadcast.c </nowiki></code>
+
  gedit example-broadcast.c
  
This will open your text editor, allowing you to edit the code inside the broadcast packet.  
+
This will open your text editor, allowing you to edit the code inside the broadcast packet.
  
 
=== Step 3 ===
 
=== Step 3 ===
Line 35: Line 35:
 
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains:  
 
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains:  
  
<code><nowiki> packetbuf_copyfrom(“Hello”,  6) </nowiki></code>
+
<source lang="c">
 +
packetbuf_copyfrom(“Hello”,  6)
 +
</source>
  
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read
+
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the "null character" associated with character strings in C when changing the number of characters. The line should now read
  
<code><nowiki> packetbuf_copyfrom(“yourName”,  9) </nowiki></code>
+
<source lang="c">
 +
packetbuf_copyfrom(“yourName”,  9)
 +
</source>
  
Save and exit the text editor.  
+
Save and exit the text editor.
  
 
=== Step 4 ===
 
=== Step 4 ===
  
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop).  
+
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine and not the host computer. The LEDs on the mote will temporarily blink when connected to the laptop.   
 
+
Then in terminal, type
+
 
+
  <code><nowiki> sudo chown :user /dev/ttyUSB0 </nowiki></code>
+
 
+
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.
+
 
+
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password.
+
  
 
=== Step 5 ===
 
=== Step 5 ===
Line 59: Line 55:
 
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type
 
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type
  
<code><nowiki> make TARGET=sky example-broadcast.upload login </nowiki></code>
+
  make TARGET=sky example-broadcast.upload login
  
 
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.
 
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.
  
 
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.
 
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.
 
 
  
 
'''Congratulations! You have successfully programmed the Tmote Sky! '''
 
'''Congratulations! You have successfully programmed the Tmote Sky! '''
Line 73: Line 67:
 
'''Tip:''' You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.
 
'''Tip:''' You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.
  
 +
== Using Cooja Simulator ==
  
 +
Cooja is a network simulator included in the Contiki system that simulates networks of Contiki nodes.
  
 +
=== Step 1 ===
 +
 +
Go to contiki folder and navigate to the tools/cooja/ directory and run "ant" to start the simulator.
 +
 +
  ant run
 +
 +
When Cooja is up and running, it will start with a blue window.
 +
 +
=== Step 2 ===
 +
 +
To create a new simulation, click on the File menu, choose 'New Simulation', name the simulation and click on 'Create'.
 +
 +
The new simulation shows an empty 'Network' window at the top left of the screen as we have not yet added any motes to our simulation. The 'Simulation Control' window has options to Start, Pause and Reload the simulation. The 'Notes' window provides us with a space to add notes for our simulation. The 'Mote Output' window prints out all serial port activities for the motes connected in the simulation. The 'Timeline' window provides real-time information of the events happening in the simulation.
 +
 +
=== Step 3 ===
  
 +
To add Motes to the simulation, click on the Motes-> Add motes-> Create a new mote type-> and select the type of mote to be added in the network.
  
 +
In the 'Create Mote Type' window, choose a suitable name for the mote type. In the 'Contiki process/ Firmware' option, follow the path <code><nowiki> examples/ipv6/simple-udp-rpl</nowiki></code> and select the 'broadcast-example.c' program.
 +
Compile and click Create.
  
=== Understanding the code ===
+
In the 'Add mote' window that pops up, enter the number of motes and alter the position intervals as required and click 'Add motes'. The number of motes added to the network is now shown in the 'Network' window.
 +
 
 +
=== Step 4 ===
 +
 
 +
To start the simulation, Click on 'Start' in the 'Simulation Control' window.
 +
 
 +
While the simulation is running, the 'Mote output' window prints sender and receiver information.
 +
 
 +
The 'View' tab in the Network window can be used to display mote features such as,
 +
 
 +
* Mote IDs- Displays the mote id
 +
* Addresses: IP or Rime- Displays the IPv6 address of the mote
 +
* Radio Traffic- Enables animation showing the communication among the motes
 +
* Positions- Displays the co-ordinates of the mote
 +
* Radio Environment- Clicking on a particular mote displays its coverage area
 +
 
 +
== Understanding the code ==
 
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.
 
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.
 
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.
 
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.
Line 84: Line 114:
 
==== Macros and Structures ====
 
==== Macros and Structures ====
  
<code><nowiki> PROCESS(name,strname) </nowiki></code>
+
<source lang="c">
 +
PROCESS(name,strname)
 +
</source>
  
Every process should be defined via the PROCESS macro.
+
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.
 
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.
 
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.
  
Line 92: Line 124:
 
*strname: The string representation of the process name.
 
*strname: The string representation of the process name.
  
<code><nowiki> AUTOSTART_PROCESS(struct process &) </nowiki></code>
+
<source lang="c">
 +
AUTOSTART_PROCESS(struct process &)
 +
</source>
  
 
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.
 
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.
Line 98: Line 132:
 
*&name: Reference to the process name
 
*&name: Reference to the process name
  
<code><nowiki> broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) </nowiki></code>
+
<source lang="c">
 +
broadcast_recv(struct broadcast_conn *, const rimeaddr_t *)
 +
</source>
  
 
This function parses an incoming packet and displays the message and the address of the sender.
 
This function parses an incoming packet and displays the message and the address of the sender.
Line 107: Line 143:
 
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].
 
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].
  
<code><nowiki> PROCESS_THREAD(name, process_event_t, process_data_t) </nowiki></code>
+
<source lang="c">
 +
PROCESS_THREAD(name, process_event_t, process_data_t)
 +
</source>
  
A process in Contiki consists of a single reference to "protothread". This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.  
+
A process in Contiki consists of a single reference to a "[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]". This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.  
 
Each process in the module requires an event handler under the PROCESS_THREAD macro.
 
Each process in the module requires an event handler under the PROCESS_THREAD macro.
  
Line 126: Line 164:
 
** deallocate resources
 
** deallocate resources
  
 
+
<source lang="c">
 
+
PROCESS_EXITHANDLER(handler)
<code><nowiki>PROCESS_EXITHANDLER(handler) </nowiki></code>
+
</source>
  
 
Specifies an action when a process exits.
 
Specifies an action when a process exits.
Line 135: Line 173:
 
* handler: The action to be performed.
 
* handler: The action to be performed.
  
 
+
<source lang="c">
 
+
PROCESS_BEGIN()
<code><nowiki>PROCESS_BEGIN() </nowiki></code>
+
</source>
  
 
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.
 
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.
  
 
+
<source lang="c">
 
+
broadcast_close(struct broadcast_conn *)
<code><nowiki>broadcast_close(struct broadcast_conn *) </nowiki></code>
+
</source>
  
 
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.
 
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.
  
*broadcast_conn :  This is same as the variable from boradcast_recv().
+
*broadcast_conn :  This is same as the variable from broadcast_recv().
  
 
+
<source lang="c">
 
+
PROCESS_END()
<code><nowiki> PROCESS_END() </nowiki></code>
+
</source>
  
 
This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.
 
This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.
  
 
+
<source lang="c">
 
+
broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)
<code><nowiki> broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) </nowiki></code>
+
</source>
  
 
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.
 
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.
Line 165: Line 203:
 
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
 
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
  
 
+
<source lang="c">
 
+
etimer_set(struct etimer *, clock_time_t)
<code><nowiki> etimer_set(struct etimer *, clock_time_t) </nowiki></code>
+
</source>
  
 
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.
 
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.
Line 174: Line 212:
 
*clock_time_t : The interval before the timer expires.
 
*clock_time_t : The interval before the timer expires.
  
 
+
<source lang="c">
 
+
static struct broadcast_conn
<code><nowiki> static struct broadcast_conn </nowiki></code>
+
</source>
  
 
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets.  
 
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets.  
Line 184: Line 222:
  
  
 +
[[Contiki_tutorials | Back to Contiki Tutorials]]
  
  
[[Contiki_tutorials | Back to Contiki Tutorials]]
+
Edited by: Rahul, Nikhil, Bhavana, Lakshmi, Mugdhe, Samarth

Latest revision as of 18:53, 27 September 2016

Back to Contiki Tutorials

Introduction

This exercise is an introduction into programming the Tmote Sky. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.

You will learn

  • How to program the Broadcast communication found within the Rime stack
  • How to encapsulate data in packets

Connect the Tmote Sky

Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.

Step 1

The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type

 cd contiki-2.7/examples/rime

directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.

Step 2

Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:

 gedit example-broadcast.c

This will open your text editor, allowing you to edit the code inside the broadcast packet.

Step 3

To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains:

packetbuf_copyfrom(Hello,  6)

Change the character string to your name. Then change the number of characters accordingly. Remember to account for the "null character" associated with character strings in C when changing the number of characters. The line should now read

packetbuf_copyfrom(yourName,  9)

Save and exit the text editor.

Step 4

In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine and not the host computer. The LEDs on the mote will temporarily blink when connected to the laptop.

Step 5

In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type

 make TARGET=sky example-broadcast.upload login

You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.

This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent... should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.

Congratulations! You have successfully programmed the Tmote Sky!

Note: If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C

Tip: You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.

Using Cooja Simulator

Cooja is a network simulator included in the Contiki system that simulates networks of Contiki nodes.

Step 1

Go to contiki folder and navigate to the tools/cooja/ directory and run "ant" to start the simulator.

 ant run

When Cooja is up and running, it will start with a blue window.

Step 2

To create a new simulation, click on the File menu, choose 'New Simulation', name the simulation and click on 'Create'.

The new simulation shows an empty 'Network' window at the top left of the screen as we have not yet added any motes to our simulation. The 'Simulation Control' window has options to Start, Pause and Reload the simulation. The 'Notes' window provides us with a space to add notes for our simulation. The 'Mote Output' window prints out all serial port activities for the motes connected in the simulation. The 'Timeline' window provides real-time information of the events happening in the simulation.

Step 3

To add Motes to the simulation, click on the Motes-> Add motes-> Create a new mote type-> and select the type of mote to be added in the network.

In the 'Create Mote Type' window, choose a suitable name for the mote type. In the 'Contiki process/ Firmware' option, follow the path examples/ipv6/simple-udp-rpl and select the 'broadcast-example.c' program. Compile and click Create.

In the 'Add mote' window that pops up, enter the number of motes and alter the position intervals as required and click 'Add motes'. The number of motes added to the network is now shown in the 'Network' window.

Step 4

To start the simulation, Click on 'Start' in the 'Simulation Control' window.

While the simulation is running, the 'Mote output' window prints sender and receiver information.

The 'View' tab in the Network window can be used to display mote features such as,

  • Mote IDs- Displays the mote id
  • Addresses: IP or Rime- Displays the IPv6 address of the mote
  • Radio Traffic- Enables animation showing the communication among the motes
  • Positions- Displays the co-ordinates of the mote
  • Radio Environment- Clicking on a particular mote displays its coverage area

Understanding the code

The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example. In the code, a process called example_broadcast_process is kicked off by AUTOSTART_PROCESSES.

Macros and Structures

PROCESS(name,strname)

Every process should be defined via the PROCESS macro. PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.

  • name: The variable name of the process structure.
  • strname: The string representation of the process name.
AUTOSTART_PROCESS(struct process &)

AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.

  • &name: Reference to the process name
broadcast_recv(struct broadcast_conn *, const rimeaddr_t *)

This function parses an incoming packet and displays the message and the address of the sender. By setting it as the broadcast's designated callback function, broadcast_recv is automatically called when a packet is received.

  • broadcast_conn *: This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).
  • rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].
PROCESS_THREAD(name, process_event_t, process_data_t)

A process in Contiki consists of a single reference to a "protothread". This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. Each process in the module requires an event handler under the PROCESS_THREAD macro.

  • name: The variable name of the process structure.
  • process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.

Within the body of PROCESS_THREAD there are 3 major tasks:

  • Initialization
    • allocate resources
    • define variables
    • begin process
  • Infinite Loop
    • while(1) is used to create an infinite loop in which the actual event-handling response takes place
  • Deallocation
    • end process
    • deallocate resources
PROCESS_EXITHANDLER(handler)

Specifies an action when a process exits. NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.

  • handler: The action to be performed.
PROCESS_BEGIN()

This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.

broadcast_close(struct broadcast_conn *)

This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.

  • broadcast_conn : This is same as the variable from broadcast_recv().
PROCESS_END()

This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.

broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)

Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.

  • broadcast_conn : A pointer to a struct broadcast_conn
  • uint16_t: The channel on which the connection will operate
  • broadcast_callbacks : A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received
etimer_set(struct etimer *, clock_time_t)

This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.

  • etimer : A pointer to the event timer
  • clock_time_t : The interval before the timer expires.
static struct broadcast_conn

The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. broadcast_conn structure consists of two structures

  • abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.
  • broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point to a function that will be called when a packet arrives on the channel.


Back to Contiki Tutorials


Edited by: Rahul, Nikhil, Bhavana, Lakshmi, Mugdhe, Samarth