3. Required Hardwares
■ Programming Board
■ Mote
■ Sensing Board
■ And a PC of course….
A Typical Mote
5/31/2018 Riman Mandal, mandal.riman@gmail.com 3
4. Typical Programming Board
For Practical Purpose We have a different model
5/31/2018 Riman Mandal, mandal.riman@gmail.com 4
5. Typical Sensor Board
For Practical Purpose We have a different model
5/31/2018 Riman Mandal, mandal.riman@gmail.com 5
6. Typical Mote
Antenna Interface
Power Button
2 AA battery
Section
For Practical Purpose We have a different model
5/31/2018 Riman Mandal, mandal.riman@gmail.com 6
7. Tiny OS
■ An operating system for low power, embedded,
wireless devices
– Wireless sensor networks (WSNs)
– Sensor-actuator networks
– Embedded robotics
■ Open source, open developer community
■ http://www.tinyos.net
■ E-book: TinyOS Programming:
http://csl.stanford.edu/~pal/pubs/tinyos-
programming.pdf
5/31/2018 Riman Mandal, mandal.riman@gmail.com 7
8. Tiny OS (Cont.)
■ An open-source development environment
■ Not an operation system for general purpose, it
is designed for wireless embedded sensor
network.
■ Programming language: NesC (an extension of C)
■ It features a component-based architecture.
■ Supported platforms include Linux, Windows
2000/XP with Cygwin.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 8
9. Installation
■ Need Ubuntu 12.04 LTS for hassle free installation.
■ Try installing TinyOS ON Windows machines using VMWare
or Virtual Box.
■ I will send the details of Installation via e-mail.
■ If you are interested we can try on Windows using
Cygwin.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 9
10. Installing TinyOS 2.1.2
on Ubuntu 12.04 LTS
using Virtual Box
5/31/2018 Riman Mandal, mandal.riman@gmail.com 10
11. Preprocessing
■ Install VirtualBox on your Windows machine.
■ Install Ubuntu 12.04LTS inside the Virtual Machine.
■ Start the Ubuntu from Virtual machine.
■ Open Ubuntu Terminal.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 11
12. Step 1 Adding TinyOS
Source
■ Execute the following command,
■ Paste the line given below at the end of the file
■ Save the file and quit
5/31/2018 Riman Mandal, mandal.riman@gmail.com 12
sudo gedit /etc/apt/sources.list
deb http://tinyos.stanford.edu/tinyos/dists/ubuntu
lucid main
13. Step 2 Installing TinyOS
■ First update the TinyOS source using.
■ Use the following command to install TinyOS on your
Ubuntu machine.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 13
sudo apt-get update
sudo apt-get install tinyos2.1.2
14. Step 3 Environment Setup
■ Enter the following command to edit the Environment
setup in Ubuntu
■ Add the following line at the end of the ~/.bashrc file.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 14
sudo gedit ~/.bashrc
#Sourcing the tinyos environment variable setup script
source /opt/tinyos-2.1.2/tinyos.sh
export CLASSPATH=$CLASSPATH:.
15. Step 4 Creating the
Environment Source File
■ Create the setup script file using the command
■ Now enter the following contents into this file
5/31/2018 Riman Mandal, mandal.riman@gmail.com 15
sudo gedit /opt/tinyos-2.1.2/tinyos.sh
#echo "Setting up for TinyOS 2.1.2"
export TOSROOT=
export TOSDIR=
export MAKERULES=
TOSROOT="/opt/tinyos-2.1.2"
TOSDIR="$TOSROOT/tos"
CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java:$TOSROOT/support/sdk
/java/tinyos.jar
MAKERULES="$TOSROOT/support/make/Makerules"
export TOSROOT
export TOSDIR
export CLASSPATH
export MAKERULES
16. Step 5 Permission for Setup
Script and Refresh
Environment
■ Run the command below to allow this script to execute
■ To refresh the environment with new setup - close and
start a new terminal or alternatively execute the
following command
5/31/2018 Riman Mandal, mandal.riman@gmail.com 16
sudo chmod 755 /opt/tinyos-2.1.2/tinyos.sh
source ~/.bashrc
17. Checking if Installation is
successful
■ Run the command to check TOS environment setup is
complete or not
■ If it gives warnings related to Java version then do
■ If your version is above 1.5, then ignore this warning else
upgrade to a newer java version. Ignore
the warning related to graphviz.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 17
tos-check-env
java -version
19. Basic Idea
■ HURRY UP AND SLEEP!!
– Sleep as often as possible to save power
■ Programs are built out of components
– Libraries and components are written in nesC.
– Applications are too -- just additional components
composed with the OS components.
■ Each component is specified by an interface
– Provides “hooks” for wiring components together
■ Components are statically wired together based on their
interfaces
– Increases runtime efficiency
5/31/2018 Riman Mandal, mandal.riman@gmail.com 19
20. Basic Unit of Programming
■ Basic unit of nesC code is a component
■ Components connect via interfaces
– Connections called “wiring”
5/31/2018 Riman Mandal, mandal.riman@gmail.com 20
B
A
interface
21. What is a Component?
■ A component is a file (names must match)
■ Modules are components that have variables and
executable code
■ Configurations are components that wires other
components together
■ A component does not care if another component is a
module or configuration
■ A component may be composed of other components via
configurations
5/31/2018 Riman Mandal, mandal.riman@gmail.com 21
23. Singletons and Generics
5/31/2018 Riman Mandal, mandal.riman@gmail.com 23
■ Singleton components are unique: they exist in a global
namespace
■ Generics are instantiated: each instantiation is a new,
independent copy
configuration BlinkC { … }
implementation {
components new TimerC();
components BlinkC;
BlinkC.Timer -> TimerC;
}
24. Component Syntax - Module
5/31/2018 Riman Mandal, mandal.riman@gmail.com 24
■ A component specifies a set of interfaces by which it is connected to
other components
– provides a set of interfaces to others
– uses a set of interfaces provided by others
module ForwarderM {
provides {
interface StdControl;
}
uses {
interface StdControl as CommControl;
interface ReceiveMsg;
interface SendMsg;
interface Leds;
}
}
implementation {
…// code implementing all provided commands
and used events
}
ForwarderM
StdControl ReceiveMsg
provides uses
CommControl
SendMsg
Leds
26. Interface
5/31/2018 Riman Mandal, mandal.riman@gmail.com 26
■ Collections of related functions
■ Define how components connect
■ Interfaces are bi-directional: for A->B
– Commands are from A to B
– Events are from B to A
■ Can have parameters (types)
interface Timer<tag> {
command void startOneShot(uint32_t period);
command void startPeriodic(uint32_t period);
event void fired();
}
27. Interface (provide and use)
5/31/2018 Riman Mandal, mandal.riman@gmail.com 27
User
Provider
Interface
Commands
Events
Module BlinkC {
use interface xxxx;
provide interface xxxxxxx;
.........
}
28. Interface (provide and use)
(Cont.)
■ A component provides and uses interfaces.
■ A interface defines a logically related set of commands
and events.
■ Components implement the events they use and the
commands they provide:
5/31/2018 Riman Mandal, mandal.riman@gmail.com 28
Component Commands Events
Use Can call Must implement
Provide Must implement Can signal
29. Terminal Commands related
to TinyOS
■ system modifications
– sudo chmod –R 777 /bin
– sudo chmod –R 777 /dev
■ applications directory
– /opt/tinyos-2.1.1/apps/
■ making hex image for iris mote without sensor board
– make iris
■ making hex image for iris mote with sensor board
– SENSORBOARD=mda100 make iris
■ burning hex image into iris mote
– make <mote> install.moteid burnerid,/dev/tty<serialport>
– EX. make iris install.0 mib520,/dev/ttyUSB0
– EX. make iris reinstall.0 mib520,/dev/ttyUSB0
■ burning hex image into iris mote with sensor board
■ SENSORBOARD=mda100 make iris reinstall.0 mib520,/dev/ttyUSB0
5/31/2018 Riman Mandal, mandal.riman@gmail.com 29
30. Power Up Testing
Programing
■ Try to build a tinyOS app that turn on the Red Led on
Power up.
5/31/2018 Riman Mandal, mandal.riman@gmail.com 30
PowerUpC
uses
Boot
Leds
MainC
Boot
LedsC
Leds
32. Blink App Using
Timer<TMilli> C
■ The Red light will blink continuously with a time interval
5/31/2018 Riman Mandal, mandal.riman@gmail.com 32
BlinkC
uses
Boot
Leds
MainC
Boot
LedsC
33. Using Printf Component
■ Include printf.h header file in the module file
■ Use Printf method to print anything on terminal
■ Add Component PrintfC in the Component File
■ Use the following command to print on the terminal
– java net.tinyos.tools.PrintfClient -comm
serial@/dev/ttyUSB1:iris
5/31/2018 Riman Mandal, mandal.riman@gmail.com 33
java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSBXXX:telosb