http://anrg.usc.edu/contiki/api.php?action=feedcontributions&user=Venkata&feedformat=atomContiki - User contributions [en]2024-03-29T12:29:28ZUser contributionsMediaWiki 1.26.2http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&diff=1705Build your own application in Contiki2016-06-17T10:15:46Z<p>Venkata: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
This tutorial help you understand how to build you own application in Contiki. Section#2 '''How to start an application in Contiki''' walk you through the complete process of writing you own application in Contiki. Section#3 '''Generic structure of Application in Contiki''' gives a generic skeleton of any application in contiki.<br />
<br />
== How to start an application in Contiki ==<br />
<br />
=== Step 1 ===<br />
Go to the directory contiki/examples and make new sub directory named my_first_app<br />
<br />
<br />
[[File:byaic_1.png|center|800px]]<br />
<br />
<br />
=== Step 2 ===<br />
Now create a new C file named my_first_app.c<br />
<br />
<br />
[[File:byaic_2.png|center|800px]]<br />
<br />
<br />
=== Step 3 ===<br />
'''Write my_first_app.c''' <br />
<br />
<code><nowiki><br />
<Header Files><br />
<br />
PROCESS(my_first_app_process,"My_First_App");<br />
AUTOSTART_PROCESSES(&my_first_app_process);<br />
<br />
PROCESS_THREAD(my_first_app_process,ev,data)<br />
{ <br />
/* Declare variables required */<br />
static int i=652; <br />
<br />
/* Begin Process */<br />
PROCESS_BEGIN(); <br />
<br />
/* Set of C statement(s) */<br />
printf("EE-%d is an awesome course at USC\n",i); <br />
<br />
/* Process End */<br />
PROCESS_END(); <br />
}<br />
</nowiki></code><br />
<br />
Every process in Contiki should start with the PROCESS macro. It takes two arguments<br />
*name: The variable name of the process structure.<br />
*strname: The string representation of the process name.<br />
<code><nowiki> PROCESS(name,strname) </nowiki></code><br />
<br />
<br />
<br />
Then comes another macro AUTOSTART_PROCESS(struct process &). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.<br />
*&name: Reference to the process name.<br />
<code><nowiki> AUTOSTART_PROCESS(struct process &) </nowiki></code><br />
<br />
<br />
<br />
Then we call the PROCESS_THREAD function. 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.<br />
*name: The variable name of the process structure.<br />
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.<br />
<code><nowiki> PROCESS_THREAD(name, process_event_t, process_data_t) </nowiki></code><br />
<br />
<br />
<br />
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.<br />
<code><nowiki>PROCESS_BEGIN() </nowiki></code><br />
<br />
<br />
<br />
Then we write the set of C statements as per the requirement of the application.<br />
<br />
<br />
<br />
At the end we use another macro called 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.<br />
<code><nowiki> PROCESS_END() </nowiki></code><br />
<br />
=== Step 4 ===<br />
'''Makefile''' - Create makefile in the same folder (contiki/exmples/my_first_app)<br />
<br />
<code><nowiki><br />
CONTIKI_PROJECT = my_first_app<br />
all: $(CONTIKI_PROJECT)<br />
<br />
#UIP_CONF_IPV6=1<br />
<br />
CONTIKI = ../..<br />
include $(CONTIKI)/Makefile.include<br />
<br />
</nowiki></code><br />
<br />
=== Step 5 ===<br />
Create a file Makefile.target and then type<br />
TARGET = sky <br />
<br />
=== Step 6 ===<br />
'''Compilation''' - Use terminal to go to "contiki/examples/my_first_app" directory. Once you are in this directory type "make". This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.<br />
<br />
<br />
=== Step 7 ===<br />
<br />
'''Upload the firmware on Tmote Sky''' - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app and then write the following commands to upload your program on the Tmote Sky. <br />
<br />
:: <code>make TARGET=sky savetarget</code> (This save the target for any future compilations)<br />
:: <code>make my_first_app.upload</code> (This will upload the code on the Tmote Sky)<br />
:: <code>make login</code> (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)<br />
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting<br />
<br />
<br />
Press the reset button on the Tmote Sky. The following message will appear on the terminal window <br />
<br />
:: <code>EE-652 is an awesome course at USC</code><br />
<br />
<br />
Then Press CTRL-C to quit.<br />
<br />
<br />
<br />
== Generic structure of Application in Contiki ==<br />
<br />
<code><nowiki><br />
<br />
<Header Files><br />
<br />
PROCESS(name,strname);<br />
AUTOSTART_PROCESSES(struct process &);<br />
<br />
PROCESS_THREAD(name, process_event_t, process_data_t)<br />
{ <br />
<br />
----Initialization of required variables----<br />
<br />
<br />
PROCESS_BEGIN();<br />
<br />
<br />
---Set of C statements---<br />
<br />
<br />
PROCESS_END();<br />
<br />
}<br />
<br />
</nowiki></code><br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
<br />
Edited by : Nitin</div>Venkatahttp://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&diff=1704Broadcast Example2016-05-21T02:54:05Z<p>Venkata: /* Understanding the code */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
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.<br />
<br />
== You will learn ==<br />
<br />
* How to program the Broadcast communication found within the Rime stack<br />
* How to encapsulate data in packets<br />
<br />
== Connect the Tmote Sky ==<br />
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.<br />
<br />
=== Step 1 ===<br />
<br />
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 <br />
<br />
<code><nowiki> cd contiki-2.7/examples/rime </nowiki></code><br />
<br />
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.<br />
<br />
=== Step 2 ===<br />
<br />
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:<br />
<br />
<code><nowiki> gedit example-broadcast.c </nowiki></code><br />
<br />
This will open your text editor, allowing you to edit the code inside the broadcast packet.<br />
<br />
=== Step 3 ===<br />
<br />
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: <br />
<br />
<code><nowiki> packetbuf_copyfrom(“Hello”, 6) </nowiki></code><br />
<br />
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<br />
<br />
<code><nowiki> packetbuf_copyfrom(“yourName”, 9) </nowiki></code><br />
<br />
Save and exit the text editor.<br />
<br />
=== Step 4 ===<br />
<br />
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. <br />
<br />
=== Step 5 ===<br />
<br />
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type<br />
<br />
<code><nowiki> make TARGET=sky example-broadcast.upload login </nowiki></code><br />
<br />
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.<br />
<br />
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.<br />
<br />
<br />
<br />
'''Congratulations! You have successfully programmed the Tmote Sky! '''<br />
<br />
'''Note:''' If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C<br />
<br />
'''Tip:''' You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.<br />
<br />
<br />
<br />
<br />
<br />
<br />
== Understanding the code ==<br />
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.<br />
In the code, a process called example_broadcast_process is kicked off by AUTOSTART_PROCESSES.<br />
<br />
==== Macros and Structures ====<br />
<br />
<code><nowiki> PROCESS(name,strname) </nowiki></code><br />
<br />
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.<br />
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.<br />
<br />
*name: The variable name of the process structure.<br />
*strname: The string representation of the process name.<br />
<br />
<br />
<br />
<code><nowiki> AUTOSTART_PROCESS(struct process &) </nowiki></code><br />
<br />
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.<br />
<br />
*&name: Reference to the process name<br />
<br />
<br />
<br />
<code><nowiki> broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) </nowiki></code><br />
<br />
This function parses an incoming packet and displays the message and the address of the sender.<br />
By setting it as the broadcast's designated callback function, broadcast_recv is automatically called when a packet is received.<br />
<br />
*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).<br />
<br />
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].<br />
<br />
<br />
<br />
<code><nowiki> PROCESS_THREAD(name, process_event_t, process_data_t) </nowiki></code><br />
<br />
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. <br />
Each process in the module requires an event handler under the PROCESS_THREAD macro.<br />
<br />
*name: The variable name of the process structure.<br />
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.<br />
<br />
Within the body of PROCESS_THREAD there are 3 major tasks:<br />
* Initialization<br />
** allocate resources<br />
** define variables<br />
** begin process<br />
* Infinite Loop<br />
** while(1) is used to create an infinite loop in which the actual event-handling response takes place<br />
* Deallocation<br />
** end process<br />
** deallocate resources<br />
<br />
<br />
<br />
<code><nowiki>PROCESS_EXITHANDLER(handler) </nowiki></code><br />
<br />
Specifies an action when a process exits.<br />
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.<br />
<br />
* handler: The action to be performed.<br />
<br />
<br />
<br />
<code><nowiki>PROCESS_BEGIN() </nowiki></code><br />
<br />
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.<br />
<br />
<br />
<br />
<code><nowiki>broadcast_close(struct broadcast_conn *) </nowiki></code><br />
<br />
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.<br />
<br />
*broadcast_conn : This is same as the variable from broadcast_recv().<br />
<br />
<br />
<br />
<code><nowiki> PROCESS_END() </nowiki></code><br />
<br />
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.<br />
<br />
<br />
<br />
<code><nowiki> broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) </nowiki></code><br />
<br />
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.<br />
<br />
*broadcast_conn : A pointer to a struct broadcast_conn<br />
*uint16_t: The channel on which the connection will operate<br />
*broadcast_callbacks : A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received<br />
<br />
<br />
<br />
<code><nowiki> etimer_set(struct etimer *, clock_time_t) </nowiki></code><br />
<br />
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.<br />
<br />
*etimer : A pointer to the event timer<br />
*clock_time_t : The interval before the timer expires.<br />
<br />
<br />
<br />
<code><nowiki> static struct broadcast_conn </nowiki></code><br />
<br />
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. <br />
broadcast_conn structure consists of two structures<br />
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.<br />
*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.<br />
<br />
<br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
<br />
Edited by: Rahul, Nikhil, Bhavana, Lakshmi</div>Venkatahttp://anrg.usc.edu/contiki/index.php?title=Hello_World&diff=1686Hello World2016-05-17T17:15:44Z<p>Venkata: /* Step 3 */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
This article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.<br />
<br />
== You will learn ==<br />
<br />
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.<br />
<br />
=== Step 1 ===<br />
<br />
Open the terminal window.<br />
<br />
=== Step 2 === <br />
<br />
In the terminal window, go to the hello world example folder. <br />
<br />
:: <code>.cd /examples/hello-world</code><br />
<br />
===Step 3=== <br />
<br />
Compile the code for the native platform (to be used when no mote is connected to the laptop.)<br />
<br />
:: <code>make TARGET=native</code><br />
If there is any bug during compilation which says "#include<curses.h> : No such file or directory" you need to do the following on Ubuntu. <br />
<br />
If you are currently in the terminal, type "sudo apt-get install libncurses5-dev"(for which you should have installed the "apt" for 32-bit using "sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_i386.deb" and for 64-bit using sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_amd64.deb")<br />
<br />
You need to also install a version of javac compiler using the command "sudo apt-get install openjdk-7-jdk".<br />
<br />
=== Step 4 ===<br />
<br />
Once the compilation is over, run the Hello World program. <br />
<br />
:: <code>./hello-world.native</code><br />
<br />
=== Step 5 ===<br />
<br />
This will print the words "Hello, world" on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.<br />
<br />
== Hello World on the Tmote Sky! ==<br />
<br />
=== Step 1 ===<br />
<br />
Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.<br />
<br />
:: <code>make TARGET=sky savetarget</code> (This save the target for any future compilations)<br />
:: <code>make hello-world.upload</code> (This will upload the code on the Tmote Sky)<br />
:: <code>make login</code> (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)<br />
<br />
=== Step 2 ===<br />
<br />
Press the reset button on the Tmote Sky. The following message will appear on the terminal window <br />
<br />
:: <code>Contiki 2.7 started. Node id is set to 3.</code><br />
:: <code>Rime started with address 3.0</code><br />
:: <code>MAC 00:12:ff:11:65:23:52:ed</code><br />
:: <code>Starting 'Hello world process'</code><br />
:: <code>Hello, world</code><br />
<br />
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.<br />
<br />
=== Step 3 ===<br />
<br />
Press Ctrl-C to quit.<br />
<br />
=== Try This ===<br />
<br />
You can upload and login with one line. You can also point the upload and/or login to a specific device path (use `dmesg` to find the device path of a mote after inserting it to your computer). Try the following command:<br />
<br />
:: <code>make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login</code><br />
<br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]</div>Venkatahttp://anrg.usc.edu/contiki/index.php?title=Hello_World&diff=1685Hello World2016-05-17T17:15:12Z<p>Venkata: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
This article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.<br />
<br />
== You will learn ==<br />
<br />
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.<br />
<br />
=== Step 1 ===<br />
<br />
Open the terminal window.<br />
<br />
=== Step 2 === <br />
<br />
In the terminal window, go to the hello world example folder. <br />
<br />
:: <code>.cd /examples/hello-world</code><br />
<br />
===Step 3=== <br />
<br />
Compile the code for the native platform (to be used when no mote is connected to the laptop.)<br />
<br />
:: <code>make TARGET=native</code><br />
If there is any bug during compilation which says "#include<curses.h> : No such file or directory" you need to do the following on Ubuntu. <br />
<br />
If you are currently in the terminal type "sudo apt-get install libncurses5-dev"(for which you should have installed the "apt" for 32-bit using "sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_i386.deb" and for 64-bit using sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_amd64.deb")<br />
<br />
You need to also install a version of javac compiler using the command "sudo apt-get install openjdk-7-jdk".<br />
<br />
=== Step 4 ===<br />
<br />
Once the compilation is over, run the Hello World program. <br />
<br />
:: <code>./hello-world.native</code><br />
<br />
=== Step 5 ===<br />
<br />
This will print the words "Hello, world" on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.<br />
<br />
== Hello World on the Tmote Sky! ==<br />
<br />
=== Step 1 ===<br />
<br />
Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.<br />
<br />
:: <code>make TARGET=sky savetarget</code> (This save the target for any future compilations)<br />
:: <code>make hello-world.upload</code> (This will upload the code on the Tmote Sky)<br />
:: <code>make login</code> (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)<br />
<br />
=== Step 2 ===<br />
<br />
Press the reset button on the Tmote Sky. The following message will appear on the terminal window <br />
<br />
:: <code>Contiki 2.7 started. Node id is set to 3.</code><br />
:: <code>Rime started with address 3.0</code><br />
:: <code>MAC 00:12:ff:11:65:23:52:ed</code><br />
:: <code>Starting 'Hello world process'</code><br />
:: <code>Hello, world</code><br />
<br />
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.<br />
<br />
=== Step 3 ===<br />
<br />
Press Ctrl-C to quit.<br />
<br />
=== Try This ===<br />
<br />
You can upload and login with one line. You can also point the upload and/or login to a specific device path (use `dmesg` to find the device path of a mote after inserting it to your computer). Try the following command:<br />
<br />
:: <code>make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login</code><br />
<br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]</div>Venkatahttp://anrg.usc.edu/contiki/index.php?title=Hello_World&diff=1684Hello World2016-05-17T17:03:12Z<p>Venkata: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
This article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.<br />
<br />
== You will learn ==<br />
<br />
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.<br />
<br />
=== Step 1 ===<br />
<br />
Open the terminal window.<br />
<br />
=== Step 2 === <br />
<br />
In the terminal window, go to the hello world example folder. <br />
<br />
:: <code>.cd /examples/hello-world</code><br />
<br />
===Step 3=== <br />
<br />
Compile the code for the native platform (to be used when no mote is connected to the laptop.)<br />
<br />
:: <code>make TARGET=native</code><br />
If there is any bug during compilation which says "#include<curses.h> : No such file or directory" you need to do the following on Ubuntu. <br />
<br />
If you are currently in the terminal type "sudo apt-get install libncurses5-dev"(for which you should have installed the "apt" for 32-bit using "sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_i386.deb" and for 64-bit using sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_amd64.deb")<br />
<br />
=== Step 4 ===<br />
<br />
Once the compilation is over, run the Hello World program. <br />
<br />
:: <code>./hello-world.native</code><br />
<br />
=== Step 5 ===<br />
<br />
This will print the words "Hello, world" on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.<br />
<br />
== Hello World on the Tmote Sky! ==<br />
<br />
=== Step 1 ===<br />
<br />
Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.<br />
<br />
:: <code>make TARGET=sky savetarget</code> (This save the target for any future compilations)<br />
:: <code>make hello-world.upload</code> (This will upload the code on the Tmote Sky)<br />
:: <code>make login</code> (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)<br />
<br />
=== Step 2 ===<br />
<br />
Press the reset button on the Tmote Sky. The following message will appear on the terminal window <br />
<br />
:: <code>Contiki 2.7 started. Node id is set to 3.</code><br />
:: <code>Rime started with address 3.0</code><br />
:: <code>MAC 00:12:ff:11:65:23:52:ed</code><br />
:: <code>Starting 'Hello world process'</code><br />
:: <code>Hello, world</code><br />
<br />
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.<br />
<br />
=== Step 3 ===<br />
<br />
Press Ctrl-C to quit.<br />
<br />
=== Try This ===<br />
<br />
You can upload and login with one line. You can also point the upload and/or login to a specific device path (use `dmesg` to find the device path of a mote after inserting it to your computer). Try the following command:<br />
<br />
:: <code>make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login</code><br />
<br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]</div>Venkatahttp://anrg.usc.edu/contiki/index.php?title=Hello_World&diff=1683Hello World2016-05-17T17:02:47Z<p>Venkata: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
== Introduction ==<br />
<br />
This article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.<br />
<br />
== You will learn ==<br />
<br />
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.<br />
<br />
=== Step 1 ===<br />
<br />
Open the terminal window.<br />
<br />
=== Step 2 === <br />
<br />
In the terminal window, go to the hello world example folder. <br />
<br />
:: <code>.cd /examples/hello-world</code><br />
<br />
===Step 3=== <br />
<br />
Compile the code for the native platform (to be used when no mote is connected to the laptop.)<br />
<br />
:: <code>make TARGET=native</code><br />
If there is any bug during compilation which says "#include<curses.h> : No such file of directory" you need to do the following on Ubuntu. <br />
<br />
If you are currently in the terminal type "sudo apt-get install libncurses5-dev"(for which you should have installed the "apt" for 32-bit using "sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_i386.deb" and for 64-bit using sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_amd64.deb")<br />
<br />
=== Step 4 ===<br />
<br />
Once the compilation is over, run the Hello World program. <br />
<br />
:: <code>./hello-world.native</code><br />
<br />
=== Step 5 ===<br />
<br />
This will print the words "Hello, world" on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.<br />
<br />
== Hello World on the Tmote Sky! ==<br />
<br />
=== Step 1 ===<br />
<br />
Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.<br />
<br />
:: <code>make TARGET=sky savetarget</code> (This save the target for any future compilations)<br />
:: <code>make hello-world.upload</code> (This will upload the code on the Tmote Sky)<br />
:: <code>make login</code> (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)<br />
<br />
=== Step 2 ===<br />
<br />
Press the reset button on the Tmote Sky. The following message will appear on the terminal window <br />
<br />
:: <code>Contiki 2.7 started. Node id is set to 3.</code><br />
:: <code>Rime started with address 3.0</code><br />
:: <code>MAC 00:12:ff:11:65:23:52:ed</code><br />
:: <code>Starting 'Hello world process'</code><br />
:: <code>Hello, world</code><br />
<br />
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.<br />
<br />
=== Step 3 ===<br />
<br />
Press Ctrl-C to quit.<br />
<br />
=== Try This ===<br />
<br />
You can upload and login with one line. You can also point the upload and/or login to a specific device path (use `dmesg` to find the device path of a mote after inserting it to your computer). Try the following command:<br />
<br />
:: <code>make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login</code><br />
<br />
<br />
<br />
[[Contiki_tutorials | Back to Contiki Tutorials]]</div>Venkata