0

lwt stopped working for me?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

lwt stopped working for me?

by ds18s20 on Wed Jun 08, 2016 1:07 pm

Hi

I've been using AIO for few months now, before lwt used to work and now lwt stopped working for me? Can anyone confirm that lwt is working?

I simply can't make it to publish lwt, I kill power to my nodes, nada. Nothing has changed in my code in the way how lwt is registered when the node starts up.

Thanks
~B

ds18s20
 
Posts: 35
Joined: Tue Jan 24, 2012 7:45 pm

Re: lwt stopped working for me?

by uniontownlabs on Fri Jun 24, 2016 3:23 pm

i was able to get the last will to work during testing. here are a couple things that might help:

  • the last will topic must match the normal IO MQTT topic format for feeds or group publishes
  • last will is only sent if the client doesn't disconnect cleanly by sending the MQTT disconnect packet

here is some node.js code you can use to test locally if you would like to confirm that it works with your account:

Code: Select all | TOGGLE FULL SIZE
var mqtt = require('mqtt');

var client = mqtt.connect({
  username: 'uniontownlabs',
  password: 'xxxxxxxxxxxxxxxxxxxx',
  host: 'io.adafruit.com',
  will: {
    topic: 'uniontownlabs/feeds/test', // note the valid IO topic format for last will
    payload: 'dead'
  }
});

client.on('connect', function() {
  // exit early without cleanly disconnecting
  process.exit();
});

uniontownlabs
 
Posts: 110
Joined: Wed Dec 17, 2014 10:56 pm

Re: lwt stopped working for me?

by ds18s20 on Mon Jun 27, 2016 12:45 pm

Thanks for the feedback and sample code. I'm still unable to "make lwt fire" but I've noticed that in your example there isn't an option to auto-reconnect while in my LUA code I specifically set auto-reconnect to deal with random drops.

Could it be that auto-reconnect disabled lwt? If yes then what I am observing would be expected?

I assure you that my nodes exit VERY uncleanly.. I pull the power...

Thanks
~B

ds18s20
 
Posts: 35
Joined: Tue Jan 24, 2012 7:45 pm

Re: lwt stopped working for me?

by uniontownlabs on Mon Jun 27, 2016 12:57 pm

could you post some lua example code that demonstrates the issue so i can see how things are setup?

uniontownlabs
 
Posts: 110
Joined: Wed Dec 17, 2014 10:56 pm

Re: lwt stopped working for me?

by ds18s20 on Mon Jun 27, 2016 1:55 pm

Totally, here's my test node. All it does is it monitors a topic and flips the on-board LED on or off and also it publishes a "ping" as a feedback that it has seen and executed the command:

Code: Select all | TOGGLE FULL SIZE
m = mqtt.Client(wifi.sta.getmac(), 60, "123456789", "12345678912345679812345798")

gpio.mode(0,gpio.OUTPUT)
gpio.write(0,gpio.HIGH)

m:lwt("123456789/feeds/lwt", "offline node "..wifi.sta.getmac(), 0, 0)
m:on("connect", function(con) print("CONNECTED") end)
m:on("offline", function(con)
print("Lost connection. RE-connecting to MQTT...")
end)

-- on publish message receive event
m:on("message", function(conn, topic, data)
  print(topic .. ":" ) 
  if data ~= nil then
    print(data)
    --tmr.stop(2)
    m:publish("123456789/feeds/boot","**** ping **** ".. wifi.sta.getmac() .. " -- " .. data,0,0,function(publish)
    end)
    if data == "ON" then gpio.write(0,gpio.LOW)   end
    if data == "OFF" then gpio.write(0,gpio.HIGH) end
    end
end)

function mqttconnectfunction()
tmr.alarm(2,15000,1,function() print ("Connectioin timer kicked...")
m:close();
m:connect("io.adafruit.com", 1883, 0, 1, function(connect)
print("m:connect says it is connected")
tmr.stop(2)
m:subscribe("123456789/feeds/Butt222",1,function(subscribe)
print("m:subscribe says it is subscribed")
m:publish("123456789/feeds/boot","booting node " .. wifi.sta.getmac(),0,0,function(publish)
print("m:publish says it is published") end)
end) end) end)
end

pcall(mqttconnectfunction)

ds18s20
 
Posts: 35
Joined: Tue Jan 24, 2012 7:45 pm

Re: lwt stopped working for me?

by uniontownlabs on Mon Jun 27, 2016 2:22 pm

you could try dropping the keep-alive from 120 to 5 and disabling the auto-reconnect to test if lwt is working. most likely the reconnect is happening before the keep-alive expires.

uniontownlabs
 
Posts: 110
Joined: Wed Dec 17, 2014 10:56 pm

Re: lwt stopped working for me?

by ds18s20 on Mon Jun 27, 2016 5:38 pm

Hi uniontownlabs,

Whether you did something or the thing is just afraid.. LOL it is now working just as it was few weeks ago. I tested with NO auto-reconnect and low timeout and discovered it was working fine, then tested with auto-reconnect and the original timeout and it still worked so my guess is that it would've worked with auto-reconnect right off the bad, I just didn't do that first thing today after your reply.

So in summary, I am back in biz with lwt.. Thanks!

~B

ds18s20
 
Posts: 35
Joined: Tue Jan 24, 2012 7:45 pm

Please be positive and constructive with your questions and comments.