wireless embedded systems (0120442x) sensor network programming and motelib simulator
DESCRIPTION
Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator. Chaiporn Jaikaeo [email protected] Department of Computer Engineering Kasetsart University. Outline. Network programming with MoteLib MoteSim – MoteLib's Simulator. Virtual Mote. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/1.jpg)
Network Kernel Architectures and Implementation
(01204423)
Sensor Network Programmingand MoteLib Simulator
Chaiporn [email protected]
Department of Computer EngineeringKasetsart University
![Page 2: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/2.jpg)
2
Outline Network programming with MoteLib MoteSim – MoteLib's Simulator
![Page 3: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/3.jpg)
3
Mote and Network Emulator
Virtual Mote
![Page 4: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/4.jpg)
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()
![Page 5: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/5.jpg)
5
Creating Executable for Simulator Executable for simulator can be built
by running
Executable will be stored under build/sim directory
make PLATFORM=sim
![Page 6: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/6.jpg)
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()
![Page 7: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/7.jpg)
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)
![Page 8: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/8.jpg)
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
![Page 9: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/9.jpg)
9
Accessing Node Objects Node objects are stored in the node
list inside sim object>>> n = sim.nodes[2]>>> dir(n)
![Page 10: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/10.jpg)
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()
![Page 11: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/11.jpg)
11
Emulating Button Button pressing can be emulated by
two methods: pressButton() releaseButton()
>>> n = sim.nodes[3]>>> n.pressButton()>>> n.releaseButton()
![Page 12: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/12.jpg)
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
![Page 13: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/13.jpg)
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
![Page 14: Wireless Embedded Systems (0120442x) Sensor Network Programming and MoteLib Simulator](https://reader035.vdocuments.mx/reader035/viewer/2022062411/56816689550346895dda4256/html5/thumbnails/14.jpg)
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