All QNet Outstations run this Python application to handle connections to the MQTT Broker and interfacing with the onboard GPIO of the Raspberry Pi.
The MQTT broker disseminates messages between the server and Outstations.
There are two types of QNet model:
- Q-Lite – Is based on a Raspberry Pi Zero
- Q-Pro – Is based a Raspberry Pi 3B
Note
Q-Lite models must be configured to connect to the network wirelessly due to the lack of onboard physical network interface.
The Python application is agnostic of the hardware model and can be run on either type.
The default wiring of the GPIO devices is:
RED_LED: Pin 4GREEN_LED: Pin 11BUTTON_PIN: Pin 16RELAY_SWITCH: Unassigned
These pins are chosen because of their proximity to a ground pin, allowing for a 2x1 2.54 mm dupont connector to be wired to each IO device.
The RELAY_SWITCH output is provisioned for future use and currently serves no purpose.
- The application starts and the LED Controller and MQTT Client classes are both instantiated.
- The device connects to the broker to announce itself as online.
- The device enters the
IDLEstate and waits to receive commands from the server.
A system service should be configured to start the application automatically, after the network interface services (network.target) have started.
There are two message types (topics) that are used between Outstations and the Broker: status and command messages.
Status messages are always sent from an Outstation to the broker to announce connection or disconnections from the broker. Every Outstation on startup sends a connected status message and sets the LWT message to announce the disconnection on its behalf:
{
"state": "IDLE",
"online": true // or false
}Command messages are used to inform the system of a change in state. These messages are bidirectional however the only state command an Outstation would send is the READY command.
{
"state": "GO"
}Some Raspberry Pi Wi-Fi models put the Wi-Fi chip into power-saving mode after a few seconds of inactivity which can lead to noticeable delays when using QNet.
To check if Power Save Mode is enabled:
iw wlan0 get power_saveTo disable Power Save Mode:
sudo iw wlan0 set power_save offThis will improve latency across wireless QNet and make them more responsive.
A function is provided by default within the application to execute this command once the script starts.