Simulation - Kvel2D/ecs193-wireless-sensor-network GitHub Wiki

The simulation is useful for determining RX_RATE and TX_RATE for a particular average packet age that you desire. It can also be used for balancing packet age and power usage but current deployment doesn't use batteries, so this feature is not fully developed.

How to use the simulation

Set SIM_TIME to how long you want the simulation to run for. Start with a low number to see how long the simulation takes to run on your computer. Then increase this number to get more accurate results.

Set PACKET_PERIOD to match it's value in the Arduino code.

TX_TRANSMIT_TIME, TX_ACK_TIMEOUT, RX_ACK_TIME, RX_RECEIVE_TIMEOUT are by default set to what they are in the Arduino code, if you change any of these times you also need to change them in the simulation. Note that not all of these values correspond one-to-one to some variable in Arduino code, TX_TRANSMIT_TIME for example is an estimation of how long it takes for a node to transmit a packet(without waiting for ack).

Next, go to simulate() function. Here you need to setup nodes. This is done by adding lines of:
env.process(run(env, nodes, id, parent_id, has_sensor(optional))
This should be a straight translation of the tree structure that is in tree_data.h of your Arduino code. Make sure that all id's are correct and there are no missing nodes or extra nodes.

You also need to set gateway_node to whatever node is the gateway.

Finally, you can pick which info you want to be written to the results file. There are two functions for this purpose:
write_packet_stats() - will output min, max and average ages of packets that come from a particular node. write_awake_stats() - will output awake ratios of a particular node.

After this the general process is finding the rates that are safely below your desired average packet age. Recommended procedure is to set SIM_TIME to 1 hour and then try different rates until you get close to desired packet age. Then switch to 24 hours and fine tune rates more. Finally switch to very long SIM_TIME and confirm that the average packet age is consistent over a long duration.

Note that this simulation doesn't mirror the real Arduino behavior completely.

  • It doesn't simulate multiple children interference accurately. This means that the resulting average packet ages are slightly lower than they will be in reality.
  • It doesn't simulate chaining. This means that real congested networks will perform slightly better,
  • Queue size is not limited like it is in Arduino code. This is to avoid stealthily dropping packets.
  • The awake ratios are purely time-based. Real Arduino boards use different amounts of power for transmitting and receiving, so you will need to factor this into your power usage calculations.
  • It simulates the network with the assumption that all links have perfect connection quality. In a real setup connection quality can be decreased by distance or obstacles.

In general the simulation average packet ages underestimate the reality by 10-20%.