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 as shown below:


Applicable Releases
v11
v12
v13



Energy consumed by the sensor devices are computed in the function battery_set_mode() present in the BatteryModel.c file which belongs to the BatteryModel project.


And called in the function fn_NetSim_Zigbee_ChangeRadioState() present in the ChangeRadioState.c file which belongs to ZigBee project. 

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 which provides energy consumption of each device with respect to Transmission, Reception, Idle Mode, Sleep Mode as shown below:



Applicable Releases
v10.2


Energy consumed by the sensor devices are computed in the function fn_NetSim_Zigbee_ChangeRadioState() present in the ChangeRadioState.c file which belongs to ZigBee project. 


int fn_NetSim_Zigbee_ChangeRadioState(NETSIM_ID nDeviceId, PHY_TX_STATUS nOldState, PHY_TX_STATUS nNewState,POWER** pstruDevicePower,NetSim_EVENTDETAILS* pstruEventDetails)
{
  double* d;
  double dPrevTime,dConsumedEnergy,dRechargeEnergy=0;
  int nStatus = 0;
  dPrevTime = pstruDevicePower[nDeviceId-1]->dPrevChangedStateTime;
  switch(nOldState)
  {
  case SLEEP:
    dConsumedEnergy = pstruDevicePower[nDeviceId-1]->dSleepModeCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
    d = &pstruDevicePower[nDeviceId - 1]->dSleepModeEnergyConsumed;
    break;
  case TRX_ON_BUSY:
    dConsumedEnergy = pstruDevicePower[nDeviceId-1]->dTransmittingCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
    d = &pstruDevicePower[nDeviceId - 1]->dTransmissionModeEnergyConsumed;
    break;
  case RX_ON_IDLE:
    dConsumedEnergy = pstruDevicePower[nDeviceId-1]->dIdleModeCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
    d = &pstruDevicePower[nDeviceId - 1]->dIdleModeEnergyConsumed;
    break;
  case RX_ON_BUSY:
    dConsumedEnergy = pstruDevicePower[nDeviceId-1]->dReceivingCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
    d = &pstruDevicePower[nDeviceId - 1]->dReceptionModeEnergyConsumed;
    break;
  case RX_OFF:
    dConsumedEnergy = pstruDevicePower[nDeviceId-1]->dIdleModeCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
    d = &pstruDevicePower[nDeviceId - 1]->dIdleModeEnergyConsumed;
    break;
  default:
    dConsumedEnergy=0;
    d = &dConsumedEnergy;
    //Unknown mode
    break;
  }
  //Change the state

  nStatus = 1;
  if(pstruDevicePower[nDeviceId-1]->nNodeStatus == OFF)
  {
    nStatus = 0;
    //  return nStatus;
  }
  dRechargeEnergy = pstruDevicePower[nDeviceId-1]->dRechargingCurrent_mA*pstruDevicePower[nDeviceId-1]->dVoltage_V*(ldEventTime-dPrevTime)/1000000;
  
  //Store the time
  double r = pstruDevicePower[nDeviceId - 1]->dRemainingPower;

  pstruDevicePower[nDeviceId-1]->dPrevChangedStateTime = ldEventTime;
  pstruDevicePower[nDeviceId-1]->dRemainingPower -=dConsumedEnergy;
  pstruDevicePower[nDeviceId-1]->dRemainingPower += dRechargeEnergy;
  if(pstruDevicePower[nDeviceId-1]->dRemainingPower  <= 0 &amp;&amp; pstruDevicePower[nDeviceId-1]->nPowerSource == BATTERY)
  {
    pstruDevicePower[nDeviceId-1]->nNodeStatus = OFF;
    pstruDevicePower[nDeviceId-1]->dRemainingPower = 0;
    nStatus = 0;
    *d += r;
  }
  else
  {
    *d += dConsumedEnergy;
  }
  double per = pstruDevicePower[nDeviceId - 1]->dRemainingPower * 100;
  per /= pstruDevicePower[nDeviceId - 1]->dInitialEnergy_mW;
  animation_add_new_entry(pstruDevicePower[nDeviceId-1]->animHandle,
              ANIM_BATTERY,
              "%d,%lf,%lf,",
              DEVICE_CONFIGID(nDeviceId),
              per,
              pstruEventDetails->dEventTime);
  if(nStatus)
  {
    WSN_PHY(nDeviceId)->nOldState = nOldState; 
    WSN_PHY(nDeviceId)->nRadioState = nNewState; 
    return nStatus;
  }
  else
  {
    WSN_PHY(nDeviceId)->nRadioState = RX_OFF;
    WSN_MAC(nDeviceId)->nNodeStatus = OFF;
    return nStatus;

  }
}


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 Energy Metrics table which provides energy consumption of each device with respect to Transmission, Reception, Idle Mode, Sleep Mode 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


Related articles:

how-do-i-configure-sleep-time-inactive-active-times-for-sensors-in-netsim-

how-do-i-plot-energy-consumption-over-time-for-sensor-nodes-for-wsn-iot-networks-