Applicable Versions | NetSim Standard | NetSim Pro |
RSSI, SINR, and BER in ZigBee can be logged into a text or CSV file and then be plotted as per your requirement. Following is one such example where we log these parameters into a comma-separated CSV file.
Applicable Releases | v13.3 |
The log file IEEE802.15.4 Radio measurements Log is enabled in GUI. IEEE802_15_4_RADIO_MEASUREMENTS_LOG.csv file contains the values of SNR, BER and RSSI defined as RadioMeasurements_802_15_4_Log() function inside 802._15_4_RadioMeasurementsLog.c file, under ZigBee protocol.
Now right-click on the ZigBee module in the solution explorer and select rebuild.
Upon successful build, NetSim will automatically update the respective binaries in the current workspace.
Now on running any simulation in ZigBee (WSN/IoT), users can now access the IEEE802_15_4_RADIO_MEASUREMENTS_LOG .csv file from the results dashboard under the Log Files drop-down as shown below:
Modifying the source codes:
The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim.
Applicable Releases | v13.1 | v13.2 |
i. Open NetSim source code in Visual Studio by clicking on the Open Code button on NetSim Home Screen via Your Work-> Source code-> Open Code.
ii. Go to the ZigBee project through the solution explorer and open the file 802_15_4.c Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Init() function as shown below:
_declspec (dllexport) int fn_NetSim_Zigbee_Init()
{
//RSSI BER SNR LOG
FILE* fp;
char filename[BUFSIZ];
sprintf(filename, "%s\\%s", pszIOLogPath, "ZIGBEE_BER_LOG.csv");
fp = fopen(filename, "w+");
if (fp)
{
fprintf(fp, "PACKET_ID,PACKET_TYPE,TRANSMITTER,RECEIVER,RX_POWER(dBm),TOTAL_RX_POWER(dBm),SNR(dB),BER");
fclose(fp);
}
//RSSI BER SNR LOG
return fn_NetSim_Zigbee_Init_F();
}
ii. Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Run() function under PHYSICAL_IN_EVENT as shown below:
case PHYSICAL_IN_EVENT:
{
NetSim_PACKET *pstruPacket;
PACKET_STATUS nPacketStatus;
double SNR;
double dBER;
pstruPacket = pstruEventDetails->pPacket;
if(pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)
{
fnNetSimError("Different device packet received..");
assert(false);
return 0;
}
if(!ZIGBEE_CHANGERADIOSTATE(pstruEventDetails->nDeviceId, WSN_PHY(pstruEventDetails->nDeviceId)->nRadioState, RX_ON_IDLE))
return 0;
if(WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower - GET_RX_POWER_mw(pstruPacket->nTransmitterId,pstruPacket->nReceiverId,pstruEventDetails->dEventTime) >= WSN_PHY(pstruEventDetails->nDeviceId)->dReceiverSensivity)
pstruPacket->nPacketStatus = PacketStatus_Collided;
nPacketStatus = pstruPacket->nPacketStatus;
ZIGBEE_SINR(&SNR,
WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower,
GET_RX_POWER_mw(pstruPacket->nTransmitterId,pstruPacket->nReceiverId,pstruEventDetails->dEventTime));
dBER = fn_NetSim_Zigbee_CalculateBER(SNR);
//RSSI BER SNR LOG
double rxpwr = MW_TO_DBM(WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower);
double total_rxpwr = GET_RX_POWER_dbm(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime);
FILE* fp;
char filename[BUFSIZ];
sprintf(filename, "%s\\%s", pszIOLogPath, "ZIGBEE_BER_LOG.csv");
fp = fopen(filename, "a+");
if (fp)
{
fprintf(fp, "\n%d,%s,%s,%s,%lf,%lf,%lf,%lf", pstruPacket->nPacketId,
pstruPacket->szPacketType,
DEVICE_NAME(pstruPacket->nTransmitterId),
DEVICE_NAME(pstruPacket->nReceiverId),
rxpwr, total_rxpwr, SNR, dBER);
fclose(fp);
}
//RSSI BER SNR LOG
if(fn_NetSim_Packet_DecideError(dBER,pstruEventDetails->dPacketSize))
{
pstruPacket->nPacketStatus = PacketStatus_Error;
nPacketStatus = PacketStatus_Error;
}
iii. Now right-click on the ZigBee module in the solution explorer and select rebuild.
iv. Upon successful build, NetSim will automatically update the respective binaries in the current workspace.
vi. Now on running any simulation in ZigBee (WSN/IoT), users can now access the ZIGBEE_BER_LOG.csv file from the results dashboard under the Log Files drop-down as shown below:
Applicable Releases | v11.1 | v12 | v13.0 |
i.Open NetSim source code in Visual Studio by clicking on the Open Code button present in NetSim Home Screen via Open Simulation->Workspace Options->Open Code.
ii.Go to ZigBee project through the solution explorer and open the file 802_15_4.c Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Init() function as shown below:
_declspec (dllexport) int fn_NetSim_Zigbee_Init(struct stru_NetSim_Network *NETWORK_Formal, \
NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, \
char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
{
FILE* fp;
pstruEventDetails = pstruEventDetails_Formal;
NETWORK = NETWORK_Formal;
pszAppPath = pszAppPath_Formal;
pszIOPath = pszWritePath_Formal;
//RSSI BER SNR LOG
fp = fopen("ZIGBEE_BER_LOG.csv", "w+");
if (fp)
{
fprintf(fp, "PACKET_ID,PACKET_TYPE,TRANSMITTER,RECEIVER,RX_POWER(dBm),TOTAL_RX_POWER(dBm),SNR(dB),BER");
fclose(fp);
}
//RSSI BER SNR LOG
fn_NetSim_Zigbee_Init_F(NETWORK_Formal, pstruEventDetails_Formal, pszAppPath_Formal, \
pszWritePath_Formal, nVersion_Type, fnPointer);
return 0;
}
ii. Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Run() function under PHYSICAL_IN_EVENT as shown below:
case PHYSICAL_IN_EVENT:
{
NetSim_PACKET *pstruPacket;
PACKET_STATUS nPacketStatus;
double SNR;
double dBER;
double dErrorRange;
FILE* fp;
pstruPacket = pstruEventDetails->pPacket;
if (pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)
{
fnNetSimError("Different device packet received..");
assert(false);
return 0;
}
if (!ZIGBEE_CHANGERADIOSTATE(pstruEventDetails->nDeviceId, WSN_PHY(pstruEventDetails->nDeviceId)->nRadioState, RX_ON_IDLE))
return 0;
if (WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower - GET_RX_POWER_mw(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime) >= WSN_PHY(pstruEventDetails->nDeviceId)->dReceiverSensivity)
pstruPacket->nPacketStatus = PacketStatus_Collided;
nPacketStatus = pstruPacket->nPacketStatus;
ZIGBEE_SINR(&SNR,
WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower,
GET_RX_POWER_mw(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime));
dBER = fn_NetSim_Zigbee_CalculateBER(SNR);
//RSSI BER SNR LOG
double rxpwr = MW_TO_DBM(WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower);
double total_rxpwr = GET_RX_POWER_dbm(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime);
fp = fopen("ZIGBEE_BER_LOG.csv", "a+");
if (fp)
{
fprintf(fp, "\n%d,%s,%s,%s,%lf,%lf,%lf,%lf", pstruPacket->nPacketId,
pstruPacket->szPacketType,
DEVICE_NAME(pstruPacket->nTransmitterId),
DEVICE_NAME(pstruPacket->nReceiverId),
rxpwr, total_rxpwr, SNR, dBER);
fclose(fp);
}
//RSSI BER SNR LOG
if (fn_NetSim_Packet_DecideError(dBER, pstruEventDetails->dPacketSize))
iii. Now right-click on the ZigBee module in the solution explorer and select rebuild.
iv. Upon successful build, NetSim will automatically take care of updating the respective binaries in the current workspace.
vi. Now on running any simulation in ZigBee (WSN/IoT), you will get a log file containing RSSI, SINR, and BER, in the bin folder of NetSim (“<NetSim_Install_Directory>/bin”)
Applicable Releases | v10 | v11.0 |
i.Open NetSim source code in Visual Studio by double clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder.
ii.Go to ZigBee project through the solution explorer and open the file 802_15_4.c Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Init() function as shown below:
_declspec (dllexport) int fn_NetSim_Zigbee_Init(struct stru_NetSim_Network *NETWORK_Formal, \
NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, \
char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
{
FILE* fp;
pstruEventDetails = pstruEventDetails_Formal;
NETWORK = NETWORK_Formal;
pszAppPath = pszAppPath_Formal;
pszIOPath = pszWritePath_Formal;
//RSSI BER SNR LOG
fp = fopen("ZIGBEE_BER_LOG.csv", "w+");
if (fp)
{
fprintf(fp, "PACKET_ID,PACKET_TYPE,TRANSMITTER,RECEIVER,RX_POWER(dBm),TOTAL_RX_POWER(dBm),SNR(dB),BER");
fclose(fp);
}
//RSSI BER SNR LOG
fn_NetSim_Zigbee_Init_F(NETWORK_Formal, pstruEventDetails_Formal, pszAppPath_Formal, \
pszWritePath_Formal, nVersion_Type, fnPointer);
return 0;
}
ii. Add the lines of code highlighted in red inside the fn_NetSim_Zigbee_Run() function under PHYSICAL_IN_EVENT as shown below:
case PHYSICAL_IN_EVENT:
{
NetSim_PACKET *pstruPacket;
PACKET_STATUS nPacketStatus;
double SNR;
double dBER;
double dErrorRange;
FILE* fp;
pstruPacket = pstruEventDetails->pPacket;
if (pstruPacket->nReceiverId && pstruPacket->nReceiverId != pstruEventDetails->nDeviceId)
{
fnNetSimError("Different device packet received..");
assert(false);
return 0;
}
if (!ZIGBEE_CHANGERADIOSTATE(pstruEventDetails->nDeviceId, WSN_PHY(pstruEventDetails->nDeviceId)->nRadioState, RX_ON_IDLE))
return 0;
if (WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower - GET_RX_POWER_mw(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime) >= WSN_PHY(pstruEventDetails->nDeviceId)->dReceiverSensivity)
pstruPacket->nPacketStatus = PacketStatus_Collided;
nPacketStatus = pstruPacket->nPacketStatus;
ZIGBEE_SINR(&SNR,
WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower,
GET_RX_POWER_mw(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime));
ZIGBEE_BER(SNR, &dBER, &dErrorRange);
//RSSI BER SNR LOG
double rxpwr = MW_TO_DBM(WSN_PHY(pstruEventDetails->nDeviceId)->dTotalReceivedPower);
double total_rxpwr = GET_RX_POWER_dbm(pstruPacket->nTransmitterId, pstruPacket->nReceiverId, pstruEventDetails->dEventTime);
fp = fopen("ZIGBEE_BER_LOG.csv", "a+");
if (fp)
{
fprintf(fp, "\n%d,%s,%s,%s,%lf,%lf,%lf,%lf", pstruPacket->nPacketId,
pstruPacket->szPacketType,
DEVICE_NAME(pstruPacket->nTransmitterId),
DEVICE_NAME(pstruPacket->nReceiverId),
rxpwr, total_rxpwr, SNR, dBER);
fclose(fp);
}
//RSSI BER SNR LOG
if (fn_NetSim_Packet_DecideError(dBER, pstruEventDetails->dPacketSize))
iii. Now right-click on the ZigBee module in the solution explorer and select rebuild.
iv. Upon successful build, you will get a new libZigBee.dll file in the “<NetSim_Install_Directory>/src/Simulation/DLL” folder.
v.Copy this newly-built DLL file and replace it in the bin folder of NetSim after you rename the original libZigBee.dll file which is already existing there(as a backup).
vi. Now on running any simulation in ZigBee (WSN/IOT), you will get a log file containing RSSI, SINR, and BER, in the bin folder of NetSim (“<NetSim_Install_Directory>/bin”)