SlideShare a Scribd company logo
1 of 44
Download to read offline
Internet of Things Lab
Lab 6: TinyOS (2)
Agenda
2
• Using the Radio in TinyOS
• TOSSIM simulation
• Advanced Examples
• Challenge 3
Using the Radio
Creating/Sending/Receiving/Manipulating Messages
General Idea
4
Fill
Message
Specify
Destination
Pass
Message to OS
Wait For
FeedBack
OS Stores
Message
OS signal
Msg Reception
Pass Message to
Applications
SENDER
RECEIVER
Read
Data
Message Buffer Abstraction
5
• In tos/types/messages.h
• Header, footer, metadata: already implemented by the
specific link layer
• Data: handled by the application/developer
typedef nx_struct message_t {
nx_uint8_t header[sizeof(message_header_t)];
nx_uint8_t data[TOSH_DATA_LENGTH];
nx_uint8_t footer[sizeof(message_header_t)];
nx_uint8_t metadata[sizeof(message_metadata_t)];
} message_t;
Message.h file
6
#ifndef FOO_H
#define FOO_H
typedef nx_struct FooMsg {
nx_uint16_t field1;
nx_uint16_t field2;
….
nx_uint16_t field_N;
} FooMsg;
enum { FOO_OPTIONAL_CONSTANTS = 0 };
#endif
Header and Metadata
7
typedef nx_struct cc2420_header_t {
nxle_uint8_t length;
nxle_uint16_t fcf;
nxle_uint8_t dsn;
nxle_uint16_t destpan;
nxle_uint16_t dest;
nxle_uint16_t src;
nxle_uint8_t network; // optionally included with
6LowPAN layer
nxle_uint8_t type;
} cc2420_header_t;
typedef nx_struct cc2420_metadata_t {
nx_uint8_t tx_power;
nx_uint8_t rssi;
nx_uint8_t lqi;
nx_bool crc;
nx_bool ack;
nx_uint16_t time;
} cc2420_metadata_t;
Interfaces
8
• Components above the basic data-link layer MUST always
access packet fields through interfaces (in /tos/interfaces/).
• Messages interfaces:
• AMPacket: manipulate packets
• AMSend
• Receive
• PacketAcknowledgements (Acks)
Communication stack
9
• Active Message (AM) TinyOS communication
technology
• Include the communication protocol to send and receive
packets
• Each Packet is characterized by an AM Type:
• Similar to a UDP port
Communication stack
10
• message_t structure:
• Packet are represented by a message_t structure
• To access message_t fields is must be used Packet and AMPacket interfaces:
interface Packet {
command uint8_t payloadLength(message_t* msg);
command void* getPayload(message_t* msg, uint8_t len);
...
}
interface AMPacket {
command am_addr_t address();
command am_addr_t destination(message_t* amsg);
...
}
Sender Component
11
AMSenderC.nc
generic configuration AMSenderC(am_id_t id)
{
provides {
interface AMSend;
interface Packet;
interface AMPacket;
interface PacketAcknowledgements as Acks;
}
}
Receiver Component
12
AMReceiverC.nc
generic configuration AMReceiverC(am_id_t id)
{
provides{
interface Receive;
interface Packet;
interface AMPacket;
}
}
SplitControl Interface
13
• Radio needs to be activated prior to be used.
• To turn on the radio, use the split-operation start/startDone
• To turn off the radio use the split-operation stop/stopDone
• ActiveMessageC create the communication stack on evry specific
architecture
• AMSenderC component to send messages
• AMReceiverC component to receive messages
Example 2 – RadioCountToLeds
14
Create an application that counts over a timer and broadcast the
counter in a wireless packet.
What do we need?
• Header File: to define message structure (RadioCountToLeds.h)
• Module component: to implement interfaces
(RadioCountToLedsC.nc)
• Configuration component: to define the program graph, and the
relationship among components (RadioCountToLedsAppC.nc)
Message Structure
15
• Message structure in RadioCountToLeds.h file
typedef nx_struct radio_count_msg_t {
nx_uint16_t counter; //counter value
} radio_count_msg_t;
enum {
AM_RADIO_COUNT_MSG = 6, TIMER_PERIOD_MILLI = 250
};
Module Component
16
1. Specify the interfaces to be used
2. Define support variables
3. Initialize and start the radio
4. Implement the core of the application
5. Implement all the events of the used interfaces
Module Component
17
• Define the interfaces to be used:
module RadioCountToLedsC
{
uses interface Packet;
uses interface AMSend;
uses interface Receive;
uses interface SplitControl as AMControl;
}
• Define some variables:
implementation {
message_t packet;
bool locked; ...
}
Control interface
Packet Manipulation
Interfaces
Local Variables
Initialize and Start the Radio
18
event void Boot.booted() {
call AMControl.start();
}
event void AMControl.startDone(error_t err) {
if (err == SUCCESS) {
call MilliTimer.startPeriodic(TIMER_PERIOD_MILLI );
}
else {
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err) { }
Events to report
Interface Operation
Implement the Application Logic
19
event void MilliTimer.fired() {
...
if (!locked) {
radio_count_msg_t* rcm = (radio_count_msg_t*)call
Packet.getPayload(&packet, sizeof(radio_count_msg_t));
rcm->counter = counter;
if (call AMSend.send(AM_BROADCAST_ADDR, &packet,
sizeof(radio_count_msg_t)) == SUCCESS) {
locked= TRUE; }
}
}
Create and set
Packet
Send Packet
Implement Events of Used Interfaces
20
event void AMSend.sendDone(message_t* msg, error_t error
{
if (&packet == msg) {
loked = FALSE;
}
}
Must implement the events referred to all the interfaces of used
components.
What about Receiving?
21
• We need a Receive interface
uses interface Receive;
• We need to implement an event Receive handler
event message_t* Receive.receive(message_t* msg, void*
payload, uint8_t len) {
if (len == sizeof(radio_count_msg_t)) {
radio_count_msg_t* rcm= (radio_count_msg_t*)payload;
call Leds.set(rcm->counter);
}
return msg;
}
• We need to modify the configuration component
implementation {
... components new AMReceiverC(AM_RADIO_COUNT_MSG); ... }
implementation {
... App.Receive -> AMReceiverC; ... }
Configuration File
22
implementation {
...
components ActiveMessageC;
components new AMSenderC(AM_RADIO_COUNT_MSG);
...
App.Packet -> AMSenderC;
App.AMSend -> AMSenderC;
App.AMControl -> ActiveMessageC;
...
}
RadioCountToLeds
23
• Let’s have a look at the files (RadioCountToLeds project)
• Let’s see how it works
• Let’s try to turn off a device
• Can you do that in Cooja?
Message Destination
24
• AM_BROADCAST_ADDR: for broadcast messages
call AMSend.send(AM_BROADCAST_ADDR, &packet,
sizeof(radio_count_msg_t))
Message will be handled by all receivers
• mote id: for unicast messages (e.g., 1,2 …)
call AMSend.send(1, &packet, sizeof(radio_count_msg_t))
Message will be handled only by mote 1, even if other motes are in range
Get current mote ID
25
• In some cases can be useful to get the mote ID used in the simulation
• The mote ID is store in the macro TOS_NODE_ID
• e.g.: Program motes with different behaviours, based on mote ID
if ( TOS_NODE_ID == 1 ) {
//do stuff for mote 1
}
else if ( TOS_NODE_ID ==2){
// do stuff for mote 2
}
else{
//stuff for other motes
}
TinyOS SIMulator
Simulate a Wireless Sensor Network with TOSSIM
Motivations
27
• WSN require large scale deployment
• Located in inaccessible places
• Apps are deployed only once during network lifetime
• Little room to re-deploy on errors
System Evaluation
28
• Check correctness of application behavior
• Sensors are hard to debug!
• “… prepare to a painful experience” [Tinyos authors’ own
words]
Simulation: Pros and Cons
29
• Advantages
• Study system in controlled environment
• Observe interactions difficult to capture live
• Helps in design improvement
• Cost effective alternative
• Disadvantages
• May not represent accurate real-world results
• Depends on modeling assumptions
TOSSIM General Concepts
30
• TOSSIM is a discrete event simulator
• It uses the same code that you use to program the sensors
• There are two programming interfaces supported: Python and
C++
Key Requirements
31
• Scalability
• Large deployments (10^3 motes)
• Completeness
• Cover as many interactions as possible
• Simulate complete applications
• Fidelity
• Capture real-world interactions
• Reveal unexpected behavior
• Bridging
• Between algorithm and implementation
Example: RadioToss
32
• Let’s simulate the RadioCountToLeds example with Tossim
• The updated code is in the folder RadioToss
• Behaviour:
• Send a BROADCAST message with a counter
• Turn on/off the LEDs according to the counter
TOSSIM Files
33
• TinyOS Project files:
• RadioTossC.nc
• RadioTossAppC.nc
• RadioToss.h
• Topology file: topology.txt
• Noise file: meyer-heavy.txt
• Simulation script: RunSimulationScript.py
Configuring a Network
34
• It’s easy to simulate large networks
• You must specify a network topology
• The default TOSSIM radio model is signal-strength based
Network Topology
35
• You can create network topologies in terms of channel gain:
Each entry in the topology is formatted as
source destination gain i.e. 1 2 -54.0
Radio Channel
36
• You need to feed a noise trace (meyer-heavy.txt file)
• The directory tos/lib/tossim/noise contains some sample
models
• On reception, SNR is evaluated for each bit of the message
Debugging Statements
37
• The output is configurable by debug channels
• <ch> identifies the output channel
• <text> text debugging and application variables
• dbg(<ch>,<text>) → DEBUG(ID):<text>
• dbg_clear(<ch>,<text>) → <text>
• dbgerror(<ch>,<text>) → ERROR(ID):<text>
• A channel can have multiple outputs
How to Run TOSSIM?
38
• To compile TOSSIM you pass the sim option to make:
make micaz sim
• To run TOSSIM use the RunSimulationScript. It must be in the
same folder of the TinyOS files
python RunSimulationScript.py
Simulation
39
• Setup Debug Channels
• Number of events: increase/decrease according to your
simulation
Attention on RunSimulationScript
40
Adapt the script for the correct number of nodes
• Add noise trace for all nodes:
• Create noise model for all nodes Range(1,n_nodes+1)
Exercise: temp/hum sensor
41
• Starting from the example in:
IOT-examples/TinyOS/Supporting Files/TempHumSensor
• Simulate with TOSSIM a TinyOS application that:
• Generate 3 motes (1, 2, 3)
• Mote #1 is the sink
• Mote #2 is the temperature sensor
• Mote #3 is the humidity sensor
Topology
42
Mote 2
Temp
Mote 3
Hum
Mote 1
Sink
Fake temp/hum sensor
43
• Mote #1 only receives messages from #2 and #3
• Mote #2 sends periodic (every 1 second) messages to the sink
(#1)
• Mote #3 sends periodic (every 2 seconds) messages to the sink
(#1)
Message format
44
• Messages are composed of the following fields:
• Type: 0 or 1 (0 for temperature, 1 for humidity)
• Data: the value of the sensor

More Related Content

Similar to 6. TinyOS_2.pdf

Splunk Conf 2014 - Getting the message
Splunk Conf 2014 - Getting the messageSplunk Conf 2014 - Getting the message
Splunk Conf 2014 - Getting the messageDamien Dallimore
 
Network-Connected Development with ZeroMQ
Network-Connected Development with ZeroMQNetwork-Connected Development with ZeroMQ
Network-Connected Development with ZeroMQICS
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementationRajan Kumar
 
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Andrea Tino
 
A Retasking Framework For Wireless Sensor Networks
A Retasking Framework For Wireless Sensor NetworksA Retasking Framework For Wireless Sensor Networks
A Retasking Framework For Wireless Sensor NetworksMichele Weigle
 
Raspberry pi Part 6
Raspberry pi Part 6Raspberry pi Part 6
Raspberry pi Part 6Techvilla
 
EKON 23 Code_review_checklist
EKON 23 Code_review_checklistEKON 23 Code_review_checklist
EKON 23 Code_review_checklistMax Kleiner
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMostafa Arjmand
 
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...Marcello Tomasini
 
Open source Tools and Frameworks for M2M - Sierra Wireless Developer Days
Open source Tools and Frameworks for M2M - Sierra Wireless Developer DaysOpen source Tools and Frameworks for M2M - Sierra Wireless Developer Days
Open source Tools and Frameworks for M2M - Sierra Wireless Developer DaysBenjamin Cabé
 

Similar to 6. TinyOS_2.pdf (20)

An Introduction to OMNeT++ 5.4
An Introduction to OMNeT++ 5.4An Introduction to OMNeT++ 5.4
An Introduction to OMNeT++ 5.4
 
Splunk Conf 2014 - Getting the message
Splunk Conf 2014 - Getting the messageSplunk Conf 2014 - Getting the message
Splunk Conf 2014 - Getting the message
 
OneTeam Media Server
OneTeam Media ServerOneTeam Media Server
OneTeam Media Server
 
GCF
GCFGCF
GCF
 
Network-Connected Development with ZeroMQ
Network-Connected Development with ZeroMQNetwork-Connected Development with ZeroMQ
Network-Connected Development with ZeroMQ
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
Tossim intro
Tossim introTossim intro
Tossim intro
 
An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1An Introduction to OMNeT++ 5.1
An Introduction to OMNeT++ 5.1
 
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
 
Intake 37 12
Intake 37 12Intake 37 12
Intake 37 12
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
 
A Retasking Framework For Wireless Sensor Networks
A Retasking Framework For Wireless Sensor NetworksA Retasking Framework For Wireless Sensor Networks
A Retasking Framework For Wireless Sensor Networks
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Raspberry pi Part 6
Raspberry pi Part 6Raspberry pi Part 6
Raspberry pi Part 6
 
EKON 23 Code_review_checklist
EKON 23 Code_review_checklistEKON 23 Code_review_checklist
EKON 23 Code_review_checklist
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
 
Monomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted DataMonomi: Practical Analytical Query Processing over Encrypted Data
Monomi: Practical Analytical Query Processing over Encrypted Data
 
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...
CSE5656 Complex Networks - Location Correlation in Human Mobility, Implementa...
 
Open source Tools and Frameworks for M2M - Sierra Wireless Developer Days
Open source Tools and Frameworks for M2M - Sierra Wireless Developer DaysOpen source Tools and Frameworks for M2M - Sierra Wireless Developer Days
Open source Tools and Frameworks for M2M - Sierra Wireless Developer Days
 

Recently uploaded

VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneCall girls in Ahmedabad High profile
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escortsindian call girls near you
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdfkeithzhangding
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 

Recently uploaded (20)

VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 

6. TinyOS_2.pdf

  • 1. Internet of Things Lab Lab 6: TinyOS (2)
  • 2. Agenda 2 • Using the Radio in TinyOS • TOSSIM simulation • Advanced Examples • Challenge 3
  • 4. General Idea 4 Fill Message Specify Destination Pass Message to OS Wait For FeedBack OS Stores Message OS signal Msg Reception Pass Message to Applications SENDER RECEIVER Read Data
  • 5. Message Buffer Abstraction 5 • In tos/types/messages.h • Header, footer, metadata: already implemented by the specific link layer • Data: handled by the application/developer typedef nx_struct message_t { nx_uint8_t header[sizeof(message_header_t)]; nx_uint8_t data[TOSH_DATA_LENGTH]; nx_uint8_t footer[sizeof(message_header_t)]; nx_uint8_t metadata[sizeof(message_metadata_t)]; } message_t;
  • 6. Message.h file 6 #ifndef FOO_H #define FOO_H typedef nx_struct FooMsg { nx_uint16_t field1; nx_uint16_t field2; …. nx_uint16_t field_N; } FooMsg; enum { FOO_OPTIONAL_CONSTANTS = 0 }; #endif
  • 7. Header and Metadata 7 typedef nx_struct cc2420_header_t { nxle_uint8_t length; nxle_uint16_t fcf; nxle_uint8_t dsn; nxle_uint16_t destpan; nxle_uint16_t dest; nxle_uint16_t src; nxle_uint8_t network; // optionally included with 6LowPAN layer nxle_uint8_t type; } cc2420_header_t; typedef nx_struct cc2420_metadata_t { nx_uint8_t tx_power; nx_uint8_t rssi; nx_uint8_t lqi; nx_bool crc; nx_bool ack; nx_uint16_t time; } cc2420_metadata_t;
  • 8. Interfaces 8 • Components above the basic data-link layer MUST always access packet fields through interfaces (in /tos/interfaces/). • Messages interfaces: • AMPacket: manipulate packets • AMSend • Receive • PacketAcknowledgements (Acks)
  • 9. Communication stack 9 • Active Message (AM) TinyOS communication technology • Include the communication protocol to send and receive packets • Each Packet is characterized by an AM Type: • Similar to a UDP port
  • 10. Communication stack 10 • message_t structure: • Packet are represented by a message_t structure • To access message_t fields is must be used Packet and AMPacket interfaces: interface Packet { command uint8_t payloadLength(message_t* msg); command void* getPayload(message_t* msg, uint8_t len); ... } interface AMPacket { command am_addr_t address(); command am_addr_t destination(message_t* amsg); ... }
  • 11. Sender Component 11 AMSenderC.nc generic configuration AMSenderC(am_id_t id) { provides { interface AMSend; interface Packet; interface AMPacket; interface PacketAcknowledgements as Acks; } }
  • 12. Receiver Component 12 AMReceiverC.nc generic configuration AMReceiverC(am_id_t id) { provides{ interface Receive; interface Packet; interface AMPacket; } }
  • 13. SplitControl Interface 13 • Radio needs to be activated prior to be used. • To turn on the radio, use the split-operation start/startDone • To turn off the radio use the split-operation stop/stopDone • ActiveMessageC create the communication stack on evry specific architecture • AMSenderC component to send messages • AMReceiverC component to receive messages
  • 14. Example 2 – RadioCountToLeds 14 Create an application that counts over a timer and broadcast the counter in a wireless packet. What do we need? • Header File: to define message structure (RadioCountToLeds.h) • Module component: to implement interfaces (RadioCountToLedsC.nc) • Configuration component: to define the program graph, and the relationship among components (RadioCountToLedsAppC.nc)
  • 15. Message Structure 15 • Message structure in RadioCountToLeds.h file typedef nx_struct radio_count_msg_t { nx_uint16_t counter; //counter value } radio_count_msg_t; enum { AM_RADIO_COUNT_MSG = 6, TIMER_PERIOD_MILLI = 250 };
  • 16. Module Component 16 1. Specify the interfaces to be used 2. Define support variables 3. Initialize and start the radio 4. Implement the core of the application 5. Implement all the events of the used interfaces
  • 17. Module Component 17 • Define the interfaces to be used: module RadioCountToLedsC { uses interface Packet; uses interface AMSend; uses interface Receive; uses interface SplitControl as AMControl; } • Define some variables: implementation { message_t packet; bool locked; ... } Control interface Packet Manipulation Interfaces Local Variables
  • 18. Initialize and Start the Radio 18 event void Boot.booted() { call AMControl.start(); } event void AMControl.startDone(error_t err) { if (err == SUCCESS) { call MilliTimer.startPeriodic(TIMER_PERIOD_MILLI ); } else { call AMControl.start(); } } event void AMControl.stopDone(error_t err) { } Events to report Interface Operation
  • 19. Implement the Application Logic 19 event void MilliTimer.fired() { ... if (!locked) { radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, sizeof(radio_count_msg_t)); rcm->counter = counter; if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_count_msg_t)) == SUCCESS) { locked= TRUE; } } } Create and set Packet Send Packet
  • 20. Implement Events of Used Interfaces 20 event void AMSend.sendDone(message_t* msg, error_t error { if (&packet == msg) { loked = FALSE; } } Must implement the events referred to all the interfaces of used components.
  • 21. What about Receiving? 21 • We need a Receive interface uses interface Receive; • We need to implement an event Receive handler event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { if (len == sizeof(radio_count_msg_t)) { radio_count_msg_t* rcm= (radio_count_msg_t*)payload; call Leds.set(rcm->counter); } return msg; } • We need to modify the configuration component implementation { ... components new AMReceiverC(AM_RADIO_COUNT_MSG); ... } implementation { ... App.Receive -> AMReceiverC; ... }
  • 22. Configuration File 22 implementation { ... components ActiveMessageC; components new AMSenderC(AM_RADIO_COUNT_MSG); ... App.Packet -> AMSenderC; App.AMSend -> AMSenderC; App.AMControl -> ActiveMessageC; ... }
  • 23. RadioCountToLeds 23 • Let’s have a look at the files (RadioCountToLeds project) • Let’s see how it works • Let’s try to turn off a device • Can you do that in Cooja?
  • 24. Message Destination 24 • AM_BROADCAST_ADDR: for broadcast messages call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_count_msg_t)) Message will be handled by all receivers • mote id: for unicast messages (e.g., 1,2 …) call AMSend.send(1, &packet, sizeof(radio_count_msg_t)) Message will be handled only by mote 1, even if other motes are in range
  • 25. Get current mote ID 25 • In some cases can be useful to get the mote ID used in the simulation • The mote ID is store in the macro TOS_NODE_ID • e.g.: Program motes with different behaviours, based on mote ID if ( TOS_NODE_ID == 1 ) { //do stuff for mote 1 } else if ( TOS_NODE_ID ==2){ // do stuff for mote 2 } else{ //stuff for other motes }
  • 26. TinyOS SIMulator Simulate a Wireless Sensor Network with TOSSIM
  • 27. Motivations 27 • WSN require large scale deployment • Located in inaccessible places • Apps are deployed only once during network lifetime • Little room to re-deploy on errors
  • 28. System Evaluation 28 • Check correctness of application behavior • Sensors are hard to debug! • “… prepare to a painful experience” [Tinyos authors’ own words]
  • 29. Simulation: Pros and Cons 29 • Advantages • Study system in controlled environment • Observe interactions difficult to capture live • Helps in design improvement • Cost effective alternative • Disadvantages • May not represent accurate real-world results • Depends on modeling assumptions
  • 30. TOSSIM General Concepts 30 • TOSSIM is a discrete event simulator • It uses the same code that you use to program the sensors • There are two programming interfaces supported: Python and C++
  • 31. Key Requirements 31 • Scalability • Large deployments (10^3 motes) • Completeness • Cover as many interactions as possible • Simulate complete applications • Fidelity • Capture real-world interactions • Reveal unexpected behavior • Bridging • Between algorithm and implementation
  • 32. Example: RadioToss 32 • Let’s simulate the RadioCountToLeds example with Tossim • The updated code is in the folder RadioToss • Behaviour: • Send a BROADCAST message with a counter • Turn on/off the LEDs according to the counter
  • 33. TOSSIM Files 33 • TinyOS Project files: • RadioTossC.nc • RadioTossAppC.nc • RadioToss.h • Topology file: topology.txt • Noise file: meyer-heavy.txt • Simulation script: RunSimulationScript.py
  • 34. Configuring a Network 34 • It’s easy to simulate large networks • You must specify a network topology • The default TOSSIM radio model is signal-strength based
  • 35. Network Topology 35 • You can create network topologies in terms of channel gain: Each entry in the topology is formatted as source destination gain i.e. 1 2 -54.0
  • 36. Radio Channel 36 • You need to feed a noise trace (meyer-heavy.txt file) • The directory tos/lib/tossim/noise contains some sample models • On reception, SNR is evaluated for each bit of the message
  • 37. Debugging Statements 37 • The output is configurable by debug channels • <ch> identifies the output channel • <text> text debugging and application variables • dbg(<ch>,<text>) → DEBUG(ID):<text> • dbg_clear(<ch>,<text>) → <text> • dbgerror(<ch>,<text>) → ERROR(ID):<text> • A channel can have multiple outputs
  • 38. How to Run TOSSIM? 38 • To compile TOSSIM you pass the sim option to make: make micaz sim • To run TOSSIM use the RunSimulationScript. It must be in the same folder of the TinyOS files python RunSimulationScript.py
  • 39. Simulation 39 • Setup Debug Channels • Number of events: increase/decrease according to your simulation
  • 40. Attention on RunSimulationScript 40 Adapt the script for the correct number of nodes • Add noise trace for all nodes: • Create noise model for all nodes Range(1,n_nodes+1)
  • 41. Exercise: temp/hum sensor 41 • Starting from the example in: IOT-examples/TinyOS/Supporting Files/TempHumSensor • Simulate with TOSSIM a TinyOS application that: • Generate 3 motes (1, 2, 3) • Mote #1 is the sink • Mote #2 is the temperature sensor • Mote #3 is the humidity sensor
  • 43. Fake temp/hum sensor 43 • Mote #1 only receives messages from #2 and #3 • Mote #2 sends periodic (every 1 second) messages to the sink (#1) • Mote #3 sends periodic (every 2 seconds) messages to the sink (#1)
  • 44. Message format 44 • Messages are composed of the following fields: • Type: 0 or 1 (0 for temperature, 1 for humidity) • Data: the value of the sensor