Applicable VersionsNetsim StandardNetsim Pro


Applicable Releasesv11v12
v13
NetSim has a dedicated power model for Sensor nodes that are part of WSN/IoT networks. The power model is user-configurable and can be found in the ZigBee Interface properties of the Sensor nodes.


Energy consumption is calculated individually for each sensor node that is part of the network scenario during various Radio States such as SLEEP, TRX_ON_BUSY, RX_ON_IDLE, RX_ON_BUSY, RX_OFF. 

Based on the calculations done, NetSim provides a detailed Battery Model Metrics table that provides energy consumption of each device with respect to Transmission, Reception, Idle Mode, Sleep Mode, etc.  


It also provides information about the node's initial energy, consumed energy and remaining energy.  However, remaining energy may also include harvested energy if energy harvesting is turned on.


To explicitly get the energy harvested by each device in the Battery Metrics table modifications to the source codes of the BatteryModel Project of NetSim is required. 


Please follow the steps given below:


1. Add a variable rechargingEnergy to the stru_battery structure in BatteryModel.c file as shown below:
typedef struct stru_battery
{
    NETSIM_ID deviceId;
    NETSIM_ID interfaceId;
    double initialEnergy;
    double consumedEnergy;
    double remainingEnergy;
    double rechargingEnergy;
    double voltage;
    double rechargingCurrent;
    int modeCount;
    ptrBATTERYMODE mode;

    int currentMode;
    double modeChangedTime;

    void* animHandle;
    struct stru_battery* next;
}BATTERY, *ptrBATTERY;


2. Add a line to udpate the variable inside the function battery_set_mode() as shown below:
_declspec(dllexport) bool battery_set_mode(ptrBATTERY battery,
                                         int mode,
                                         double time)
{
    bool ret;
    ptrBATTERYMODE pm = battery_find_mode(battery, battery->currentMode);
    double r = battery->voltage*battery->rechargingCurrent*(time - battery->modeChangedTime) / 1000000;
    double c = battery->voltage*pm->current*(time - battery->modeChangedTime) / 1000000;
 
   battery->rechargingEnergy += r;
    battery->remainingEnergy += r;
    battery->modeChangedTime = time;

3. Further Modify the while loop in the function battery_metrics() to write the Recharging Energy to Battery Model metrics table as shown below:

declspec(dllexport) void battery_metrics(PMETRICSWRITER metricsWriter)

{

ptrBATTERY b;

    static bool isCalled = false;

    if (isCalled)

        return;

    isCalled = true;


    if (!firstBattery)

        return; // No battery is added


    PMETRICSNODE menu = init_metrics_node(MetricsNode_Menu, "Battery model", NULL);

    PMETRICSNODE table = init_metrics_node(MetricsNode_Table, "Battery model", NULL);

    add_node_to_menu(menu, table);


    char modeList[BUFSIZ]="";

    sprintf(modeList, "Device Name#1,Initial energy(mJ)#1,Consumed energy(mJ)#1,Remaining      Energy(mJ)#1,Recharging Energy(mJ)#1,");

    prepare_mode_list(modeList);

    add_table_heading_special(table, modeList);

    b = firstBattery;

    while (b)

.

.

.

.

while (b)
    {
        add_table_row_formatted(false, table,
                                "%s,%lf,%lf,%lf,
%lf,",
                                DEVICE_NAME(b->deviceId),
                                b->initialEnergy,
                                b->consumedEnergy,
                                b->remainingEnergy,
                             
   b->rechargingEnergy);
        add_to_table(table, index);
        b = b->next;
        index++;
    }

4. After performing the above changes, rebuild the BatteryModel project to get the recharging energy in the results dashboard for further simulations, as shown below:




The default settings in the energy model in NetSim IoT/ WSN library is based on Table 1 in the following paper:

Accurate Prediction of Power Consumption in Sensor Networks