Node-RED: Use case: connect mailboxes
Seamlessly connect hundreds of mailboxes in a post office
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Node-RED cloud solution that provides a host of benefits, including:
- MQTT server included (Mosquitto).
- Full access to Node-RED admin UI.
- Node-RED Dashboard included.
- Unlimited and dedicated SMTP email server included.
- Effortless updates with just a click.
- Customisable domain name secured with HTTPS (for example, https://node-red.your-company.com).
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's Node-RED cloud hosting solution!
One of our customers manages post office boxes, hundreds of them, to be precise. The company aimed to notify their customers when they received new mail (not emails, but actual paper mail!). An IoT solution was crafted to achieve this, leveraging Node-RED, MQTT, and MongoDB, and it was implemented in just a few days. It is akin to an Amazon Dash, but tailored specifically for mail notifications. Here is how it was accomplished.
Details of the IoT device
The IoT device is elegantly simple. It is a compact black box, powered via USB, that incorporates a button and a red light. There is one device assigned to each mailbox.
When mail is received at the reception desk, it is placed into the corresponding mailbox, and the operator presses the button. The red light blinks for 15 seconds. If the operator presses the button again within this period, the notification is cancelled. If no action is taken within these 15 seconds, an email notification is dispatched to the customer.
Connecting the button to the world
Each button is equipped with an ESP8266, a WiFi-capable chipset. This WiFi connection facilitates the device's communication with the Internet.
An ESP8266 on a WEMOS D1 Mini board
The MQTT protocol was chosen for communication between the ESP8266 and the server. It is a lightweight protocol, ideal for IoT applications.
When the button is pressed, after a brief pause of 15 seconds, a message is sent to the server via MQTT. The server then identifies the corresponding email and sends a notification to the customer.
MQTT is perfect for IoT. Unfortunately, authentication is not activated by default, nor is encryption. We have observed many IoT platforms vulnerable to attacks, leading to private data leaks. Fortunately, when you start an MQTT instance on Stackhero, both authentication and encryption are activated, providing a fully secured solution out of the box.
Receiving button pushes and sending emails
To manage the button actions and dispatch notifications to users, Node-RED was chosen for data processing, with a MongoDB database to store user emails.
Node-RED is a graphical programming tool developed by IBM, ideal for this kind of task. It is easy to use, powerful, and highly extensible.
Thanks to Node-RED, our customer was able to create their entire backend in just a few hours!
When a mailbox button is pressed, the message is received by Node-RED via MQTT. Node-RED then locates the corresponding user in the MongoDB database, composes a new email, and sends it.
Node-RED flow: only 5 nodes are required to create the entire backend!
When you start a Node-RED instance on Stackhero, you get an MQTT server along with a dedicated email server, enabling you to send unlimited emails!
Creating the backoffice interface
The backoffice interface is utilised by post office operators. They can add a new button with an associated email or remove one as needed.
Node-RED includes an HTTP server, allowing the creation of HTML pages and APIs with minimal effort.
Node-RED backoffice flow
The entire backoffice interface was developed directly within Node-RED. It consists of an HTML page with authentication and an API with two routes. The first API route allows for the addition of a new button, while the second route facilitates the removal of an existing button.
Conclusion
Node-RED served as the cornerstone of this project. With Stackhero's instance providing a secured MQTT server and an email server right out of the box, the project was realised in just a few hours, something that traditional tools could not match.
Node-RED offers limitless possibilities. You can, for instance, connect it to any API or database and add external modules effortlessly (~2000 modules are available!).
If Node-RED piques your interest, you can start an instance on Stackhero in just 2 minutes: Node-RED.