and Implementation 01204423 Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo chaipornjkuacth Department of Computer Engineering Kasetsart University 2 Outline Network programming with MoteLib ID: 807132
Download The PPT/PDF document "Network Kernel Architectures" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Network Kernel Architectures and Implementation(01204423) Sensor Network Programmingand MoteLib Simulator
Chaiporn Jaikaeo
chaiporn.j@ku.ac.th
Department of Computer Engineering
Kasetsart University
Slide22OutlineNetwork programming with MoteLibMoteSim – MoteLib's Simulator
Slide33Mote and Network Emulator
Virtual
Mote
Slide44Mote and Network SimulationMotes are modeled with standard C programExact same code as used for the actual hardwareNetwork is modeled with Python program
from
motesim
import
Simulator, Mote
MOTEAPP = '
build/sim/count-radio.elf
'
sim = Simulator()
sim.addNode(Mote(MOTEAPP), (100,100))
sim.addNode(Mote(MOTEAPP), (200,100))
sim.run()
Slide55Creating Executable for SimulatorExecutable for simulator can be built by runningExecutable will be stored under build/sim directory
make PLATFORM=
sim
Slide66Modeling NetworkNetwork is modeled with PythonMake sure the following directories are part of PYTHONPATHTry the following program sim-blink.pyCan be found in
examples/
directory
$MOTELIB_DIR
/platforms/sim/python
$MOTELIB_DIR
/lib/python
from
motesim
import
Simulator, Mote
sim = Simulator()
sim.addNode(Mote('build/sim/blink.elf'), (100,100))
sim.addNode(Mote('build/sim/blink.elf'), (200,100))
sim.run()
Slide77Virtual Mote CreationVirtual mote object can be instantiated from class MoteEach virtual mote instance must be added to the simulation using addNode method
from
motesim
import
Simulator, Mote
sim = Simulator()
m1 = Mote('build/sim/blink.elf')
m2 = Mote('build/sim/count.elf')
sim.addNode(m1, (100,100))
sim.addNode(m2, (200,100))
sim.run()
Create a mote
running
'blink
' app
Create a mote
running
'count
' app
Add m2 to the simulation
at position (200,100)
Slide88Enabling Python ConsoleIPython is recommended for better interaction
from
motesim
import
Simulator, Mote
sim = Simulator()
sim.addNode(Mote('build/sim/blink.elf'), (100,100))
sim.addNode(Mote('build/sim/blink.elf'), (200,100))
sim.run(script=sim.console)
$ sudo apt-get install ipython
Slide99Accessing Node ObjectsNode objects are stored in the node list inside sim object
>>> n = sim.nodes[2]
>>> dir(n)
Slide1010Turning Node On and OffNode can be turned off using shutdown() methodboot() method turns node back on
>>> sim.nodes[3].shutdown()
>>> sim.nodes[3].boot()
Slide1111Emulating ButtonButton pressing can be emulated by two methods:pressButton()releaseButton()
>>> n = sim.nodes[3]
>>> n.pressButton()
>>> n.releaseButton()
Slide1212Emulating UARTNode's UART interface can be emulated via TCP socketNot activated by defaultUse activateSocket() inside node's uart object to activate
>>> n = sim.nodes[3]
>>> n.uart.activateSocket()
('0.0.0.0', 32345)
>>>
Listening port
$ telnet localhost 57597
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
^]
telnet> mode c
switch to character mode
Slide1313Exercise: Voting MachineReimplement the wireless voting applicationAllow user to cast a vote using the USER buttonVoting choices are: Red (1),
Yellow (2)
,
Green (3)
, or No Vote (0)
When the USER button is pressed,
Set LED status accordingly
Report current vote to the base station (#0) with message type 50
Integrate base station functionality into your app
Slide1414Exercise (cont'd)Create a virtual network with 5 nodesActivate UART at base station (node #0)Telnet to the open portEmulate button pressing at other nodes