Applicable VersionsNetSim StandardNetSim Pro

In this example, we explain how the data rate in WSN can be modified based on the number of error packets. And, as the error increases the data rate drops.


Add the following code in 802.15.4.c file


int error_packet[100];



Add the following lines of code in the PHY_OUT event present in 802.15.4.c file 


if(error_packet[nDeviceId-1] > 20)

    dDataRate = 0.200;  // here we change the rate from 250 kbps to 200 kbps

   else

    dDataRate = NETWORK->ppstruNetSimLinks[nDevice_PortId-1]->puniMedProp.pstruWirelessLink.dDataRateUp;


 

Add the following line in PHY_IN event


error_packet[nDeviceId-1]++;


 

After code modifications rebuild the project and replace the dll in the bin folder.

For error packets please set channel characteristics to Line of Sight, path loss exponent to 3 or more.

To check the change in data rate, put the breakpoint as per the above screenshots. During debugging you can see the variation in data rate 


Related articles:

what-is-the-iot-stack-in-netsim-

how-is-the-phy-rate-decided-in-netsim-802-11-

how-do-i-modify-the-802-15-4-phy-