Applicable Versions
NetSim StandardNetSim 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.


RSSI, SINR, and BER in Zigbee, along with other relevant parameters, are recorded in the IEEE 802.15.4 Radio Measurements Log.


Applicable Releases
v14


The IEEE 802.15.4 Radio Measurements Log file is enabled in the GUI. The IEEE802_15_4_RADIO_MEASUREMENT_LOG.csv file contains SNR, SINR, BER, and RSSI values, defined in the RadioMeasurements_802_15_4_Log() function within the 802_15_4_RadioMeasurementsLog.c file under the ZigBee protocol.



After running the simulation with the IEEE802_15_4_RADIO_MEASUREMENT_LOG.csv enabled, the file can be accessed from the results dashboard under the Logs section.

 




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 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.1v13.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: