Register client IP-address as a trusted client
Only trusted clients may subscribe or connect
If your client IP changes, provide a range or set.
Flowity provides:
Credentials with client-id and a client-secret
Isolated topic for your organization
Client ID & client secret.
Effectively username/password
Host: broker.flowity.com
Port: 1883
Subscribe to all message streams
<HOST>/<ACCOUNTID>/+
Sensordata channel
<HOST>/<ACCOUNTID>/sensordata
Station Diagnostics channel
<HOST>/<ACCOUNTID>/diagnostics
Station Status+Audit channel
<HOST>/<ACCOUNTID>/status
from paho.mqtt import client as mqtt
import ssl
import os, time, logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
CLIENT_ID = "yourclientid"
CLIENT_SECRET = "yourclientsecret"
TOPIC = "yourorganizationtopic"
def on_connect(client:mqtt.Client, userdata, flags, reason_code, properties):
if reason_code.is_failure:
logger.error(f"Failed to connect: {reason_code}")
else:
logger.info("Connected to Flowity broker")
client.subscribe(TOPIC, qos=0)
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
if __name__ == '__main__':
print("Starting up...")
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
client.on_connect = on_connect
client.on_message = on_message
client.on_connect_fail = lambda client, userdata, response: logger.error(f"Failed to connect: {response}")
client.on_log = lambda client, userdata, level, buf: logger.debug(f"MQTT log: {buf}")
client.username_pw_set(CLIENT_ID, CLIENT_SECRET)
client.connect("broker.flowity.com", 1883, 60)
client.loop_start()
while True:
logger.debug("Listening on MQTT. Port 1883")
time.sleep(10)