. .
.
Wireless Sensor Network
.
.

 

Prerequisites

 

Introduction to WSN, nesc, send and receive, wireless propagation

 

Hardware requirements

 

Micaz mote, multimeters, sensor board MTS310, mib board

 

Programming

 

nesc

 

This experiment deals with the study of different types of wireless sensor network topologies. Two types of wireless sensor networks called single hop network and hierarchical network are implemented in this experiment. A total of 19 wireless nodes are used in this experiment for implementing single hop network or hierarchical network. The WSN works according to the user input selection. 

                These 19 wireless nodes are divided into three levels of the network. Of them, one node is in the first level and it acts as a sink node, three nodes are placed in the second level and they act as cluster nodes and fifteen nodes are placed in the third level which form the leaf nodes. Each leaf node is connected to the sensor board MTS310  which is having accelerometer sensor, magnetometer sensor, light sensor, acoustic sensor, sound sensor and temperature sensor. In a single hop network, the sensed values from the leaf nodes are sent directly to the sink node whereas in a hierarchical network the leaf nodes sent the sensed values to the corresponding cluster heads(CH) and the CH sends it to the sink node.

                                               

                                                  Figure9: MTS310[14]

 

   Wireless Sensor Network : Experimental Setup

 

                                                                    

                                   Figure10: Wireless Sensor Network setup

 

Experimental wireless sensor network setup is shown in the figure 2. In this wireless sensor network setup each wireless node has its own default address which is shown in the figure that is

·         1 is the sink node address.

·         2, 8 and 14 are the cluster nodes addresses.

·         3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 and 19 are the leaf node addresses.

 

When leaf node sends sensed data to the cluster node, cluster node does the average of the leaf node data and will send it to the sink node.  In this experiment the remote user can give three inputs which are listed below

1. Network type: Remote user has the option to select any one of single hop network or hierarchical network.

Single hop network: In this network, leaf nodes 3, 4, 5, 6 and 7 can be connected to the sink node.

Hierarchical network: In this network, leaf nodes 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 and 19 can be connected to the cluster nodes 2, 8 and 14 and these cluster nodes are connected to the sink node.

2.   Number of nodes:

In a single hop network, the minimum number of nodes are 2 and the maximum number of nodes selected is 6. If the user selects number of nodes as 4, then leaf nodes 3, 4 and 5 are connected to the sink node and thus the total number of nodes in the network is 4.

In a hierarchical network, minimum number of nodes are 3 and maximum number of nodes selected is 19. If the user selects number of nodes as 10, then the leaf nodes 3, 4, 5, 6 and 7 gets connected to the cluster node 2. Leaf nodes 9, 10 gets connected to the cluster node 8. The cluster nodes 2 and 8 are connected to the sink node 1. Thus the total number of nodes in the network is 10.

  3.     Power levelUser can operate the wireless sensor network in different power levels.

           Ref: http://vlab.amrita.edu/?sub=78&brch=256&sim=1362&cnt=1

Procedure

1.      Implement the configuration file

                              1.1 Identify the interfaces required:  

                               1.2. Identify the components which are providing the required interfaces:

                                1.3.  Perform wiring:   

                         

 2.   Implement the module file :

               This is the file, where we are implementing the actual task. Here the tasks include

                             

 Here we are  Implementing two types of network, i.e centralized  network and hierarchical network. For that,        we need 4sets on nodes(Gateway node, Sink node, Cluster head and leaf node)

 


 3. Implement the make file

 

 4. Burn the program to device and start functioning.

 

Leaf node:

 

The components used are :

components Main, leafnodeM, TimerC, LedsC, GenericComm;
 components CC2420RadioC, SensirionHumidity;

implementation

{

/* Booting and initialization */
      Main.StdControl -> TimerC.StdControl;
      Main.StdControl -> leafnodeM.StdControl;
      Main.StdControl -> GenericComm.Control; 
      Main.StdControl -> CC2420RadioC.StdControl;
     
      /* Leds and Timers */
      leafnodeM.Leds -> LedsC.Leds;
      leafnodeM .Timer1 -> TimerC.Timer[unique("Timer")];
      leafnodeM .Timer2 -> TimerC.Timer[unique("Timer")];
      leafnodeM .Timer3 -> TimerC.Timer[unique("Timer")];
      //leafnodeM.ADC -> Sensor;
      //leafnodeM.ADCControl -> Sensor;
     
      /*Radio related */
      leafnodeM.CC2420Control -> CC2420RadioC.CC2420Control;
      leafnodeM.SendMsg -> GenericComm.SendMsg[AM_INTMSG];
      leafnodeM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_INTMSG];
     
     
      /* sensor reading MTS400 */
      leafnodeM.ReadTemp -> SensirionHumidity.Temperature;
      leafnodeM.ReadHum -> SensirionHumidity.Humidity;
      leafnodeM.SensControl -> SensirionHumidity.SplitControl;

}

In the module file:

includes IntMsg;  

module

{

provides
            interface StdControl;
      uses
      {
            interface Timer as Timer1; //Idle timer to reset
            interface Timer as Timer2; //Sensing timer
            interface Timer as Timer3;
            interface Leds;
            interface SendMsg;
            interface ReceiveMsg;
            interface CC2420Control; //TxPower set
            interface ADC as ReadTemp;
            interface ADC as ReadHum;
            interface SplitControl as SensControl;
           
           

      command void health_packet(bool enable, uint16_t intv);
      }
}

 

Implementation {

Write your code here;

}

event result_t Timer3.fired()
      {
            IntMsg *message = (IntMsg *)sendPkt.data;
            atomic
            {
                  message->val = temperature;
                  message->src = TOS_LOCAL_ADDRESS;
                  message->ptype = ntype;
                  addr_bak = address;
                  if(call SendMsg.send(addr_bak, sizeof(IntMsg), &sendPkt))
                  {
                        atomic
                        {
                              send_to_clHead = TRUE;
                        }
                  }
            }
            return SUCCESS;
      }
      event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t status)
      {
            IntMsg *message = (IntMsg *)sendPkt.data;
            if(status == FAIL)
            {
                  call Leds.redToggle();
            }
            if(send_to_clHead)
            {    
                  message->expid = 9;
                  atomic
                  {
                        message->dstads = addr_bak;
                        message->src = TOS_LOCAL_ADDRESS;
                        message->val = temperature;
                  }
                  if(call SendMsg.send(20, sizeof(IntMsg), &sendPkt))
                  {
                        atomic
                        {
                              send_to_clHead = FALSE;
                        }
                        call Leds.yellowToggle();
                  }
            }          
            return SUCCESS;
      }

 

 

Cluster head:

 

The components used are

components Main, clusternodeM, TimerC, LedsC;
 components GenericComm, CC2420RadioC;

implementation
{

      components Main, clusternodeM, TimerC, LedsC;
    components GenericComm, CC2420RadioC;
     
      Main.StdControl -> TimerC.StdControl;
      clusternodeM .Timer1 -> TimerC.Timer[unique("Timer")];
      clusternodeM .Timer2 -> TimerC.Timer[unique("Timer")];
      Main.StdControl -> clusternodeM.StdControl;
      Main.StdControl -> GenericComm.Control;
      Main.StdControl -> CC2420RadioC.StdControl;
      clusternodeM.CC2420Control -> CC2420RadioC.CC2420Control;
      clusternodeM.Leds -> LedsC.Leds;
      clusternodeM.SendMsg -> GenericComm.SendMsg[AM_INTMSG];
      clusternodeM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_INTMSG];

}

In the module file:

includes IntMsg;  

module

{

provides interface StdControl;
      uses
      {
            interface Leds;
            interface Timer as Timer1;
            interface Timer as Timer2;
            interface SendMsg;
            interface ReceiveMsg;
            interface CC2420Control;

      }
}

implementation
{

Write your code here;

}

event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t status)
      {
            IntMsg *message = (IntMsg *)sendPkt.data;
            if(status == FAIL)
            {
                  call Leds.redToggle();
            }
            if(send_to_sink)
            {
                  send_to_sink = FALSE;                    
                  message->expid = 9;
                  message->dstads = 1;
                  message->val = avg;
                  if(call SendMsg.send(20, sizeof(IntMsg), &sendPkt))
                  {
                        call Leds.yellowToggle();
                  }
            }
            return SUCCESS;
      }
      /*
       * Idle timer resets all the LEDs and turnof other timers */
      event result_t Timer1.fired()
      {
            call Leds.set(0);
            return SUCCESS;
      }
}

 

 

Sink node

 

components used are 

components Main, SinknodeM, TimerC, LedsC;

 components GenericComm, CC2420RadioC;

implementation

{

     

      Main.StdControl -> SinknodeM.StdControl;

      SinknodeM .Timer1 -> TimerC.Timer[unique("Timer")];

      SinknodeM .Timer2 -> TimerC.Timer[unique("Timer")];

      Main.StdControl -> CC2420RadioC.StdControl;

      SinknodeM.CC2420Control -> CC2420RadioC.CC2420Control;

      SinknodeM.Leds -> LedsC.Leds;

      Main.StdControl -> GenericComm.Control;

      SinknodeM.SendMsg -> GenericComm.SendMsg[AM_INTMSG];

      SinknodeM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_INTMSG];

}

In the module file:

module SinknodeM
{
      provides
            interface StdControl;
      uses
      {          
            interface Leds;
            interface Timer as Timer1;
            interface Timer as Timer2;
            interface SendMsg;
            interface ReceiveMsg;
            interface CC2420Control;
      }

implementation
{

write your code here

}

 

event result_t Timer2.fired()
      {
            sendPacket(avg); 
            return SUCCESS;
      }
      event result_t Timer1.fired()
      {
            call Leds.set(0);
            return SUCCESS;
      }
}

 

 

Gateway node/main sink

 

components used are 

components Main, msinkM, LedsC, TimerC, GenericComm, HPLUARTC;

 

implementation
{

      Main.StdControl -> msinkM.StdControl;
      Main.StdControl -> TimerC.StdControl;    
      Main.StdControl -> GenericComm.Control;
      msinkM.HPLUART -> HPLUARTC;  
      msinkM.SendMsg -> GenericComm.SendMsg[AM_INTMSG];
      msinkM.UARTTimer -> TimerC.Timer[unique("Timer")];
      msinkM.Leds -> LedsC.Leds;
      msinkM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_INTMSG];
}

In module file:

 

includes IntMsg;

module 
{
      provides
            interface StdControl;
      uses
      {
            interface Leds;
            interface SendMsg;
            interface HPLUART;
            interface ReceiveMsg;
            interface Timer as UARTTimer;
      }
}

implementation
{

write your code here

}

event result_t UARTTimer.fired()
      {
            IntMsg* message;
            if(buf_head_index == buf_tail_index)
            {
                  call UARTTimer.stop();
                  call Leds.redToggle();
                  timer_started = FALSE;
                  return SUCCESS;
            }
            call UARTTimer.stop();
            message = (IntMsg *)TosMsgPtr_buf[buf_tail_index]->data;
            atomic
            {
                  lastPkt[lastIndex++] = '/';
                  lastPkt[lastIndex++] = '9';
                  lastPkt[lastIndex++] = '*';
                  if(message->src < 10)
                  {
                        lastPkt[lastIndex++] = (char)(message->src + 48);
                  }
                  else
                  {
                        lastPkt[lastIndex++] = (char)((message->src % 10) + 48);
                        lastPkt[lastIndex++] = '1';
                  }
                  lastPkt[lastIndex++] = '*' ;
                  convToNumber((message -> dstads) )  ;
                  lastPkt[lastIndex++] = '*' ;
                  convToNumber((message -> val))  ;
                  lastPkt[lastIndex++] = '$' ;
                  lastPkt[lastIndex] = '\0' ;
           
      /** Added to reinitialize "lastIndex"       
                  lastIndex = 0;
                  call HPLUART.put(lastPkt[count++]);
            }
            buf_tail_index = (buf_tail_index + 1) % (MSG_BUF_SIZE + 1);
            return SUCCESS;
      }
      event async result_t HPLUART.putDone()
      {
            atomic
            {
                  if( count == strlen(lastPkt) )
                  {
      /** Added to reinitialize "count" 
                        call UARTTimer.start(TIMER_REPEAT, 5);
                        count = 0;
                        call Leds.yellowToggle();
                  }
                  else
                  {
                        call HPLUART.put(lastPkt[count]) ;
                        count++ ;
                  }
            }
            return SUCCESS;
      }

  
}

 

 Steps

In the remote panel

Step1: select the type of network (Single hope network or Hierarchical network)

Step2: Select the number of nodes needed in the wireless sensor network.

Step3: The user has to select the power level at which the network operates

Step4: User can observe the life time of the network at various power levels as the output.

Cite this Simulator:

.....
..... .....

Copyright @ 2024 Under the NME ICT initiative of MHRD

 Powered by AmritaVirtual Lab Collaborative Platform [ Ver 00.13. ]