Back-end Considerations
Progress continues according to the initial plan. It is now time to handle the data collected from the ESP32. Since the physical hardware has not yet arrived, I am continuing to rely on the Wokwi simulation.
To process the incoming data, I’ve chosen Spring Boot. It is a powerful framework with a broad ecosystem; specifically, I’m utilizing spring-integration-mqtt to manage the messaging. To maintain a history of the weather data, a database is essential.
Because the ultimate goal is to host this in the cloud, I need to be mindful of resource consumption and disk space. Since the schema only requires a single table with a few columns, using a full-scale DB like MySQL or PostgreSQL would be overkill—like using a heavy truck to deliver a single pizza. Instead, I’ve opted for a "lean" solution: SQLite.
To keep the database lightweight, I’ve implemented a housekeeping job using the @Scheduled annotation to purge records older than three days. While the final UI is still being decided, the simplest immediate solution for data visualization is sending updates to a dedicated Telegram chat. Finally, to ensure portability for cloud deployment, the entire back-end is containerized using Docker, including the Mosquitto MQTT broker.
Challenges
A primary challenge arose with networking: the Wokwi simulator cannot natively access a Mosquitto broker running on my local localhost. To bridge this gap, I used ngrok to create a publicly accessible tunnel to my local machine. This is a temporary workaround for local testing; once the back-end is migrated to the cloud and the physical hardware is in use, this will no longer be necessary.
Outcomes
You can find the configuration and source code at the links below:
Mosquitto Config: https://github.com/olyv/weather/tree/main/broker/config
Back-end Application: https://github.com/olyv/weather/tree/main/message-listener
And finally, a couple of screenshots of the setup in action:
Comments
Post a Comment