Using the Consentium IoT Public MQTT Broker
This guide provides developers with the necessary information to connect to the Consentium IoT public MQTT broker. Our broker is designed to facilitate lightweight, real-time data exchange for your IoT projects, including those utilizing our proprietary hardware such as the Edge Dalton board.
Connection Details
Broker Address:
broker.consentiumiot.comPort:
1883(Non-secure TCP)Protocol: MQTT (Message Queuing Telemetry Transport)
Python Implementation
To interact with the broker in Python, we recommend using the paho-mqtt library.
Prerequisites
Install the library via terminal:
Bash
pip install paho-mqttExample Code
Python
import paho.mqtt.client as mqtt
import time
# Broker settings
BROKER = "broker.consentiumiot.com"
PORT = 1883
TOPIC = "consentium/test/topic"
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to Consentium Broker")
client.subscribe(TOPIC)
else:
print(f"Failed to connect, return code {rc}")
def on_message(client, userdata, msg):
print(f"Message received on {msg.topic}: {msg.payload.decode()}")
# Setup client
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
# Connect and loop
client.connect(BROKER, PORT, 60)
client.loop_start()
# Publish a test message
client.publish(TOPIC, "Hello from Consentium IoT!")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
client.loop_stop()ESP32 Implementation
For ESP32 development, the PubSubClient library is the standard choice for handling MQTT communication.
Prerequisites
Ensure the ESP32 Board Support is installed in your Arduino IDE.
Install the PubSubClient library via the Library Manager.
Example Code
C++
Best Practices
Client IDs: Always use unique Client IDs for each device. Using
WiFi.macAddress()is a reliable way to ensure uniqueness for ESP32 devices.Payloads: While our broker supports raw strings, we recommend using JSON format for structured data, ensuring you follow schema requirements (e.g., using
true/falsefor boolean feature states).QoS: Use QoS 0 for telemetry data to maintain low latency, and QoS 1 if message delivery guarantees are critical for your application.
Non-blocking: Keep your
loop()functions non-blocking to ensure the MQTT client can maintain its connection heartbeats.
Last updated