|Applicable Versions||NetSim Standard||NetSim Pro|
In this example, we explain the simulation of a Body Area Sensor Network/ IoT Healthcare application based on real data.
Multiple sensors in the real BAN measure various health parameters which is saved to a log file (sample log file attached). An equivalent IoT network scenario is designed in NetSim, consisting of 11 sensor nodes, a 6LoWPAN Gateway, a router, and a server as shown below (sample configuration file attached - WBAN_v13_0.netsim_exp for v13, Configuration.netsim and WBAN_v12_2.netsim_exp for v12 and BAN_v11_1 for NetSim v11.1). The sensors are part of the BAN which connects to a server on the cloud.
- An application is configured for each sensor to periodically generate packets and forward it to the server via the 6LoWPAN Gateway
- Sensors and Applications have been renamed suitably as per the log file used
- The Application packet inter-arrival time has been set to 4 milliseconds as per the timestamps in the log file
- The Wireshark option in the sensor general properties is set to Offline. This will create a *.pcap log file for each sensor node, which can be accessed from the results dashboard after the simulation
The CSV / XL file below shows the readings of the sensors. The first column has the timestamps for the subsequent 11 columns having values from 11 different sensors (measuring body's ECG, EEG, Airflow, .. etc) in the network.
NetSim Application module source codes are modified to read from the log file and update the packet payload during run time. In the inbuilt traffic generator, users can model different types of applications such as CBR, Custom, Voice, Video, Database, HTTP, etc. In those applications, NetSim adds a dummy payload (string "abcd...") to the packet as per the packet size. However, users can modify the packet payload to include specific information which can be read from a string, file, etc during the simulation. The following steps highlight the code modifications done:
STEP 1: Open NetSim source codes from Open Simulation->Workspace Options-> Open code button or from Help->Open Source code option.
STEP 2: Open copy_payload() function present in Application.c file inside Application project
STEP 3: Inside the function copy_payload(), make the modifications as given below (hightlighted in red) :
void copy_payload(UINT8 real,NetSim_PACKET* packet,unsigned int* payload,APP_INFO* info)
uint32_t key = 16;
size_t len = 0;
int row = 2502;
int col = 12;
char fname[BUFSIZ] = "samplesEEG.csv";
if (packet->nPacketId + 1 > row || packet->nSourceId > col)
//Rows in Excel file are mapped to the packet ID (packet->npacketId+1)
//Columns are mapped to Application ID (info->id)
sprintf(reading, "%s", get_sensor_reading(packet->nPacketId + 1, info->id, fname));
len = strlen(reading);
for (i = 0; i < *payload; i++)
if (i < len)
real[i] = reading[i];
else if (len > 0)
real[i] = ' ';
if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt('a' + i % 26, 16);
real[i] = 'a' + i % 26;
if (info->encryption == Encryption_TEA)
encryptBlock(real, payload, &key);
else if (info->encryption == Encryption_AES)
STEP 4: In the same Application.c file perform modifications at the start of the file as given below (hightlighted in red) :
char* get_sensor_reading(int row, int col, char* filename);
char* get_sensor_reading(int row, int col, char* filename)
file = fopen(filename, "r");
int i = 0, j = 0;
const char* tok;
while (fgets(line, 4098, file) && (i < row))
if (i == row)
fprintf(stderr, "\nRow: %d, Column: %d, Value: Error", row, col);
char* rest = line;
while ((tok = strtok_s(rest, ",", &rest)))
if (j == col)
//fprintf(stderr, "\nRow: %d, Column: %d, Value: %s", row, col, tok);
This function is used to initialize the parameter for all the application based on
the traffic type
_declspec(dllexport) int fn_NetSim_Application_Init(struct stru_NetSim_Network *NETWORK_Formal,
STEP 5: Right-click on the Application module in Visual Studio Solution Explorer, and select Rebuild to update NetSim Application binaries as per the modifications done.
STEP 6: Place the log file samplesEEG.csv in NetSim binary folder in <NetSim_Installation_Directory>/bin folder (Right-click on NetSim shortcut in desktop and select Open file location option to reach this path).
STEP 7: Import the attached network configuration into NetSim using the Import Experiment option available in the Open Simulation menu of NetSim Home Screen. Open the imported network configuration in NetSim.
(Parameters configured in the sample config file: Zigbee_ACK_Request Enabled in Datalink layer of sensors and Lowpan gateway, Application_End_Time is set to 10s in every application)
STEP 8: Run Simulation for 50 Seconds. Simulation time is set to 50 seconds as the log file contains entries sufficient for 50 seconds of simulation with an interval of 4 Milliseconds.
STEP 9: After the simulation, the packet capture log files associated with each sensor node can be accessed under the packet capture drop-down as shown below:
STEP 10: In the Wireshark logs the packet payload (Data) will contain the readings obtained from the log file during the simulation as shown below:
Abdomen Respiration Sensor:
The above screenshot highlights the first reading from the ABDO_RES sensor and ECG sensor during the simulation, which can be related to the log file discussed above.
NetSim IoT module overview - https://tetcos.com/iot-wsn.html
NetSim IoT module documentation - https://tetcos.com/downloads/v13.1/IOT-WSN.pdf