Processing Mosquitto topics
We have to deploy the deployment called process
using the mqttsubs
container image, which sends the data published in Mosquitto to a public or private Redis instance in the cloud layer. Let’s explore the code inside this container image:
import paho.mqtt.client as mqtt import os import redis import sys mqhost = os.environ['MOSQUITTO_HOST'] rhost = os.environ['REDIS_HOST'] rauth = os.environ['REDIS_AUTH'] stopic = os.environ['SENSOR_TOPIC'] def on_connect(client, userdata, flags, rc): client.subscribe(stopic) def on_message(client, userdata, msg): r = redis.StrictRedis(host=rhost,\ port=6379,db=0,password=rauth,\ decode_responses=True) r.rpush(stopic,msg.payload) client = mqtt.Client() client.on_connect = on_connect client.on_message...