Author: Cosmin-Răzvan Vancea (SAS1)
If the flash memory is empty or the user holds down the SETUP button while FireAlarm is starting up, then the device will switch to the configuration mode:
192.168.4.1
(the IP of the FireAlarm on the local hotspot network);REST APIs implemented on the microcontroller:
GET /api/v1/access-points
: returns a the list of Wi-Fi Access Points accessible to the FireAlarm device;GET /api/v1/settings
: returns the current configuration of the FireAlarm device;POST /api/v1/settings
: pushes a new configuration to the FireAlarm device;POST /api/v1/switch-mode
: forces the device to switch to the normal mode;POST /api/v1/ping
: echoes back the request. Useful to determine whether we are connected to a FireAlarm device.The project is comprised of three main software components:
We will only focus on the microcontroller software.
The code is split into multiple “modules”:
SettingsManager
: manages the configuration dataNetManager
: manages the Wi-Fi operation mode (station or client). Branches down further in two modules:NetClient
: the FireAlarm device acts as a clientNetConfigAP
: the FireAlarm device acts as a station (“Hotspot”)(Flame|Gas)Sensor
: abstraction layer for the sensorsLed
: abstraction layer for a 4-pin RGB ledBuzzer
: abstraction layerFireAlarm
: puts together the components above; responsible for the general logic of the program.Moreover, the following 3rd-party libraries are used:
During a network operation, the device might appear unresponsive due to the main loop()
being busy processing the network request. In order to increase the responsiveness of the FireAlarm device, interrupts are being used: each time a sensor value changes, an interrupt is raised. The interrupt handler marks the event for further processing in the main loop and changes the state of the buzzer (on/off) so that the alarm appears to be responsive to the nearby people.
The server software is written in Flask. It is basically a web server that:
The alarm notification is served though PushBullet. For the notification mechanism to actually work, the user must associate a PushBullet token to their FireAlarm GUID. This operation can be done though the web interface.
Written in Java. It is basically a client that consumes both the API provided by the ESP32 (when in configuration mode) and the API provided by the remote web server.
The app provides a step-by-step tutorial on how to configure the FireAlarm. After the configuration is done, the app stores locally the assigned GUID of the FIreAlarm device so that the users are not needed to remember the GUID themselves.
It was a challenging and productive experience because I had to approach the project from three different perspectives: a local system that collects data from sensors; a remote system that receives and processes measurements from multiple devices; and a hybrid system that must communicate to both the local system (through a local network/“Hotspot”) and to the remote system (through the Internet).