Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator
description
Transcript of Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator
Network Kernel Architectures and Implementation
(01204423)
Sensor Network Programmingand MoteLib Simulator
Chaiporn [email protected]
Department of Computer EngineeringKasetsart University
2
Outline Network programming with MoteLib MoteSim – MoteLib's Simulator
3
Mote and Network Emulator
Virtual Mote
4
Mote and Network Simulation Motes are modeled with standard C
program Exact same code as used for the actual
hardware Network is modeled with Python
programfrom 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()
5
Creating Executable for Simulator Executable for simulator can be built
by running
Executable will be stored under build/sim directory
make PLATFORM=sim
6
Modeling Network Network is modeled with Python Make sure the following directories are
part of PYTHONPATH
Try the following program sim-blink.py Can 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()
7
Virtual Mote Creation Virtual mote object can be
instantiated from class Mote Each virtual mote instance must be
added to the simulation using addNode methodfrom 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 simulationat position (200,100)
8
Enabling Python Console
IPython 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
9
Accessing Node Objects Node objects are stored in the node
list inside sim object>>> n = sim.nodes[2]>>> dir(n)
10
Turning Node On and Off Node can be turned off using
shutdown() method boot() method turns node back on
>>> sim.nodes[3].shutdown()>>> sim.nodes[3].boot()
11
Emulating Button Button pressing can be emulated by
two methods: pressButton() releaseButton()
>>> n = sim.nodes[3]>>> n.pressButton()>>> n.releaseButton()
12
Emulating UART Node's UART interface can be
emulated via TCP socket Not activated by default Use activateSocket() inside node's uart object to activate
>>> n = sim.nodes[3]>>> n.uart.activateSocket()('0.0.0.0', 32345)>>>
Listening port
$ telnet localhost 57597Trying 0.0.0.0...Connected to 0.Escape character is '^]'.^]
telnet> mode c
switch to character mode
13
Exercise: Voting Machine Reimplement the wireless voting
application Allow user to cast a vote using the USER
button Voting 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
14
Exercise (cont'd) Create a virtual network with 5
nodes Activate UART at base station (node
#0) Telnet to the open port Emulate button pressing at other nodes