This is an old revision of the document!
Gateway Simulation Module
The “Gateway Simulation Module” is a means to test the ability of the Gateway to correctly handle the various types of packets. The current simulation module includes the following packets: Heartbeat, Apple, Cranberry, Dragonfruit, and Bad Packet. If you wish to add more packets, follow the instructions below under “Adding New Packets.”
To test the Gateway with simulated packets, first download or clone the repository at https://github.com/scel-hawaii/data-gateway. For best results use a linux machine. Windows machines are incompatible.
Edited: 09/29/16
The following documentation denotes how to test packets with the packet_tester.py without hardware on a Linux machine.
Required materials:
- Configured packet_tester.py (used for testing incoming packets)
- See documentation regarding setup here
- test_data.py (used for writing preset packet to serial)
- socat (used for creating virtual serial ports)
- more info on socat here
Step 1: Install socat with the following command
sudo apt install socat
Step 2: Run socat with the following command
socat -d -d pty,link=./ttyV1,raw,echo=0 pty,link=./ttyV2,raw,echo=0
This command allows for the use of ttyV1 and ttyV2 as virtual serial ports
Step 3: Run the test_data.py program with the following command
python test_data.py
The program will then prompt the user to enter the serial port being used. You will enter the following string:
ttyV1
The program will begin writing fake packets to the serial port
Step 4: Run the packet_tester.py program with the following command
python packet_tester.py
The program will then prompt the user to enter the serial port being used. You will enter the following string:
ttyV2
The program will begin reading the packets and outputting the result to the terminal
Step 5: Congratulations you have successfully tested packets without hardware!
Adding New Packets
If at some point you need to add more packets to the simulation, here is how to do it.
Step 1: After cloning the data-gateway repository, move to the “test” directory
cd test
Step 2: Open the fake_packet.py file with the editor of your choice and make sure the “first block” of code is not commented out and the “second block” of code is commented out, if that is not the case make it so
Step 3: Run fake_packet.py while a weatherbox is transmitting the packets you wish to replicate, and an XBee is connected to your computer.
python fake_packet.py
Step 4: Reopen fake_packet.py and make sure the “first block” is now commented out and the “second block” is not commented out
Step 5: Run fake_packet.py again
python fake_packet.py
Step 6: The packet is now in the packet_data file. Now you can add the values from this file to the test_data.py script following the format existing there
NOTE: This process should be improved
Socat Usage
As shown in the diagram above, we are using socat to open virtual ports. One of the virtual ports is passed the packet data we would expect to be transmitted by a weatherbox. This data is passed to the virtual port by means of a pipe. This data is then passed to the second virtual port where it can then be accessed by the “Packet Collector” process. In our case this process is the packet_tester.py.