Introduction to SENSEnuts programming
Submitted by:
Debayan Das Indranil Roy Soubir Bhakta
ECE2012053 ECE2012002 ECE2012043
Under the Guidance of:
Prof. Bhargab B. Bhattacharya Advanced Computing and Microelectronics Unit,
Indian Statistical Institute, Kolkata
DECLARATION
I, Indranil Roy, of roll number ECE2012002, studying in the seventh semester of
Bachelor of Technology in Electronics and Communication Engineering at RCC Institute of
Information Technology, Kolkata, hereby declare that this project work entitled “Study of
the attributes of Wireless Sensor Devices” which is being submitted by me in the partial
fulfilment for the award of the degree of Bachelor of Technology in Electronics and
Communication Engineering, from Indian Statistical Institute, Kolkata is an authentic record
of me carried out during the academic year 2014-2015, under the guidance of Prof. Bhargab
B. Bhattacharya, Professor of Computer Science and Engineering, Advanced Computing
and Microelectronics Unit, Indian Statistical Institute, Kolkata.
I further undertake that the matter embodied in the dissertation has not been submitted
previously for the award of any degree or diploma by me to any other university or
institution.
Place: INDIAN STATISITICAL INSTITUTE
Student Name: Indranil Roy
Date: 10.07.2015
ACKNOWLEDGEMENT
It is our proud privilege and duty to acknowledge the kind of help and guidance
received from several people in preparation of this report. It would not have been possible to
prepare this report in this form without their valuable help, cooperation and guidance.
First and foremost, we wish to record our sincere gratitude to Indian Statistical
Institute and to Prof. Bhargab B. Bhattacharya, Advanced Computing and
Microelectronics Unit, Indian Statistical Institute, Kolkata, for his constant support and
encouragement in preparation of this report and for making available library and laboratory
facilities needed to prepare this report. Our sincere thanks to Prof. Nabanita Das, Advanced
Computing and Microelectronics Unit, Indian Statistical Institute, Kolkata, for her valuable
suggestions and guidance throughout the period of this work. We express our sincere
gratitude to our guide, Mr. Dibakar Saha, Advanced Computing and Microelectronics Unit,
ISI, Kolkata for guiding us in investigations for this work and in carrying out experimental
studies. Our numerous discussions with him were extremely helpful. We hold him in esteem
for guidance, encouragement and inspiration received from him. Our sincere thanks to Mr.
Avirup Das, Radio physics and Electronics Department, University of Calcutta, for being the
apt Project Coordinator and having supported the work related to this project. His
contributions and technical support in preparing this report is greatly acknowledged.
Last but not the least, we wish to thank our parents for constantly encouraging us to learn
engineering. Their personal sacrifice in providing this opportunity to learn engineering is
gratefully acknowledged.
Place: INDIAN STATISTICAL INSTITUTE Name: INDRANIL ROY
1. INTRODUCTION
The following is a report on the experiments performed and observed on Wireless Sensor
Nodes at the Advanced Computing and Microelectronics Unit (ACMU) at the Indian
Statistical Institute (ISI).
1.1 Wireless Sensor Network:
• A wireless sensor network is a group of specialized transducers with a
communications infrastructure for monitoring and recording conditions at diverse
locations. Commonly monitored parameters are temperature, light intensity, humidity,
pressure, wind direction and speed, vibration intensity, sound intensity, power-line
voltage, chemical concentrations, pollutant levels and vital body functions.
• The WSN is built of "nodes" – from a few to several hundreds or even thousands,
where each node is connected to one (or sometimes several) sensors. Each such sensor
network node has typically several parts: a radio transceiver with an
internal antenna or connection to an external antenna, a microcontroller, an electronic
circuit for interfacing with the sensors and an energy source, usually a battery or an
embedded form of energy harvesting.
• The topology of the WSNs can vary from a simple star network to an advanced multi-
hop wireless mesh network. The propagation technique between the hops of the
network can be routing or flooding.
Typical multi-hop wireless sensor network architecture
1.2 Zigbee Technology:
• ZigBee is a wireless networking standard that is aimed at remote control and sensor
applications which is suitable for operation in harsh radio environments and in
isolated locations.
• ZigBee technology builds on IEEE standard 802.15.4 which defines the physical and
MAC layers. Above this, ZigBee defines the application and security layer
specifications enabling interoperability between products from different
manufacturers. In this way ZigBee is a superset of the 802.15.4 specification.
• The distances that can be achieved transmitting from one station to the next extend up
to about 70 metres, although very much greater distances may be reached by relaying
data from one node to the next in a network.
• The main applications for 802.15.4 are aimed at control and monitoring applications
where relatively low levels of data throughput are needed, and with the possibility of
remote, battery powered sensors, low power consumption is a key requirement.
Sensors, lighting controls, security and many more applications are all candidates for
the new technology.
Zigbee Network Model
2. PRELIMINARIES
2.1 SENSEnuts Software developed by Eigen Technologies Pvt. Ltd.
SENSENuts is basically a WSN research platform developed by Industry Experts. This
platform is useful for academic, research and industrial applications, to benefit student,
faculties and scientists across various domains. Supported by user friendly GUI, it
seamlessly integrates with different kinds of sensor nodes.
The following are its various features:
• Wireless micro-controller with 802.15.4 transceiver
1. 2-bit RISC CPU with up to 32MIPs (low power)
2. 32KB RAM
3. 4KB EEPROM
4. 256KB Flash memory
5. Max TX power +2.5dBm
6. Receiver sensitivity –95dBm.
• Self Healing Multi-hop Mesh Network
• C Based Programming
• Easy to use GUI
• Range of Sensors
• Good Documentation
2.2 Steps to Install, Build and Run a Project in SENSEnuts-
• The installation is pretty easy. The Installation Wizard guides us through each step of
installation.
• We first enter the path specified as “C:\sensenuts\2.0.2\AppCode” where the various
demo codes are present.
• We choose our desired code or make our own, with the help of the „API Reference
Guide‟ in the „docs‟ folder that lists the pre-defined functions of the SENSENuts
software elaborately and then save our code in the path under the desired name, say
“Abcd”.
• We create two folders in Abcd, namely „output‟ and „source‟ as well as a file named
„Makefile‟.
• The „output‟ folder will be empty and the „source‟ folder will contain our source code
„Abcd‟ in .c file format.
• In the „Makefile‟ file, the source file and target needs to be modified into “Abcd.c”
and the required Target name, while the DIRS will point to the path location of the
file, generally given as DIRS= "../../../Lib"
• After we have performed the above steps, we can build our Project using either of the
two processes, using Eclipse or Command Prompt.
• Using Eclipse, we need to do the following:
• We select File -> New -> Makefile Project with Existing Code.
• We select the required folder in which our code is kept. The folder
must have the „Makefile‟ file in the folder.
• Clean the Existing Project
• Build the Existing Project
• In order to set the path, we perform the following steps:
• We copy the path that has been displayed in the Console tab.
• We click on the "Advanced System Settings" of the computer and set
the path as the one we copied.We save the changes as necessary.
• Using Command Prompt, we need to do the following:
• Delete .cproject and .project inside the “Abcd” folder
• Delete all the files inside the output folder
• Open cmd, and change directory to
“C:\sensenuts\2.0.2\AppCode\Abcd”
• We build the project using just the keyword „make‟
• Now a .bin file will be created inside the „output‟ folder, which we require.
• We open up „sensenutsGUI‟ which will then determine the Mac address once we
connect a particular sensor and then burn the code on to it.
• Now our sensor is ready to give the desired output as per the requirements of the
code.
2.3 Basic Codes in SENSEnuts:
The following is a list of some basic codes in SENSEnuts.
2.3.1 SENSEnuts Code for Neighbour List:
This code will basically create a list of the node Ids and the other co-ordinators within the
range of the pan co-ordinator, which will broadcast the message.
Neighbour List Code for the Pan Co-ordinator:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
struct nT{
uint16 nodeId;
uint8 linkQuality;
}neighbourEntry[30];
int index=0;
/*******************************Do not modify above this
line********************************/
//add header for communication with PC
#include "sendToPc.h"
//add header files for mac layer APIs
#include "mac.h"
#include "dio.h"
//user defined packet type should always be greater than 0x23 as routing protocols
//define their packet types below this value.
#define NEIGHBOUR_UPDATE_PACKET 0x30
#define ACKNOWLEDGEMENT 0x31
#define SEND_TO_PC_TIMER 0
void startNode()
{
//initialize uart
sendToPcInit();
//initialize mac layer
macInit();
}
void userTaskHandler(uint8 taskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16 prevAddr,uint8 linkQuality)
{
//receive packet from neighbouring node and update neighbour table
uint16 nodeId;
if (payload[0]==NEIGHBOUR_UPDATE_PACKET)
{
nodeId=payload[1];
nodeId= (nodeId<<8)|payload[2];
if (index<30)
{
neighbourEntry[index].nodeId=nodeId;
neighbourEntry[index].linkQuality=linkQuality;
index++;
uint8 packet[3];
packet[0]=nodeId>>8;
packet[1]=nodeId;
packet[2]=linkQuality;
debug(packet,3);
}
//send an acknowledgement (not suggested in broadcast - just for checking
purposes)
uint8 ack[1];
ack[0]=ACKNOWLEDGEMENT;
uint8 check=0;
check=sendDataToMac(ack,1,prevAddr,0,FALSE); //16 bit broadcast address
with no ack req. Mac ack should be disabled
//when broadcast is done.
if (check==FALSE)
{
/*do something to let user know that broadcast failed as the
node is not associated with any pan coordinator right now */
}
}
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
Neighbour List Code for the Co-ordinator:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header files for temperature and light sensors
#include "tmpSensor.h"
#include "lightSensor.h"
#include "dio.h"
//add header files for mac layer APIs
#include "mac.h"
#include "sendToPc.h"
extern uint8 rx[127];
//task type
#define SEND_PACKET_TO_MAC 0x08
//user defined packet type should always be greater than 0x23 as routing protocols
#define NEIGHBOUR_UPDATE_PACKET 0x30
#define ACKNOWLEDGEMENT 0x31
void startNode()
{
sendToPcInit();
//initialize sensors
tmpInit();
lightSensorInit();
//initialize mac layer
macInit();
/*set task to read sensor info and send the data to mac. If
the coordinator has already associated, it will broadcast
this packet or else it will drop the packet.*/
//addTask(USER,SEND_PACKET_TO_MAC,1*SECOND);
addTask(USER,SEND_PACKET_TO_MAC,5*SECOND);
}
void userTaskHandler(uint8 taskType)
{
uint8 packet[3];
uint16 nodeId=getNodeId();
bool check=0;
packet[0]=NEIGHBOUR_UPDATE_PACKET;
packet[1]=nodeId>>8;
packet[2]=nodeId;
check=sendDataToMac(packet,3,0xFFFF,0,FALSE);
//16 bit broadcast address with no ack req. Mac ack should be disabled
//when broadcast is done.
if (check==FALSE)
{
/*do something to let user know that broadcast failed as the
node is not associated with any pan coordinator right now */
}
addTask(USER,SEND_PACKET_TO_MAC,5*SECOND);
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16 prevAddr,uint8
linkQuality)
{
ledOn();
//when the node receives an ack, switch on the led.
if (payload[0]==ACKNOWLEDGEMENT)
{
ledOn();
}
}
2..4 Introduction to the Demo Codes:
2.4.1 Demo code 4:
This code introduces the Mac Base Routing in a multi-hop fashion. Low level
Ethernet and MAC addresses can only reach every device on the same network
(cabled or wireless). If we have two networks with a router in between, we cannot
have a device in network .Á‟ sends a packet to the MAC address of a device in
network B. No device in network A has the MAC address of the device in network B,
so a packet to this MAC address will be discarded by all devices in the network A
(also by the router).
Routing is done on IP level. The router will receive packets for its own MAC address
but for a different IP address. He will then check if he can directly reach the target IP
address. If so, he sends the packet to the target. Otherwise the router itself also has an
upstream router configured and will send the packet to that router. The routing based
on the above concept is called Mac Base Routing.
By multi-hop we mean to say that a suppose a pan-coordinator is not in the
transmission range or sensing range of a coordinator then the coordinator will send
the data packet to the nearest coordinator and then if possible then it sends the data
packet to the pan-coordinator otherwise the process continues.
There are mainly two codes:
multihop_mbr_Coord
multihop_mbr_panCoord
multihop_mbr_Coord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task1.h"
/*******************************Do not modify above this
line********************************/
//add header files for temperature and light sensors
#include "tmpSensor.h"
#include "lightSensor.h"
//add header files for mac layer APIs
#include "mac.h"
//add header file for routing APIs
#include "routing.h"
//task type
#define SEND_PACKET_TO_MAC 0
//user defined packet type should always be greater than 0x23 as routing
protocols
//define their packet types below this value.
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize sensors
tmpInit();
lightSensorInit();
//initialize mac layer
macInit();
//initialize routing
routingInit();
/*set task to read sensor info and send the data to mac. If
the coordinator has already associated, it will broadcast
this packet or else it will drop the packet.*/
addTask(USER,SEND_PACKET_TO_MAC);
}
void userTaskHandler(uint8 taskType)
{
uint8 packet[6],tmp;
uint16 light;
uint16nodeId=getNodeId();
int8 check;
//read sensor values
tmp=readTmp();
light=readLux();
packet[0]=USER_PACKET_TYPE; //packet type info
packet[1]=tmp; //temperature
packet[2]=light>>8; //light info
packet[3]=light;
packet[4]=nodeId>>8; //source address
packet[5]=nodeId;
check=routingSendData(packet, 6, 0); //0 is the destination address
if (check<=0)
{
//packet is dropped
}
addTask(USER,SEND_PACKET_TO_MAC);
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to the
API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit, sendToPcInit,
macInit, routingInit. After that a task to send data after 1 second is added.
Then on expiry, we read data and check if route to destination is available or
not. If available then it is sent towards destination, if not, route discovery may
be triggered. To make it periodic, a new task is added to be executed after 1
sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType). In
this function we are handling the task added by the user when the timer for that
particular task defined in addTask expires. taskType must be defined in the
application. In this function we have declare an array called the packet through
which we are going to send the data. The temperature values are read by using
the readTemp(), similarly the light intensity(in Lux) is read by readLux().
Since the light intensity is of a uint16 data type, we are breaking the 16 bit data
into two 8 bit data by using the right shift operator. Similarly the node Id is
also stored in the array packet. Then we send the data by using the
routingSendData(packet, 6, 0) function. Then we are checking whether the
routing is possible or not, if it is not possible then the packet is dropped else it
is send to the mac layer.then again the
addTask(USER,SEND_PACKET_TO_MAC) is called.
multihop_mbr_panCoord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header file for communication with PC
#include "sendToPc.h"
//add header file for mac layer APIs
#include "mac.h"
//add header file for routing
#include "routing.h"
/*user defined packet type should always be greater than 0x23 as routing
protocols
define their packet types below this value.*/
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize uart
sendToPcInit();
//initialize mac layer
macInit();
}
void userTaskHandler(uint8 taskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
uint8 tmp;
uint16 light;
uint16 nodeId;
if (payload[0]==USER_PACKET_TYPE)
{
tmp=payload[1];
light=payload[2];
light=light<<8;
light=light | payload[3];
nodeId=payload[4];
nodeId=nodeId<<8;
nodeId=nodeId|payload[5];
//update info in database present in PC
updateAmbientdb(nodeId,light,tmp);
}
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to the
API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit, sendToPcInit,
macInit, routingInit. After that a task to send data after 1 second is added.
Then on expiry, we read data and check if route to destination is available or
not. If available then it is sent towards destination, if not, route discovery may
be triggered. To make it periodic, a new task is added to be executed after 1
sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType). In
this function we are handling the task added by the user when the timer for that
particular task defined in addTask expires. taskType must be defined in the
application. In this function we have declare an array called the payload in
which we are going to receive the data. Then we are checking whether the data
is send by the user or not by if (payload[0]==USER_PACKET_TYPE). The
data received are being stored in the payload array. Since the light intensity
and the node Id are of 16 bit each, they are received as two 8 bits data, then
they are stored by doing an OR operation. Then the data is updated in the pc to
which the pan coordinator is connected.
2.4.2 Demo Code 5:
This code is based on the Level Base Routing ina multi hop fashion. A level based
routing approach for a wireless sensor network is in which the nodes in the network are
divided into several levels according to their hops to sink node. Every sensor node has a
level number. Using level information, a sensor node can send messages to a sink node
in a more efficient way, and a sink node can easily locate other sensor nodes.
There are mainly two codes:
multihop_lbr_Coord
multihop_lbr_panCoord
multihop_lbr_Coord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header files for temperature and light sensors
#include "tmpSensor.h"
#include "lightSensor.h"
//add header files for mac layer APIs
#include "mac.h"
//add header file for routing APIs
#include "routing.h"
//task type
#define SEND_PACKET_TO_MAC 0
//user defined packet type should always be greater than 0x23 as routing
protocols
//define their packet types below this value.
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize sensors
tmpInit();
lightSensorInit();
//initialize mac layer
macInit();
//initialize routing
routingInit();
/*set task to read sensor info and send the data to mac. If
the coordinator has already associated, it will broadcast
this packet or else it will drop the packet.*/
addTask(USER,SEND_PACKET_TO_MAC,1*SECOND);
}
void userTaskHandler(uint8 taskType)
{
uint8 packet[6],tmp;
uint16 light;
uint16 nodeId=getNodeId();
int8 check;
//read sensor values
tmp=readTmp();
light=readLux();
packet[0]=USER_PACKET_TYPE; //packet type info
packet[1]=tmp; //temperature
packet[2]=light>>8; //light info
packet[3]=light;
packet[4]=nodeId>>8; //source address
packet[5]=nodeId;
check=routingSendData(packet, 6, 0); //0 is the destination address
if (check<=0)
{
//packet is dropped
}
addTask(USER,SEND_PACKET_TO_MAC,1*SECOND);
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to the
API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit, sendToPcInit,
macInit, routingInit. After that a task to send data after 1 second is added.
Then on expiry, we read data and check if route to destination is available or
not. If available then it is sent towards destination, if not, route discovery may
be triggered. To make it periodic, a new task is added to be executed after 1
sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType). In
this function we are handling the task added by the user when the timer for that
particular task defined in addTask expires. taskType must be defined in the
application. In this function we have declare an array called the payload in
which we are going to receive the data. Then we are checking whether the data
is send by the user or not by if (payload[0]==USER_PACKET_TYPE). The
data received are being stored in the payload array. Since the light intensity
and the node Id are of 16 bit each, they are received as two 8 bits data, then
they are stored by doing an OR operation. Then the data is updated in the pc to
which the pan coordinator is connected.
multihop_lbr_panCoord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header file for communication with PC
#include "sendToPc.h"
//add header file for mac layer APIs
#include "mac.h"
//add header file for routing
#include "routing.h"
/*user defined packet type should always be greater than 0x23 as routing
protocols
define their packet types below this value.*/
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize uart
sendToPcInit();
//initialize mac layer
macInit();
}
void userTaskHandler(uint8 taskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
uint8 tmp;
uint16 light;
uint16 nodeId;
if (payload[0]==USER_PACKET_TYPE)
{
tmp=payload[1];
light=payload[2];
light=light<<8;
light=light | payload[3];
nodeId=payload[4];
nodeId=nodeId<<8;
nodeId=nodeId|payload[5];
//update info in database present in PC
updateAmbientdb(nodeId,light,tmp);
}
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to
the API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit,sendToPcInit,
macInit, routingInit. After that a task to send data after 1 second is added.
Then on expiry, we read data and check if route to destination is available or
not. If available then it is sent towards destination, if not, route discovery
may be triggered. To make it periodic, a new task is added to be executed
after 1 sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType).
In this function we are handling the task added by the user when the timer for
that particular task defined in addTask expires. taskType must be defined in
the application. In this function we have declare an array called the payload
in which we are going to receive the data. Then we are checking whether the
data is send by the user or not by if (payload[0]==USER_PACKET_TYPE).
The data received are being stored in the payload array. Since the light
intensity and the node Id are of 16 bit each, they are received as two 8 bits
data, then they are stored by doing an OR operation. Then the data is updated
in the pc to which the pan coordinator is connected.
2.4.3 Demo code 6:
This code is based on AODV (Ad-Hoc On-Demand Distance Vector) in a multi hop manner.
The AODV routing protocol is a reactive routing protocol that uses some characteristics of
proactive routing protocols. Routes are established on-demand, as they are needed. However,
once established a route is maintained as long as it is needed. Reactive (or on-demand)
routing protocols find a path between the source and the destination only when the path is
needed (i.e., if there are data to be exchanged between the source and the destination). An
advantage of this approach is that the routing overhead is greatly reduced. A disadvantage is a
possible large delay from the moment the route is needed (a packet is ready to be sent) until
the time the route is actually acquired. In AODV, the network is silent until a connection is
needed. At that point the network node that needs a connection broadcasts a request for
connection. Other AODV nodes forward this message, and record the node that they heard it
from, creating an explosion of temporary routes back to the needy node. When a node
receives such a message and already has a route to the desired node, it sends a message
backwards through a temporary route to the requesting node. The needy node then begins
using the route that has the least number of hops through other nodes. Unused entries in the
routing tables are recycled after a time. When a link fails, a routing error is passed back to a
transmitting node, and the process repeats. Much of the complexity of the protocol is to lower
the number of messages to conserve the capacity of the network. For example, each request
for a route has a sequence number. Nodes use this sequence number so that they do not repeat
route requests that they have already passed on. Another such feature is that the route
requests have a "time to live" number that limits how many times they can be retransmitted.
Another such feature is that if a route request fails, another route request may not be sent until
twice as much time has passed as the timeout of the previous route request. The advantage of
AODV is that it creates no extra traffic for communication along existing links. Also,
distance vector routing is simple, and doesn't require much memory or calculation. However
AODV requires more time to establish a connection, and the initial communication to
establish a route is heavier than some other approaches.
There are mainly two codes:
multihop_aodv_Coord
multihop_aodv_panCoord
multihop_aodv_Coord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header files for temperature and light sensors
#include "tmpSensor.h"
#include "lightSensor.h"
//add header files for mac layer APIs
#include "mac.h"
//add header file for routing APIs
#include "routing.h"
//task type
#define SEND_PACKET_TO_MAC 0
//user defined packet type should always be greater than 0x23 as routing
protocols
//define their packet types below this value.
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize sensors
tmpInit();
lightSensorInit();
//initialize mac layer
macInit();
//initialize routing
routingInit();
sendToPcInit();
/*set task to read sensor info and send the data to mac. If
the coordinator has already associated, it will broadcast
this packet or else it will drop the packet.*/
addTask(USER,SEND_PACKET_TO_MAC,5*SECOND);
}
void userTaskHandler(uint8 taskType)
{
uint8 packet[6],tmp;
uint16 light;
uint16 nodeId=getNodeId();
int8 check;
uint16 destAddr=0; //put the 16 bit address of
destination to which data is to be sent here
//read sensor values
tmp=readTmp();
light=readLux();
packet[0]=USER_PACKET_TYPE; //packet type info
packet[1]=tmp; //temperature
packet[2]=light>>8; //light info
packet[3]=light;
packet[4]=nodeId>>8; //source address
packet[5]=nodeId;
check=routingSendData(packet, 6, destAddr);
if (check<=0)
{
//packet is dropped
}
addTask(USER,SEND_PACKET_TO_MAC,1*SECOND);
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
}
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to the
API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit, sendToPcInit,
macInit, routingInit. After that a task to send data after 1 second is added.
Then on expiry, we read data and check if route to destination is available or
not. If available then it is sent towards destination, if not, route discovery may
be triggered. To make it periodic, a new task is added to be executed after 1
sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType).
In this function we are handling the task added by the user when the timer for
that particular task defined in addTask expires. taskType must be defined in
the application. In this function we have declare an array called the payload in
which we are going to receive the data. Then we are checking whether the data
is send by the user or not by if (payload[0]==USER_PACKET_TYPE). The
data received are being stored in the payload array. Since the light intensity
and the node Id are of 16 bit each, they are received as two 8 bits data, then
they are stored by doing an OR operation. Then the data is updated in the pc to
which the pan coordinator is connected.
multihop_aodv_panCoord
Code:
/*All rights reserved.
*
* Eigen Technologies Pvt. Ltd.
* New Delhi
* www.eigen.in
*
* This source code is provided to SensenutsTM users for
* research purpose only. No portion of this source code
* may be used as the basis of development of any similar
* kind of product.
*
*/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include "clock.h" //provides clock related functionality
#include "node.h"
#include "task.h"
/*******************************Do not modify above this
line********************************/
//add header file for communication with PC
#include "sendToPc.h"
//add header file for mac layer APIs
#include "mac.h"
//add header file for routing
#include "routing.h"
/*user defined packet type should always be greater than 0x23 as routing
protocols
define their packet types below this value.*/
#define USER_PACKET_TYPE 0x30
void startNode()
{
//initialize uart
sendToPcInit();
//initialize mac layer
macInit();
}
void userTaskHandler(uint8 taskType)
{
}
void userReceiveDataPacket(uint8* payload,uint8 length,uint16
prevAddr,uint8 linkQuality)
{
uint8 tmp;
uint16 light;
uint16 nodeId;
if (payload[0]==USER_PACKET_TYPE)
{
tmp=payload[1];
light=payload[2];
light=light<<8;
light=light | payload[3];
nodeId=payload[4];
nodeId=nodeId<<8;
nodeId=nodeId|payload[5];
//update info in database present in PC
updateAmbientdb(nodeId,light,tmp);
}
}
void userCriticalTaskHandler(uint8 critTaskType)
{
}
Explanation of the code:
1. At first we have to include the respective header files. We have referred to
the API reference guide and have added the header files.
2. First, we initialize modules used using tmpInit, lightSensorInit,
sendToPcInit, macInit, routingInit. After that a task to send data after 1
second is added. Then on expiry, we read data and check if route to
destination is available or not. If available then it is sent towards destination,
if not, route discovery may be triggered. To make it periodic, a new task is
added to be executed after 1 sec.
3. Next we have declared the function void userTaskHandler(uint8 taskType).
In this function we are handling the task added by the user when the timer for
that particular task defined in addTask expires. taskType must be defined in
the application. In this function we have declare an array called the payload
in which we are going to receive the data. Then we are checking whether the
data is send by the user or not by if (payload[0]==USER_PACKET_TYPE).
The data received are being stored in the payload array. Since the light
intensity and the node Id are of 16 bit each, they are received as two 8 bits
data, then they are stored by doing an OR operation. Then the data is updated
in the pc to which the pan coordinator is connected.
2.5 Various SENSEnuts Functions used in the code:
1. ledOff()
- Turns off the LED on the sensor.
2. ledOn()
- Turns on the LED on the sensor.
3. macInit()
- Initializes the MAC layer of the sensor nodes.
4. sendDataToMac(uint8 *data, uint8 len, uint16 destAddr,bool isAckReq)
- It sends the data from one node to the MAC layer of the node with the
destination address passed within the parameters of the method.
5. setTransmitPower(int32 powerLevel)
- To set the transmission power of the Transceiver. Available options are
0x00,0x40, 0x80, 0X3F, 0X5F, 0XBF, 0X33, 0X53,0XB3, 0X20, 0X60, 0XA0.
0x80 being the default transmission level.
6. setCcaMode(uint8 ccaMode)
- Selects the CCA mode. Available options are 0X01, 0X10, 0X11. We can
choose from either of the options mentioned above according to our needs.
7. routingInit()
- Initializes the routing protocol of the zigbee network.
8. routingSendData(uint8 *data,uint8 len, uint16 destAddr)
- The data passed within the parameters is send via the routing protocol to the
destination address mentioned.
9. userReceiveDataPacket(uint8* payload,uint8 length,uint16 prevAddr,uint8
linkQuality)
- When a node receives a data packet it does all the working within this method.
10. lightSensorInit()
- Initializes the light sensor.
11. readLux(void)
- Returns the light intensity with units in “lux”.
12. setLightThreshold(uint16 high, uint16 low)
- Set the upper and lower threshold of light sensor. Causes the microcontroller to
generate an interrupt when the light intensity goes above “high” or below “low”.
13. tmpInit()
– Initializes the temperature sensor.
14. readTmp()
- Read the temperature reading from the sensor.
15. setTmpThreshold(uint8 high,uint8 low)
- Sets the upper and lower thresholds of the temperature sensor to generate an
interrupt when the temperature goes above “high” value in degree Celsius. An
interrupt is generated again when the temperature falls below “low” degree
Celsius.
16. addTask(uint8 taskAdder,uint8 taskType,uint32 time)
- Adds task in the queue. For user defined tasks, “taskAdder” should be set to
“USER” and the type of task is defined by taskType. The time after which the task
is to be executed is defined by “time” in Milliseconds. This function repeatedly
adds the task within the program.
17. userTaskHandler(uint8 taskType)
- Handles the task added by the user when the timer for that particular task defined
in addTask expires. taskType must be defined in the application.
18. userCriticalTaskHandler(uint8 critTaskType)
- Handles the critical tasks, whenever there is an interrupt from a critical device
19. routingTaskHandler(uint8 taskType)
- Handles the routing tasks.
20. userReceiveDataPacket(uint8* payload,uint8 length,uint16 prevAddr,uint8
linkQuality)
- Handles the received packet task whenever a packet is received by the mote.
*payload is the pointer to the location where the incoming data of length “length”
from nodeID “prevAddr” and link quality “linkQuality” is received.
21. sendToPcInit()
- Initializes the communication between a computer and the node connected to the
computer via USB cable with the help of Gateway Module.
22. updateAmbientdb(uint16 nodeId,uint16 light,uint8 temperature)
- Updates the database of temperature(uint8) and light (uint16) senor with the
readings received from the node specified by “nodeId” as well as display any 3
parameters of our choice.
23. updateAmbientdbf(uint16 nodeId,uint16 light,uint16 temperature)
- Updates the database of temperature(uint16) and light (uint16) senor with the
readings received from the node specified by “nodeId” as well as display any 3
parameters of our choice. The temperature can now be displayed up to 4
significant digits.
24. debug(uint8* string, uint8 length)
-Prints the message on “Print Window”, pointed by “string” and Note that the
maximum allowed size of the string is 224 bytes.
25. getNodeId()
-Returns the ID of the node on which the call is being made. It is extracted from
the MAC address of the node (basically the two least significant bytes.
26. startNode()
- It is the first function, just like “void main()” in C which is called on boot.
3. SIMULATION STUDIES
A particular sensory node has two different types of range namely sensory range and
transmission range.
3.1.1 Sensory Range:
Sensory range of a node is the maximum range over which an information can be
sensed from any other node in a single hop. The sensory range of a node mainly
depends upon the battery life of the node, the light intensity of the source and the
physical conditions such as external light, temperature and others. It is thus important
to know the exact range over which the co-ordinators can sense any external factors,
and thus have to place the nodes in such a manner that the maximum area can be
covered.
3.1.2 Transmission Range:
Transmission range of a node is the maximum range over which an information can
be sent or received from any other node in a single hop. The transmission range of a
node also depends upon the battery life of the node, but not on the light intensity of
the source and nor the physical conditions such as external light, temperature and
others.
3.2 Defining the Sensory Range of a Sensor using SENSEnuts:
We used the predefined code in ‘demo3’ to determine the Sensory Range of the
sensors. The Experimental Setup and Calculations for Determination of Sensory Range of
the Sensors are as given below-
We divided an entire table into equal parts of 10cm intervals each with a least count
of 2cm.
We placed one light source at the 0 position and then moved the sensor gradually
from 0 to a larger distance and recorded the observations generated at the PAN-
Coordinator in a tabular format.
The readings were taken as Distance (cm) vs. Light Intensity (Lux) in the x vs. y plane.
More than 5 readings were taken, at different intensities and times of the day.
On the plotting of the data, it was observed that we get an exponentially decaying
curve, with the intensity decreasing exponentially with increasing distance.
On performing some mathematical calculations, it was observed that the relation
could be given as:
N(d) = N(0).exp((-lambda).d)
where,
N(d) = Light Intensity in Lux at Distance(d) in centimetres.
N(0)= Light Intensity in Lux at Distance = 0 centimetres.
exp= 2.71828 (also known as the Euler‟s Number)
Lambda = 0.09
d = distance in centimetres.
The value of lambda can be calculated by finding the value of 1/d,
where d is the distance when the light intensity is N(0)/e.
On performing the above given calculations, we obtain the value of lambda to be about 0.09
(approximately close to that). Please Note - The value of lambda is adjusted from time to
time while reading the data so as to achieve the perfect curve. It was seen that at about 0.09,
we can achieve the best fit curve.
On plotting these values using Graphs and MATLAB, we obtained some curves and data
from the observations and made a graphical analysis.
The table of observations and the graphical representation is as follows.
3.2.1 Observation Table:
Distance (in centimetres) Light Intensity ( in Lux) 0 1562
2 1504
4 1320
6 1061
8 822
10 617
12 502
14 399
16 337
18 262
20 213
22 178
24 153
26 130
28 113
30 99
40 56
50 36
60 27
70 21
80 18
90 16
100 14.25
110 13
120 12.5
130 11.75
140 11.75
150 10.75
3.2.2 MATLAB Code (for the generation of Experimental as well as
Equation Values):
d=0:10:150;
li=[1562 1504 1320 1061 822 617 502 399 337 262 213 178 153 130 113 99 56 36 27 21 18
16 14.25 13 12.5 11.75 11.75 10.75]
d=[0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 40 50 60 70 80 90 100 110 120 130 140 150]
plot(d,li)
y=1562*exp(-0.09*d)
hold on;,
plot(d,y,'r')
xlabel('Distance (in centimetres)');
ylabel('Light Intensity (in Lux)');
title('Comparative Study of Sensory Curve of the Sensors')
Thus, we can observe that the Experimental as well as the values obtained from the Equations
are of almost approximately the same cure and thus we can strongly conclude that the given
equation –
N(d) = N(0).exp((-lambda).d)
can be used to determine the values of the distance and light intensity of the sensors properly.
3.3 Setting the Transmission Range of a Sensor using SENSEnuts:
The Transmission and Sensory Range of the Sensors are distinctively different as illustrated
in the given diagram. In case of the co-ordinator sensors, multi-hop mode of propagation is
used where one node transmits the information to another node and so on till it ultimately
reaches the final Personal Area Network or PAN Co-ordinator that will be connected to our
computer.
• SENSEnuts provides us with various transmission levels for transmission of power at
various levels.
• By changing the transmission level power in the config.h file, we were able to obtain
the various power levels for transmission.
• SENSEnuts supports 4 different transmission power levels with 3 different
Tolerance levels (1db, 3db, 6db). Accordingly following macros are available
For +2.5 dbm
PHY_2.5dbm_1DB_TOLERANCE 0x00
PHY_2.5dbm_3DB_TOLERANCE 0x40
PHY_2.5dbm_6DB_TOLERANCE 0x80 (default)
For -9 dbm
PHY_-9dbm_1DB_TOLERANCE 0x3F
PHY_-9dbm_3DB_TOLERANCE 0x5F
PHY_-9dbm_6DB_TOLERANCE 0xBF
For -20 dbm
PHY_-20dbm_1DB_TOLERANCE 0x33
PHY_-20dbm_3DB_TOLERANCE 0x53
PHY_-20dbm_6DB_TOLERANCE 0xB3
For -32 dbm
PHY_-20dbm_1DB_TOLERANCE 0x20
PHY_-20dbm_3DB_TOLERANCE 0x60
PHY_-20dbm_6DB_TOLERANCE 0xA0
By default, 6db tolerance is used.
We can change the transmission level using the function- setTransmitPower(int32
powerLevel);
Practical Experiments were conducted on 4 nodes using the transmission power levels as
0x80, 0x5F, 0x53 and 0x60, and a difference of about 5 feet were observed in each of the
power levels, with the least being at 0x60 (about 7-10 feet).
3.4 Localization of the event area of a Sensor using SENSEnuts:
• By finding the co-ordinates of the 4th point when we know the distance and the co-
ordinates of 3 other points, we are able to determine the location the unknown given
area.
• One of the most important applications of the Wireless Sensor Nodes is to detect the
occurrence of an event at any random point. This can be done if we know the co-
ordinates of 3 known points along with their distances from the 4th point.
• The distances can be obtained from the equation:
N(d) = N(0).exp((-lambda).d), where the value of 'd' is unknown.
• We consider each co-ordinate to be the centre of the circle with the distance to the
unknown co-ordinate as the radius.
• We then find the intersection point of the 3(or more) circles.
• The point at which they intersect is the co-ordinate of the unknown area.
• If the co-ordinate of the unknown event area is (x,y) and d is the distance from
another point(a,b), then the equation stands as-
(x-a)^2 + (y-b)^2 = d^2
3.5 Send and Receive Data from a Single Node:
• Each node has a transceiver and can hence, both send and receive data according to its
requirement.
• We wrote a code, where we first broadcasted a parameter which was received by
another co-ordinator.
• The co-ordinator performed some operations and then sent the manipulated parameter
back to the pan co-ordinator.
• The pan co-ordinator then displays the value of the parameter, and thus, proves that
each node is able to send, receive as well as perform some operations on the values as
well.
4. FUTURE SCOPE
(Difficulties and Problems that need to be looked upon)
1. No major changes in Transmission Range even on changing the Transmission levels.
This poses a major hindrance on setting our transmission limit to a required level. On
setting the Transmission power to -32dbm, the transmission range is coming to about
20-25 feet (considering the location to be the Students‟ Lab), but it is being specified
here that it should come to about 10 feet.
2. Multiple receivers are arbitrarily receiving the data in spite of specifying the required
receiver address ID. Multiple Receivers are not accurately receiving what the Sender
Nodes are sending, i.e. the sender nodes arbitrarily choose which Receiver they want
to send the information to (in spite of specifically mentioning the node ID).
3. Print out a desired table using the updateAmbientdb() command, as per our
requirements consisting of rows and columns, including the title of each of the
columns.
4. Display a string value in the Print window, using the Debug command.
5. Simultaneous Send/Receive data: These have the following problems-
a. Send/Receive data from one gateway to another gateway.
b. Sending the data just once instead of continuously (multicast/unicast).
5. CONCLUSION
Thus, after a month of academic research, we have been able to identify the above given
points as well as the problems. Wireless Sensor Nodes, along with the application of
SENSEnuts, will have a large impact in days to come and find important applications in
several sectors, such as detection of temperature, light intensity, soil fertility, moisture
content and several other such factors. The area of WSN is thriving and every day new
ideas are emerging. This is still a young technology, allowing WSNs great growth
potential. It is this potential that captures the attention of those who interact with WSNs.
All in all, when we look at WSN, we need to think of a long haul game. We need to be in
the running for a long time and then good things will definitely come for India.
6. REFERENCES
1. ^ a b c d e Römer, Kay, Friedemann Mattern (December 2004). "The Design Space of Wireless Sensor Networks". IEEE Wireless Communications 11 (6): 54-61.
2. ^ a b Hadim, Salem, Nader Mohamed (2006). "Middleware Challenges and Approaches for Wireless Sensor Networks". IEEE Distributed Systems Online 7 (3). art. no. 0603-o3001.
3. ^ Römer, Kay (February 2004). "Programming Paradigms and Middleware for Sensor Networks". GI/ITG Fachgespräch Sensornetze, Karlsruhe.
4. An FDL'ed Textbook on Sensor Networks[4], Thomas Haenselmann. 5. Wireless Sensor Networks, Cauligi S. Raghavendra (Editor), Krishna M. Sivalingam (Editor),
Taieb Znati. 6. Wireless Sensor Networks: Architectures and Protocols, Edgar H. Callaway, Jr. and Edgar H.
Callaway, CRC Press, August 2003, 352 pages. 7. Information Processing in Sensor Networks, Feng Zhao, and Leonidas J. Guibas (Eds). 8. Handbook of sensor networks; algorithms and architectures, Edited by Ivan Stojmenovic,
Wiley-Interscience, 2005, 531 pages. 9. Wireless Sensor Network A Systems Perspective, Nirupama Bulusu, Sanjay Jha, Artech House,
Published July 2005, ISBN 1-58053-867-3 10. Protocols and Architectures for Wireless Sensor Networks, Holger Karl, Andreas Willig, ISBN
0-470-09511-3, 526 pages, January 2006 11. Adhoc and Sensor Networks Theory and Applications, Carlos de Morais Cordeiro (Philips
Research North America, USA) & Dharma Prakash Agrawal (University of Cincinnati, USA), March 2006.
12. Networking Wireless Sensors, Bhaskar Krishnamachari (University of Southern California), (ISBN-13: 9780521838474 | ISBN-10: 0521838479)
13. Distributed Sensor Networks", S. S. Iyengar, R. R. Brooks, Chapman & Hall/CRC; (October 22, 2004), ISBN 1-58488-383-9 .
14. Handbook of Sensor Networks: Compact Wireless and Wired Sensing Systems, Mohammad Ilyas, Imad Mahgoub, 672 pages CRC Press; (July 16, 2004), ISBN 0-8493-1968-4 .
15. Algorithmic Aspects Of Wireless Sensor Networks (Lecture Notes in Computer Science)", Sotiris Nikoletseas, Jose Rolim, Springer-Verlag; (September 30, 2004), ISBN 3-540-22476-9 .
16. Overview of wireless sensor networks (IEEE Computer Society) 17. Lecture on Sensor Networks incl. slides, exercises and sample solutions (University of
Mannheim) 18. Wireless Sensor Networks Training Seminar (Crossbow Technology) 19. Wireless Communications and Sensor Networks (Harvard) 20. Sensor Network Systems (Stanford) 21. Wireless Sensor Networks (course reading package available online) 22. Wireless Sensor Networks with slides and exercises - partially in German (Institute for
Pervasive Computing, ETH Zurich)
Top Related