Applicable Versions
NetSim Standard
NetSim Pro


Applicable Releases
v9
v10    
v11


fprintf() statement can be used to print to NetSim console using the default file descriptor stderr

fprintf(stderr, "The value of the variable X is %d\n", X);

You may insert such a line at a suitable place. Note that NetSim is a discrete event simulator and hence you may see this line printed multiple times, each time that particular event (where the fprintf is written) is called.


Example 1: Printing remaining power of sensors in WSN


For NetSim v9:


Inside fn_NetSim_Zigbee_ChangeRadioState() function present in ChangeRadioState.c file add following codes


fprintf (stderr,"\nNode Name\tRemaining_Power \t Time\n");

fprintf(stderr,"\n%s\t%lf mW\t%lf ms\n\n", NETWORK->ppstruDeviceList[nDeviceId-1]->szDeviceName,pstruDevicePower[nDeviceId-1]->dRemainingPower,pstruEventDetails->dEventTime);

getch();


For NetSim v10:


Inside fn_NetSim_Zigbee_ChangeRadioState() function present in ChangeRadioState.c file add following codes


fprintf (stderr,"\nNode Name\tRemaining_Power \t Time\n");

fprintf(stderr,"\n%s\t%lf mW\t%lf ms\n\n", NETWORK->ppstruDeviceList[nDeviceId-1]->szDeviceName,pstruDevicePower[nDeviceId-1]->dRemainingPower,pstruEventDetails->dEventTime);

_getch();


For NetSim v11:


Inside fn_NetSim_Zigbee_ChangeRadioState() function present in ChangeRadioState.c file add following codes


fprintf(stderr, "\nNode Name\tRemaining_Power \t Time\n");
fprintf(stderr, "\n%s\t%lf mW\t%lf ms\n\n",
NETWORK->ppstruDeviceList[nDeviceId - 1]->szDeviceName,
battery_get_remaining_energy(battery),
pstruEventDetails->dEventTime);
_getch();


  • Rebuild the Zigbee project and replace the default libZigbee.dll by the modified one.
  • Create a scenario in WSN and simulate.
  • During simulation, the user can see the remaining power of each node along printed to simulation console along with the timestamp.


Example 2: Print node positions in MANET


Open Mobility Project, and in Mobility.c and go to fn_NetSim_Mobility_Run() function. Inside the default, case add following codes


For NetSim v9:


fprintf(stderr,"\n The position of %s at time %.2lfms is X=%.2lf and Y = %.2lf \n",DEVICE_NAME(pstruEventDetails->nDeviceId),

pstruEventDetails->dEventTime,

DEVICE_POSITION(pstruEventDetails->nDeviceId)->X,

DEVICE_POSITION(pstruEventDetails->nDeviceId)->Y);

getch();


For NetSim v10 and v11:


fprintf(stderr,"\n The position of %s at time %.2lfms is X=%.2lf and Y = %.2lf \n",DEVICE_NAME(pstruEventDetails->nDeviceId),

pstruEventDetails->dEventTime,

DEVICE_POSITION(pstruEventDetails->nDeviceId)->X,

DEVICE_POSITION(pstruEventDetails->nDeviceId)->Y);

_getch();


  • Build Mobility project and replace libMobility.dll inside the binary folder of NetSim installation directory.
  • Create a scenario in MANET and configure the mobility model of the nodes.
  • During simulation, the user can notice that the positions of the nodes are displayed in the console w.r.t. the simulation time.