Commit 3fd7b82e authored by chrissi^'s avatar chrissi^

MQTT repub with testing values for the iSpindel

Signed-off-by: chrissi^'s avatarChris Fiege <>
Pipeline #988 failed with stages
#!/usr/bin/env python3
def makeNow(value):
Takes a byte-array and re-formates the value as collectd value.
The value is marked to be <now> without further timestamp.
return "N:{}".format(value.decode())
# mapping is a list of tupels with the mappings to do:
# old_topic, new_topic, callable
mapping = [
("ispindel/iSpindel_S0/tilt", "collectd/iSpindelS0/tilt/gauge", makeNow),
("ispindel/iSpindel_S0/temperature", "collectd/iSpindelS0/temperature/temperature", makeNow),
("ispindel/iSpindel_S0/battery", "collectd/iSpindelS0/battery/gauge", makeNow),
("ispindel/iSpindel_S0/gravity", "collectd/iSpindelS0/gravity/gauge", makeNow),
("ispindel/iSpindel_S0/RSSI", "collectd/iSpindelS0/RSSI/gauge", makeNow)
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
import mapping
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
for t in mapping.mapping:
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
for t in mapping.mapping:
if t[0] == msg.topic:
print("pub: {}".format(t[1]))
print("Resending as {} -> {}".format(t[1], t[2](msg.payload)))
client.publish(topic=t[1], payload=t[2](msg.payload))
except Exception as e:
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("", 1883, 60)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment