Skip to content

Commit 63cafef

Browse files
authored
Merge pull request #4 from seanauff/paho-mqtt-v2-upgrade
Paho mqtt v2 upgrade
2 parents 64dc40f + a0bbbe5 commit 63cafef

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ RUN pip install paho-mqtt wakeonlan
66

77
ADD WOL-proxy.py .
88

9-
ENTRYPOINT ["python", "./WOL-proxy.py"]
9+
ENTRYPOINT ["python", "-u", "./WOL-proxy.py"]

WOL-proxy.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
#print("All env vars read.")
1717

1818
# The callback for when the client receives a CONNACK response from the server.
19-
def on_connect(client, userdata, flags, rc):
20-
print(f"Connected to broker at {MQTT_BROKER_HOST}:{MQTT_BROKER_PORT} with result code {rc}: "+mqtt.connack_string(rc))
19+
def on_connect(client, userdata, flags, reason_code, properties):
20+
print(f"Connected to broker at {MQTT_BROKER_HOST}:{MQTT_BROKER_PORT} with reason code {reason_code}: "+mqtt.connack_string(reason_code))
2121

2222
client.publish(MQTT_TOPIC_PREFIX+"/status",payload="Online",qos=1,retain=True)
2323

2424
# subscribe to command topic
2525
client.subscribe(MQTT_TOPIC_PREFIX+"/command", MQTT_QOS)
2626

27-
def on_subscribe(client, userdata, mid, granted_qos):
28-
print(f"Subscribed to commands on topic \"{MQTT_TOPIC_PREFIX}/command\" with QOS {granted_qos[0]}.")
27+
def on_subscribe(client, userdata, mid, reason_code, properties):
28+
print(f"Subscribed to commands on topic \"{MQTT_TOPIC_PREFIX}/command\" with QOS {reason_code[0]}.")
2929
print(f"Wake-On-LAN proxy service started.")
3030

31-
def on_disconnect(client, userdata, rc):
32-
if rc != 0:
33-
print(f"Unexpected disconnection from broker (RC={rc}). Attempting to reconnect...")
31+
def on_disconnect(client, userdata, flags, reason_code, properties):
32+
if reason_code != 0:
33+
print(f"Unexpected disconnection from broker (RC={reason_code}). Attempting to reconnect...")
3434

3535
# callback for when the client receives a message on the subscribed topic
3636
def on_message(client, userdata, message):
@@ -43,7 +43,7 @@ def on_message(client, userdata, message):
4343
print(f"Message payload has invalid mac address format!")
4444

4545
# set up mqtt client
46-
client = mqtt.Client(client_id=MQTT_CLIENT_ID)
46+
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2,client_id=MQTT_CLIENT_ID)
4747
if MQTT_USERNAME and MQTT_PASSWORD:
4848
client.username_pw_set(MQTT_USERNAME,MQTT_PASSWORD)
4949
print("Username and password set.")

0 commit comments

Comments
 (0)