how to connect hmi divice to cloud server use by mqtt
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
An MQTT broker is required to facilitate communication between the HMI device and the cloud server. You can use cloud-hosted brokers like Mosquitto, AWS IoT, Google Cloud IoT, or Azure IoT Hub, depending on your requirements.
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients
Once installed, configure the Mosquitto MQTT broker. Edit /etc/mosquitto/mosquitto.conf
to allow remote connections.
sudo nano /etc/mosquitto/mosquitto.conf
Add the following lines:
listener 1883 # Default MQTT port for non-SSL communication
allow_anonymous true # For testing (disable in production)
Restart Mosquitto:
sudo systemctl restart mosquitto
Next, configure your HMI device to send data using MQTT. Many modern HMIs support MQTT out of the box. Here’s the general process:
hmi/status
or subscribe to commands sent from the cloud via cloud/commands
.To interact with the HMI from the cloud, you’ll need to set up an MQTT client on your cloud server or application to send or receive messages. You can use libraries like Paho MQTT in Python, mqtt.js for Node.js, or any other MQTT client library depending on your development environment.
Install the Paho MQTT client:
pip install paho-mqtt
Create a simple Python script to publish or subscribe to the HMI’s MQTT topics:
import paho.mqtt.client as mqtt
# Define the callback function
def on_message(client, userdata, message):
print(f"Received message: {message.payload.decode()} on topic {message.topic}")
# Create an MQTT client instance
client = mqtt.Client()
# Assign the callback function
client.on_message = on_message
# Connect to the cloud MQTT broker (Mosquitto)
client.connect("your-cloud-server-ip", 1883, 60)
# Subscribe to a topic (e.g., commands sent to HMI)
client.subscribe("cloud/commands")
# Publish a message to the HMI
client.publish("hmi/status", "Status: Online")
# Start the client loop
client.loop_forever()
Once the cloud server and the HMI device are both connected to the MQTT broker:
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.