Author: Tao Dekun, EMQX Cloud developer.
As a backend developer, I often have to run multiple JetBrains IDEs (Integrated Development Environments) at the same time, so I often face laptop overheating. I've tried a variety of cooling methods, from traditional fans to more advanced semiconductor cooling systems, but they all introduce new problems such as noise and power consumption.
Therefore, I designed an intelligent liquid cooling solution: by introducing an external water cooling system, leveraging the microcontroller ESP32, the MQTT server EMQX Cloud Serverless, and the containerized deployment platform Flyio to monitor and control the water temperature in real time. Here's a detailed description of the solution that we hope will inspire other IoT developers:
Author DIY IoT Intelligent Liquid Cooling System.
Technology selection
I wanted the system to be not only functional, but also reliable and efficient to ensure the stable operation of the water temperature monitoring system. Here's my pick of tech stacks::
esp32:Among the many options, the ESP32 microcontroller stands out for its cost-effective features due to its integrated Wi-Fi and Bluetooth capabilities. This chip provides powerful performance support for IoT projects at a manageable cost without sacrificing functionality.
DS18B20 Water Temperature Sensor:For temperature monitoring, the DS18B20 is my first choice because it provides accurate digital temperature readings and excellent water resistance. The sensor works in tandem with the ESP32 to ensure the accuracy and stability of the water temperature monitoring system.
emqx cloud serverless mqtt broker:Among the many messaging middleware, EMQX Cloud is favored for its high performance, reliability, and the Serverless MQTT service's ability to handle large numbers of concurrent connections and message routing, which are critical to ensuring smooth communication between devices.
Python and Flask:Python was chosen because of its expressiveness and rich library functions, while Flask was lightweight and highly flexible enough to accommodate rapid development and deployment, which was essential for rapid prototyping.
fly.io:fly.IO's globally distributed edge hosting service provides a unique platform for converting containers into micro-virtual machines. This not only speeds up the deployment of applications, but also dramatically reduces latency in data transfers, providing users with a near-real-time experience.
Project implementation
The implementation phase of a project is a process of turning an idea into a practical solution. In this process, the first step is to ensure the correct configuration of EMQX Cloud Serverless, then the integration of hardware, the development of back-end services, and finally the deployment and testing of the system.
Serverless MQTT broker configuration
EMQX Cloud Serverless provides free quotas that fully cover the required costs for our use case, which is one of the main reasons why I chose EMQX Cloud Serverless deployment. In addition, it supports Transport Layer Security (TLS) by default, which provides a strong encryption guarantee for our data transmission, ensuring the confidentiality, integrity and authentication of data during transmission, reducing the risk of data leakage or tampering.
Here are the steps to configure EMQX Cloud Serverless:
Create a serverless MQTT broker:
Log in to the EMQX Cloud console and navigate to"create deployment"Page.
Select"serverless"Deployment type, and configure the deployment as needed. For example, regions, spendlimits, etc.
Once you're done configuring, tap"create"button to automatically create a serverless MQTT broker.
Add Authentication Information:
After the MQTT broker is created, configure the authentication information to ensure that only authorized clients can connect to the broker.
Connection test with MQTTX:
*And install the MQTTX client (MQTTX: a full-featured MQTT client tool), and then test the connection to the MQTT broker with the authentication information configured earlier to make sure everything is working properly.
With the above steps, I successfully configured the EMQX Cloud Serverless MQTT Broker to provide a secure, reliable, and cost-effective messaging middleware for our project. Not only does it simplify the management and scaling of IoT infrastructure, but it also provides a good foundation for the project by ensuring the secure transmission of data with TLS support.
Hardware integration
In the project, we used an ESP32 microcontroller and a DS18B20 water temperature sensor to monitor the water temperature and send the data to the cloud. Through this integration, we have implemented a system that can monitor and transmit water temperature data in real time, efficiently and safely, while providing intelligent monitoring of the water cooling system.
Wi-Fi Connection Configuration:First, the ESP32 is configured to connect to the internet via Wi-Fi. This is done by setting the SSID and password for your Wi-Fi in **.
Sensor Initialization:We connected the DS18B20 water temperature sensor to the ESP25 via GPIO 32 and initialized the sensor in ** to set the resolution of the temperature reading.
Secure MQTT communication:Using the MQTT protocol, data is securely transferred through EMQX Cloud Serverless. We configured the details of the MQTT broker and used SSL TLS encryption to secure the data transmission.
Temperature data reading and sending:The system reads the water temperature every minute, formats the readings as JSON, and publishes them to the cloud via the MQTT protocol.
Develop backend services using Python and Flask
In this project, we built a backend service using Python and Flask to process the temperature data from ESP32 and display it on a web page. The entire backend is designed to process data efficiently, provide real-time feedback, and be easy to maintain. In this way, we built a back-end service that can both process data from IoT devices in real-time and provide a user-friendly interface. This not only strengthens the practicality of the project, but also provides a good basis for future expansion and optimization.
Configuration and MQTT integration:Our Flask app is configured with MQTT settings and uses the Flask MQTT library to communicate directly with MQTT. When a message is received from an EMQX ESP32 Telemetry topic, the backend processes and stores the data through specific functions.
Database management: Use the SQLite database to store temperature data, manage database connections through Flask's application context, and ensure secure storage and access to data.
Web interface and APIs: The backend provides a simple web interface and an API endpoint. The home page links to a page that displays a temperature graph, while the Data API endpoint returns temperature data for the most recent period.
System deployment
The deployment phase of the project is crucial, and we do this through docker and flyIO's configuration containerizes the Flask application and hosts it on Flyio。This process not only enables the deployment of Flask applications in the cloud, but also ensures that services are delivered quickly, securely, and efficiently. With flyWith the IO platform, applications can be easily scaled according to needs and enjoy a stable operating environment.
docker containerizationFirst, let's write a Dockerfile, using Python 38 as the base image and copy the app** to the container's app working directory. Then, install the necessary dependencies via pip, such as flask and flask-mqtt, and expose port 8080. cmd [ is automatically executed when the container starts"python", "app.py"] to run the flask app.
fly.ioConfiguration: In flyIn the toml file, we define how the application will run, including the application name, the main deployment region (e.g. Singapore), the build, and the mount point settings.
Mount point: Set a mount point to store database files to ensure the durability of data when the container is redeployed.
HTTP service configuration: Set the internal port to 8080, force https, start and stop policies, and set the minimum number of running machines.
Health checks: You can check the running status of the application by accessing the ping route periodically to ensure service stability.
Deploy the app
Createfly.ioApplications: Use the flyctl apps create command via flyIO's CLI tool to create a new app.
Deploy the app: Execute the flyctl deploy command in flyAutomatically build and deploy Docker container images on IO.
Verify the deployment: Once the deployment is complete, access flyThe URL of the application provided by IO to verify that the Flask application is running successfully.
Project Outcomes:
Real-time temperature monitoring system
Harnessing the power of the ESP32 microcontroller and the DS18B20 water temperature sensor, we designed and implemented a system that could monitor and regulate the temperature of the water cooling system in real time. Now, my laptop is no longer overheating due to the heat, it is able to run reliably, and I can enjoy a calm and comfortable working environment at any time, whether on the terrace of a café or at my desk at home.
Stable data transfer
With EMQX Cloud Serverless, we achieve the security and reliability of data transfer from ESP32 to the cloud. EMQX Cloud Serverless is a high-performance MQTT ** with low latency for real-time ingestion and processing of temperature data. This ensures that the system reacts quickly and remains operating efficiently.
Feature-rich web interface
The powerful combination of Python and Flask provides us with a clean and intuitive web interface that allows users to easily view real-time temperature data and historical temperature profiles. This not only improves the user experience, but also makes temperature monitoring more intuitive and easier to manage.
Globally distributed cloud deployment
With flyIO's globally distributed service, our Flask applications run efficiently in the cloud. This deployment method not only ensures high availability and stability of the application, but also greatly reduces the latency of data transmission, providing users with a near-real-time experience.
Summary and outlook
From the initial problem of overheating the laptop to the construction of a real-time water temperature monitoring system, this project fully demonstrates how modern IoT technology can help us solve real problems in life.
By integrating ESP32, DS18B20 water temperature sensor, EMQX Cloud Serverless MQTT broker, Python, Flask, and FlyIO cloud platform, we have succeeded in developing a system that is both practical and efficient. This system not only improves my work efficiency, but also provides an innovative solution to similar problems.
Readers who are interested in this project or want to dive deeper into the technical details can find the full and more implementation details in the MQTT client example for EMQX on GitHub. This library of resources is not only a treasure trove of learning and practice, but it may also inspire you to have new ideas and creativity for the Internet of Things and cloud computing.