35 lines
1.2 KiB
Python
Executable File
35 lines
1.2 KiB
Python
Executable File
import os
|
|
import paho.mqtt.client as mqtt
|
|
|
|
import logging
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
# If you want to use a specific client id, use
|
|
# mqttc = mqtt.Client("client-id")
|
|
# but note that the client id must be unique on the broker. Leaving the client
|
|
# id parameter empty will generate a random id for you.
|
|
mqttc = mqtt.Client()
|
|
lastmessage = ""
|
|
|
|
def onConnect(client, userdata, flags, rc):
|
|
print("Connected with result code "+str(rc))
|
|
mqttc.subscribe("/sensors/spaceschalter/status", 0)
|
|
|
|
def messageReceived(client, userdata, message):
|
|
print("received topic" + str(message.topic) + "with payload:" + str(message.payload))
|
|
global lastmessage
|
|
if (str(message.payload) == lastmessage):
|
|
print("already got message " + lastmessage + ", skipping.")
|
|
return
|
|
lastmessage = str(message.payload)
|
|
print("sending Message via signal…")
|
|
os.system("signal-cli --config /home/christoph/.local/share/signal-cli/ -u +491639709611 send -m \"Machbar: %s\" -g 4itR+98YIW1Xc4BJwKKoew==" % message.payload.decode("utf-8"))
|
|
|
|
mqttc.username_pw_set("christoph","dNppWZ2nukh+RQ")
|
|
|
|
mqttc.on_message = messageReceived
|
|
mqttc.on_connect = onConnect
|
|
mqttc.connect("ccc-p.org", 1883, 60)
|
|
|
|
mqttc.loop_forever()
|