I wrote an LWT test program but I dont seem to get my 'Last Will" to be triggered.
- Code: Select all | TOGGLE FULL SIZE
import time
import paho.mqtt.client as mqtt
import ssl
conn_flag = False
def on_connect(client, userdata, flags, rc):
global conn_flag
print("Connected")
conn_flag = True
def on_disconnect(client):
global conn_flag
print("Disconnected")
conn_flag = False
aio_username = 'AIO-MYUSERNAME-DELETED'
aio_password = 'aio_AIO-KEY-DELETED'
aio_feed = aio_username + '/feeds/connection'
client = mqtt.Client("Hello LWT world")
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.tls_set()
client.tls_insecure_set(True)
client.will_set(aio_feed, "dead", 1, True);
client.username_pw_set(aio_username, aio_password)
client.connect("io.adafruit.com", 8883, 10)
while True:
while not conn_flag:
client.loop_start()
print("Waiting to connect...")
time.sleep(1)
print("publishing...")
client.publish(aio_feed, "alive5")
time.sleep(10)
client.loop_start()
The feed is updated to 'alive5' every 10 seconds. That works fine. I then do a 'killall -9 python3' or just pull the plug from my RPI.
I expect the feed to get updated to 'dead' in the AIO Dashboard but it stays on 'alive5' forever.
I tried playing around with the QoS flags and retainer flag but no luck.
regards,
-t