Professional Documents
Culture Documents
TV Simple Report RPL
TV Simple Report RPL
MC LC
LI NI U........................................................................................................1
MC LC............................................................................................................... 3
Chng 1. TNG QUAN V H IU HNH NHNG CHO MNG CC
I TNG THNG MINH................................................................................5
1.1. Gii thiu v cc i tng thng minh.......................................................5
1.2. H iu hnh nhng cho cc i tng thng minh.....................................8
1.2.1. Chc nng ca h iu hnh..................................................................8
1.2.2. Nhng thch thc nh hng n vic thit k h iu hnh.................8
1.2.3. Cc thnh phn c bn ca mt h iu hnh........................................9
1.2.4. Kho st mt s h iu hnh..............................................................11
1.2.5. Tiu ch phn loi h iu hnh...........................................................14
1.2.6. Mt s vn cn tip tc nghin cu.................................................17
Chng 2. H IU HNH CONTIKI................................................................20
2.1. Gii thiu v h iu hnh Contiki.............................................................20
2.2. Cu trc h iu hnh Contiki....................................................................22
2.3. Kin trc phn lp h iu hnh Contiki....................................................23
2.4. Ngn xp truyn thng trong h iu hnh Contiki....................................24
2.4.1. Ngn xp uIP.......................................................................................24
2.4.2. Ngn xp RIME...........................................................................................25
2.5. K thut lp trnh trn h iu hnh Contiki...............................................27
2.5.1. Lp trnh Event-driven.........................................................................27
2.5.2. Lp trnh Multi-threaded......................................................................28
2.5.3. Lp trnh Prothreads............................................................................28
2.5.4. So snh ba m hnh lp trnh trong Contiki.........................................29
2.6. Hot ng nh thi trong Contiki..........................................................31
2.7. Qun l b nh.......................................................................................33
2.8. Ci t v thc hnh vi Contiki................................................................35
2.8.1. Ci t Instant-Contiki.........................................................................35
2.8.2. Chng trnh iu khin LED trn Tmote Sky....................................38
Chng 3. CC MODULE TRONG H IU HNH CONTIKI......................39
Chng 4. XY DNG CHNG TRNH.........................................................40
NG DNG VI CONTIKI................................................................................40
4.1. Gii thiu v cng c m phng Cooja......................................................40
4.2. Hng dn s dng Cooja..........................................................................43
4.3. Cc bc xy dng ng dng u tin.......................................................50
4.4. V d lm vic vi Shell trong Contiki.......................................................62
Hnh 1.2: Qu trnh pht trin phn mm cho i tng thng minh.
M ngun c c bin dch thnh m my m c ghi
vo ROM trong b vi iu khin.
nhng cc ngi dng phi cnh tranh cc trnh iu khin thng qua mt
kha.
Cc giao din cm bin: Cc giao din cm bin cung cp cho ngi lp
trnh ng dng cch thc truy cp c d liu cm bin mt cch d
dng v theo dng chun. Nhng m t chi tit mc thp c gn vi
nhng cu hnh cm bin cng c tru tng ha vi nhng ngi lp
trnh ng dng.
Ngn xp mng: Ngn xp mng thun tin cho vic pht trin cc ng
dng WSN phn tn. N cng cn thit cho vic duy tr h thng t xa sau
khi WSN c trin khai. Ngn xp mng cho h iu hnh nn h tr cc
dch v mc cao chng hn nh vic thu thp v truyn d liu. N cng
qun l cc chi tit mc thp nh cu hnh chip thu pht v tuyn, iu
khin truy nhp ng truyn (MAC), v qun l hng i.
1.2.4. Kho st mt s h iu hnh
Mc ny ca bo co s m t cc h iu hnh tin tin hin nay. Cn phi
ch rng, hu ht cc h iu hnh vn ang c pht trin, do vy mc ny ch
m t nhng c im chnh trong cc phin bn hin ti ca cc h iu hnh
ny.
1.2.4.1. TinyOS
H iu hnh TinyOS c pht trin UC Berkeley, c l l h iu hnh
nhng cho cc i tng thng minh sm nht. N cho php mt kin trc mm
do v tiu th ti nguyn thp, vic lp trnh trn TinyOS da trn cc thnh phn
c kt ni vi nhau to mt ng dng thi im thit k. Nhng tng tc
gia cc thnh phn xy ra theo hai chiu, tc l mt thnh phn s dng lnh
c cung cp bi mt thnh phn khc; ngoi ra, mt thnh phn c th bo hiu
cc s kin ti mt thnh phn khc. M hnh thc thi ca TinyOS bao gm cc
ngt (interrupt) v cc nhim v (task). Cc ngt c thc thi mc u tin cao
hn v c th c u tin thc thi trc cc nhim v. Cc nhim v c thc
thi mc u tin thp hn v c lp lch theo kiu vo trc ra trc FIFO
(First In First Out). Cc nhim v trong TinyOS c vit theo kiu run-tocompletion (chy n khi hon thnh), v chng khng th ginh c quyn u
tin trc (preempt) hoc tm ngng (suspend). V l do ny, vic xut nhp
(I/Os) c chia thnh cc giai on. Tc l mt yu cu (request) c thc hin
10
nhn ca nhng ngi lp trnh v chng khng thy khi c bin dch thnh
on m nh phn. Mt khc, cc modules trong SOS vn cn cc thng tin m nh
phn (v d nh im bt u ca mt module, cc hm ca mt module) sau khi
bin dch, cho php cc modules c np hoc np li t ng. h tr kin
trc ny, SOS cng h tr vic nh v b nh ng.
M hnh thc thi SOS phc tp hn khng nhiu so vi TinyOS. Cc trnh
x l bn tin SOS (ging nh cc cc tasks trong TinyOS) c gii quyt theo ba
mc u tin. Phin bn mi nht ca SOS l phin bn 2.0.1, ci tin hn so vi
phin bn c mt s im, bao gm s h tr nhiu nn phn cng v h tr
vic bo v b nh. Tuy nhin, k t 24/11/2008, SOS khng c pht trin bi
v cc thnh vin pht trin chnh tt nghip.
1.2.4.4. MantisOS
Mantis OS c pht trin i hc Colorado. Mantis OS cho php h tr
a lung thc hin a lung phn chia theo thi gian u tin. cho php lp
trnh a lung, nhn Mantis cng h tr ng b I/Os (ngc vi chia giai on
I/Os), v mt tp cc b iu khin ng thi Semaphores. Phin bn Mantis mi
nht ci thin s n nh ca h thng v sa mt s li. Ngoi ra, n thc hin
giao thc CTP (Collection Tree Protocol) cho cc nn phn cng MicaZ v
TelosB.
1.2.4.5. Nano-RK
H tr cc ng dng mng khng dy nhy cm vi thi gian nh gim st
mi trng v gim st an ninh. Nano-RK c pht trin i hc Carnegie
Mellon, thc hin h iu hnh thi gian thc. Nano-RK h tr quyn u tin a
nhim m bo cc nhim v c p ng ng thi hn. N cng h tr vic
ginh trc rng di tn mng v CPU, tc l cc nhim v c th ch nh cc
yu cu ti nguyn ca chng v h iu hnh cung cp bng thng mng v vic
truy cp cc chu k CPU kp thi, m bo v c kim sot. thun tin cho
vic lp trnh, Nano-RK cung cp cc APIs cho cc tru tng ha ging nh
socket, v h thng chung h tr nh tuyn v lp lch mng.
1.2.4.6. RETOS
RETOS c pht trin i hc Yonsei Hn Quc, c thit k ci
tin mt s im cc cng vic trc. N ci tin kh nng phc hi h thng
12
13
14
15
16
18
19
20
21
22
Hnh 2.3: Kin trc giao thc mng trong h iu hnh Contiki.
2.4.1. Ngn xp uIP
Trong nhng nm gn y, cng vi s thnh cng ca Internet, giao thc
TCP/IP tr thnh tiu chun ton cu trong lnh vc truyn thng, TCP/IP l
23
24
26
27
29
30
Event timer (etimer): l loi nh thi hot ng, c kch hot trong cc
Process v s dng gi mt s kin n Process khi b nh thi ht
hn.
Callback timer (ctimer): l loi nh thi hot ng, c th c s dng
bt k v tr no trong chng trnh, c chc nng gi mt hm x l mi
khi b nh thi ht hn. Ctimer c s dng trong module RIME ca
Contiki.
Hnh 2.11 minh ha v d s dng Etimer trong Contiki:
33
34
35
38
**> cd contiki-2.x/tools/cooja**
**> ant run**
COOJA builds and the simulator is started. However, before you can simulate a Contiki
system, you need to configure COOJA to correctly interface your toolchain.
This dialog displays your current COOJA configuration: compiler paths and arguments, a
bunch of regular expressions used to parse information from these tools, etc. **These
settings are stored in your home directory: .cooja.user.properties**, such as in
///home/myuser// or //C:\Documents And Settings\myuser//.
39
Complete all 4 steps. Note that you may have to change the recommended settings. Any
changes can later be reviewed in the //External tools paths// dialog
A simulation without motes and using the default parameters is created. Before adding
motes to the simulation, we first need to create a mote type. The mote type determines
the type of sensor hardware and which Contiki applications are to be simulated.
Open //Mote Types > Create mote type > Contiki Mote Type//
We have now added a mote type, however, the simulation does not yet contain any
simulated motes.
You may later add further motes of this type by menu //Menu > Motes > Add motes of
type >// //My first hello world mote type//. A few plugins are started: a control panel for
starting and pausing the simulation, a visualizer that shows the node positions, and a log
listener showing printouts of all simulated nodes.
Press **Start** (or CTRL+S) in the **Control Panel** plugin to start simulating.
40
Note that only the configuration, not the state of the simulation is saved. Hence, when a
simulation is loaded, the simulation will start over from time 0.
To save the current simulation:
To load a simulation:
The simulation is loaded, and the plugins will appear after a while. Loading a simulation
with several mote types may take some time, since Contiki is recompiled in the
background.
A similar functionality as saving and loading simulation, is **reloading** a simulation.
To reload the current simulation:
Open //Menu >// //File > Reload simulation > same random seed//
Example:**
Create a COOJA simulation, compile //myapp.c// and finally save the simulation
configuration **in the project directory**.
41
The Contiki application path will be stored as "[CONFIG]/myapp.c" i.e. relative where
the configuration file is stored.
or
Contents
[hide]
4 Summary
To start Cooja, double-click on the "Run Cooja" icon to the right on the screen. This will
bring up a terminal window with some text scrolling by. The Cooja Java code may need
to be compiled, which may take a few seconds. After a few seconds the Cooja window
appears. Maximize the window by double-clicking on the title bar. The screen should
now look like this:
43
Click on the Browse item, and a file dialog box appears. Go to the contiki2.x/examples/hello-world directory and open the hello-world-example.csc file:
Opening the simulation will cause Contiki to be compiled. The compilation output is
shown in a dialog box on the screen:
44
45
After a few seconds, the two nodes have started and printed out their Hello World
message. The simulation can now be stopped by pressing the Pause button.
Congratulations! You have just compiled and simulated your first Contiki system!
46
Wait for the compilation to finish. The screen now shows the data collection example:
47
Click the Start button in the Control Panel window. See the collection network form in
the Simulation Visualizer.
48
Contents
[hide]
49
Create two directories: one for holding Contiki projects, and one for holding the Hello,
World project. Do this by issuing the following commands (if you choose to use different
directories change the paths accordingly):
mkdir projects
cd projects
mkdir hello-world-project
cd hello-world-project
50
51
Save the file by clicking on the Save button. The Makefile will include the Contiki Make
structure and automatically compile your project. We can now start writing our first
program.
52
The first line includes the Contiki C header. This is needed to include all the
relevant Contiki definitions and libraries.
53
The second line declares a Contiki process. This process has a variable name
(hello_world_process), and a string name ("Hello world process"). The string
name is used in debugging and for the Contiki shell's ps command.
The third line tells Contiki that the hello_world_process should be automatically
started when Contiki boots.
The fourth line defines the hello_world_process. The ev and data arguments to
the PROCESS_THREAD() macro are the variable names that hold the event
number and the event data for subsequent events that this process may receive.
54
55
This will cause the entire Contiki system to be compiled and a lot of compilation output
to be produced in the terminal window. When compilation has finished, the terminal
window looks like this:
56
This brings up a number of windows. You may need to rearrange the windows to see
what is going on:
57
The USART1 Port Output window shows the output from the serial port of the mote. We
see the Contiki boot-up messages as well as our Hello, world message.
The SkyGui window shows the Tmote Sky mote. The reset and user buttons can be
pressed by clicking on them. We press the reset button to see the output:
The boot-up messages and our Hello, World message shows up again in the serial port
window.
We stop the simulation by bringing up the terminal window, hold the Ctrl key, and press
the C key.
58
The Tmote Sky should now be accessible from within Instant Contiki. Test this by
running
make sky-motelist
If the Tmote Sky shows up, it is possible to reprogram it with the Hello, World
application:
59
make hello-world.upload
This will upload Contiki and the Hello, World program to the Tmote Sky mote.
When the programming is complete, Contiki and the Hello, world program should now
be running on the Tmote Sky. See the output of the Tmote Sky by running
make login
60
To see the Hello, world program in action, we press the reset button on the Tmote Sky.
The following output should appear:
Congratulations! A complete Contiki project now runs on your Tmote Sky mote!
Hold the Ctrl key and press C to get back to the prompt.
Example-Shell Guide
From ContikiWiki
Jump to: navigation, search
TODO: Cross-check for contiki 2.5 release
The following is an extract from the Contiki tutorial given at the ACM/IEEE conference
on Information Processing in Sensor Networks (IPSN) in April 2009.
cd
cd contiki-2.x
cd examples
cd sky-shell
make sky-shell.upload
Wait for the compilation and uploading to finish. To connect to the shell over the USB
port, run:
make login
Press the return key to get a prompt. (We have found that with Instant Contiki running in
VMWare, garbage characters are sometimes printed out when connecting. They can be
safely ignored.) Next, we try a few shell commands. To get a list of available commands,
run:
help
The power command prints out the current power profile from Contiki's software-based
power profiler. To print out the power profile in decimal digits, run:
power | binprint
The output will look something like: 12 236 0 37421 0 4 0 380 0 0 0 380 0
The numbers that the power command outputs are:
1. The number of data items that follow, to make automatic parsing of the output
easier
2. CPU low-power mode time, least significant 16 bits
3. CPU low-power mode time, most significant 16 bits
4. CPU active mode time, least significant 16 bits
5. CPU active mode time, most significant 16 bits
6. Radio transmission time, least significant 16 bits
7. Radio transmission time, most significant 16 bits
8. Radio listen time, least significant 16 bits
9. Radio listen time, most significant 16 bits
10. Radio transmission time in idle listening, least significant 16 bits
11. Radio transmission time in idle listening, most significant 16 bits
62
Contents
[hide]
6 Summary
63
64
This opens the CollectView application. If there are no Tmote Sky motes connected to
the PC, a dialog will be displayed. Close this with its OK button.
Now we use CollectView to upload Contiki to all connected motes. Click the "Program
Nodes..." button:
You will now be asked whether you want to program the nodes. Obviously you do, so
click the Yes button:
66
67
If you need to program more motes, repeat the process. When all motes have been
programmed, remove all motes except one.
Once we have connected to the node, we can click on the "Start collect" button. This will
instruct the nodes to form a data collection network, with the mote connected to the USB
port as the sink.
68
Click the "Send command to nodes" button. This sends a command to the nodes in the
network that will cause them to periodically send sensor data to the sink. This data will
be picked up by the CollectView program and displayed.
69
Click on the "Network Graph" tab. This shows the structure of the collection network.
The nodes are moving around, so it is a good idea to fix the position of the sink node.
The sink node cna be identified by looking to what node the arrows are pointing. Right
click on the node and select the "Fixed node position" menu item to fix its position. To
make it easier to right click on the node, it might be a good idea to uncheck the "Update
layout" menu item first, as this will stop the movement of the nodes.
70
The "Node info" tab shows a table with information for each node. Here you can see how
many packages have been received, how many hops nodes are away amongst other data.
71
The "Sensors" tab shows the sensor data from the network.
72
73
Contents
[hide]
In Cooja, open the File menu, the Open simulation menu item, and click on Browse
74
75
76
77
Click on the Network tab to explore the parameters in the network. Click the <All> item
on the top left to select all nodes.
78
The Node Info tab has more information about the nodes.
The Power tab shows the power consumption of the nodes in the network.
79
80
81
Give the mote type a name, and click on the Browse button.
82
83
When the Compilation is complete, the Compile button has changed into a Create button.
Click this button.
Create one sink node.
84
The sender node uses the udp-sender.c file from the same directory as the sink node.
Click the Compile and Create buttons.
85
86
87
88
REST-Example Guide
From ContikiWiki
Jump to: navigation, search
Open a terminal and go to "<CONTIKI_HOME>/examples/rest-example/" directory.
MAIN EXAMPLE: rest-server-example.c : A RESTful server example showing how to
use the REST layer to develop server-side applications (possible to run it over either
COAP or HTTP) To use COAP as the underlying application protocol, one should define
WITH_COAP = 1 in rest-example/Makefile. Otherwise, HTTP is used. Look at the
source code to see which resources are available. (check the RESOURCE macros in the
code). Each resource has a handler function which is called by the REST layer to serve
the request. (i.e. "helloworld" resource has a handler function named
"helloworld_handler" which is called when a web service request is received for
"helloworld" resource.)
To run REST examples in COOJA under Linux
Accessing the server from outside: 1. Start COOJA and load the simulation "rest-serverexample.csc" by the following command.
make TARGET=cooja rest-server-example.csc
2. After loading the COOJA file, open another another terminal pointing to the same
directory and connect to the COOJA simulation using tunslip6:
make connect-router-cooja
3. You need to use a COAP or HTTP client to interact with the COOJA nodes running
REST code. In this setting, two servers are available: IP addresses are
aaaa::0212:7402:0002:0202 and aaaa::0212:7403:0003:0303. COAP uses 61616, whereas
HTTP uses 8080 port in default configuration. First, ping the COOJA nodes to test the
connectivity.
ping6 aaaa::0212:7402:0002:0202
ping6 aaaa::0212:7403:0003:0303
HTTP Examples You can use curl as an http client to interact with the COOJA motes
running REST code.
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/helloworld
#get helloworld plain text
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/led?
color=green -d mode=off -i #turn off the green led
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/.wellknown/core -i
89
COAP Examples You should run a COAP client on your computer. You can use the
URLs and methods provided above in HTTP examples to test the COAP Server.
Accessing the server inside the sensor network: (Note: Provided only for COAP
implementation) Start COOJA and load the simulation "coap-client-server-example.csc"
by the following command.
make TARGET=cooja coap-client-server-example.csc
2. Disconnect the nodes and program one node with the RPL border router
(cd ../ipv6/rpl-border-router && make TARGET=sky border-router.upload)
3. Connect to the border router using tunslip6: [Once tunslip6 has been built it can be
invoked directly with useful debugging switches, $CONTIKI/tools/tunslip6 --help]
make connect-router
5. Remaining parts are the same with the COOJA example. (i.e. if it is a COAP Server, it
is available at <NODE_IP_ADDR>:61616)
90
91