Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,20 @@ def onLost(interface):
username = config["username"] if "username" in config else None
password = config["password"] if "password" in config else None

logger.info(f"Connected to MQTT {config['name']}")

callback_version = mqtt.CallbackAPIVersion.VERSION2
if client_id:
mqttc = mqtt.Client(client_id)
mqttc = mqtt.Client(callback_version, client_id)
else:
mqttc = mqtt.Client()
mqttc = mqtt.Client(callback_version)

if username and password:
mqttc.username_pw_set(username, password)

def on_connect(mqttc, obj, flags, rc):
logger.debug(f"Connected to MQTT {config['name']}")
def on_connect(mqtt, obj, flags, rc, props):
if rc.is_failure:
logger.error(f"Could not connect to MQTT {config['name']} [{rc}]")
else:
logger.info(f"Connected to MQTT {config['name']}")

def on_message(mqttc, obj, msg):
orig_packet = msg.payload.decode()
Expand Down Expand Up @@ -171,11 +173,18 @@ def on_message(mqttc, obj, msg):
logger.error(f"Hit an error: {e}", exc_info=True)
logger.debug(f"MQTT {config['name']} pipeline {pipeline} finished")

def on_publish(mqttc, obj, mid):
logger.debug(f"MQTT {config['name']}: on_publish: {mid}")

def on_subscribe(mqttc, obj, mid, granted_qos):
logger.debug(f"MQTT {config['name']}: on_subscribe: {mid}")
def on_publish(mqttc, obj, mid, rc, props):
if rc.is_failure:
logger.error(f"MQTT {config['name']}: Could not publish message ID: {mid} [{rc}]")
else:
logger.debug(f"MQTT {config['name']}: Published message ID: {mid}")

def on_subscribe(mqttc, obj, mid, rc_list, props):
for rc in rc_list:
if rc.is_failure:
logger.error(f"MQTT {config['name']}: Subscription failed [{rc}]")
else:
logger.debug(f"MQTT {config['name']}: Subscribed to topic [{rc}]")

mqttc.on_message = on_message
mqttc.on_connect = on_connect
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ haversine
meshtastic
requests
pyyaml
paho-mqtt
paho-mqtt >= 2.0.0
jwcrypto
nostr
nostr