Presentation is loading. Please wait.

Presentation is loading. Please wait.

Architectures and Applications for Wireless Sensor Networks (01204525) Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo

Similar presentations


Presentation on theme: "Architectures and Applications for Wireless Sensor Networks (01204525) Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo"— Presentation transcript:

1 Architectures and Applications for Wireless Sensor Networks (01204525) Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo chaiporn.j@ku.ac.th Department of Computer Engineering Kasetsart University

2 2 Outline Network programming with MoteLib Network programming with MoteLib MoteSim – MoteLib's Simulator MoteSim – MoteLib's Simulator

3 3 Mote and Network Emulator Virtual Mote

4 4 Mote and Network Simulation Motes are modeled with standard C program Motes are modeled with standard C program  Exact same code as used for the actual hardware Network is modeled with Python program Network 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()

5 5 Creating Executable for Simulator Executable for simulator can be built by running Executable for simulator can be built by running  Executable will be stored under build/sim directory make PLATFORM=sim

6 6 Modeling Network Network is modeled with Python Network is modeled with Python Make sure the following directories are part of PYTHONPATH Make sure the following directories are part of PYTHONPATH Try the following program sim-blink.py 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 7 Virtual Mote Creation Virtual mote object can be instantiated from class Virtual mote object can be instantiated from class Mote Each virtual mote instance must be added to the simulation using method Each 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)

8 8 Enabling Python Console IPython is recommended for better interaction 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 9 Accessing Node Objects Node objects are stored in the node list inside object Node objects are stored in the node list inside sim object >>> n = sim.nodes[2] >>> dir(n)

10 10 Turning Node On and Off Node can be turned off using method Node can be turned off using shutdown() method method turns node back on boot() method turns node back on >>> sim.nodes[3].shutdown() >>> sim.nodes[3].boot()

11 11 Emulating Button Button pressing can be emulated by two methods: Button pressing can be emulated by two methods:   pressButton()   releaseButton() >>> n = sim.nodes[3] >>> n.pressButton() >>> n.releaseButton()

12 12 Emulating UART Node's UART interface can be emulated via TCP socket Node's UART interface can be emulated via TCP socket  Not activated by default  Use inside node's object to activate  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 57597 Trying 0.0.0.0... Connected to 0. Escape character is '^]'. ^] telnet> mode c switch to character mode

13 13 Exercise: Voting Machine Reimplement the wireless voting application 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 14 Exercise (cont'd) Create a virtual network with 5 nodes 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


Download ppt "Architectures and Applications for Wireless Sensor Networks (01204525) Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo"

Similar presentations


Ads by Google