Close

The MQTT Server

A project log for Mailbox Sensor

I'm tired of walking the whole way to my mailbox to see if there is mail in it, so technology comes to the rescue

kevin-kesslerKevin Kessler 06/19/2019 at 01:290 Comments

A full discussion of the MQTT server is an entire project itself, but some background is necessary to understand its function in this system.

The primary purpose of this system is to close my garage door if I leave it open for more than 10 minutes, but it is a victim of scope creep. This MQTT server is a Raspberry Pi Zero W, in a 3D printed case. It contains a ring of WS2812B RBG LEDs, for eye candy, a camera, a PIR motion sensor, an ambient light sensor, temperature sensor and hall sensors to detect the position of the garage door. The software is written in many Python modules which hang off an MQTT server, and MQTT messages provide the interprocess communication. The architecture is like Node Red for Python, without the complicating GUI.

So the basic application flow looks something as follows: The garage door starts to open, which triggers one of the hall switches. The GPIOInput Module sends an MQTT message indicating that, which the logging module picks up and logs, and the LED controller module picks up and displays the "Door Opening" pattern. When the door completely opens, another hall sensor detects that, and another message is sent, which triggers the controller modules to start a timer, another log message, and a different led pattern. The source code for this project is here: https://github.com/kevinkessler/GarageServerPi

In this project, these modules will be used to monitor the ESP32 base station. Log messages will be sent from the ESP32 to the logging module and to loggly.com. The values returned from proximity sensor and the rotary sensor will be sent to thingspeak.com through the thingspeak module so I can find the best values indicating mail in the box, and the position of the flag.

An important function that the this MQTT system provides is heartbeat monitoring. The MQTT server logs a heartbeat to loggly.com every 10 minutes. In Amazon AWS, I have a lambda function that runs every 20 minutes, and queries loggly for the heartbeat log messages. If it goes 40 minutes without seeing a heartbeat message, it sends a text message notifying me of a problem. This entire process can be run totally free in AWS lambda since it is such a light process. This same system will be used to monitor heartbeats from the basestation and instrumented mailbox.

The connection between the ESP32 and MQTT server is SSL configured to use a pre-shared key. This is a simpler approach to encryption as opposed to the full SSL stack, at almost no cost, since full certificate validation in a private network system like this doesn't really exist anyway.

Discussions