An IoT Boilerplate for ESP
The Basic Idea is to provide a working Firmware for ESP, where one can manually define Inputs and Outputs. Additionally it provides an easy way of reconfiguration without the need to reflash via a webinterface.
An Input listens on a specific topic for incoming messages and executes the supplied callback function once a new message arrives.
They work the other way round. You implement a method, which is executed in loop(). When this method defines a String at msg, it is sent as message to the outputs topic. Optionally you can add a third parameter to the Output class. An interval in milliseconds in which the loop method should be executed. This defaults to 0.
In this small exmaple we define an Input ping and an Output pong. When we receive a message on topic ping, we send a reply on topic pong. And a heartbeat is sent every 3 minutes.
The topics for this example would be:
If the ESP is unable to connect to one of it’s configured APs it falls back to AP Mode. The user can then connect to the AP and reconfigure settings. [this feature is not yet implemented]
- add/delete WifiAPs (ssid, password)
- edit MQTT host, domain, topic
MQTT Topic Pattern
Each thing gets a unique MQTT Topic Base consisting of a domain and the ESP’s MAC Every Input and Output’s topic gets appended to this base.