Polling a device from LUUP, trying to get the "status" of the poll

Reposting
Hello, I’m trying to Poll a device in a Scene, but I also need to get the result of the poling (Successful, Error, Aborted, WaitingForCallback etc…)
I’v tried 2 different approach without success, my first try:…

local zErrNbr = 0
local zErrMsg = ""
local zJobNbr = 0
local zArgumt = {}
local zDevice = 39
local zJobSta = 0
local zJobMsg = ""

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action("urn:micasaverde-com:serviceId:HaDevice1","Poll",{},zDevice)  
print (zErrNbr)
print (zErrMsg)
print (zJobNbr)
print (zArgumt)

zJobSta, zJobMsg = luup.job.status(zJobNbr, zDevice)
print (zJobSta)
print (zJobMsg)

…this code below always returns me the code 1 (Polling node ie.: polling in progress I guess)
[tt]
zErrNbr = 0
zErrMsg = “”
zJobNbr = 578
zArgumt = table: 0x1a9cdb0
zJobSta = 1
zJobMsg = “Polling node”
[/tt]
I also tried to add a few “sleep” and call the [tt]luup.job.status(zJobNbr, zDevice)[/tt] a few times but always the code 1.

So I then tried the following:

local zErrNbr = 0
local zErrMsg = ""
local zJobNbr = 0
local zArgumt = {}
local zDevice = 39
local zJobSta = 0
local zJobMsg = ""
local zluljob = {}

function zJobStatus(zluljob)
   print ("device #" .. zluljob.device_num)
   print ("status " .. zluljob.status)
   print ("name " .. zluljob.name)
   print ("type " .. zluljob.type)
   print ("notes " .. zluljob.notes)
end

luup.job_watch("zJobStatus")

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action("urn:micasaverde-com:serviceId:HaDevice1","Poll",{},zDevice)
print (zErrNbr)
print (zErrMsg)
print (zJobNbr)
print (zArgumt)

but I get a Runtime error: Line 18: attempt to call field ‘job_watch’ (a nil value) which is the line for LUUP_JOB_WATCH
I also tried to call the function like this luup.job_watch(“zJobStatus”,zDevice) but I got the same error.

Anyone has any idea? is what I’m attempting even feasible? if yes, any help would be appreciated

Thx
Claude

PS.: I’m doing this because I have 2 devices (1 thermostat and 1 heat-pump switch) that sometimes “lose” communication with my vera, and I then have to manually reset the devices… so I am trying to setup a scene that will run every few hours or so, and will attempts to poll these 2 devices, and if the poll fails, then I will send me an Alert on my phone So that I go check the devices with my own eyes and reset the breaker if necessary)

Reposting:
Reposting
Hello, I’m trying to Poll a device in a Scene, but I also need to get the result of the poling (Successful, Error, Aborted, WaitingForCallback etc…)
I’v tried 2 different approach without success, my first try:…

[code]local zErrNbr = 0
local zErrMsg = “”
local zJobNbr = 0
local zArgumt = {}
local zDevice = 39
local zJobSta = 0
local zJobMsg = “”

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”,“Poll”,{},zDevice)
print (zErrNbr)
print (zErrMsg)
print (zJobNbr)
print (zArgumt)

zJobSta, zJobMsg = luup.job.status(zJobNbr, zDevice)
print (zJobSta)
print (zJobMsg)[/code]…this code below always returns me the code 1 (Polling node ie.: polling in progress I guess)

zErrNbr = 0
zErrMsg = “”
zJobNbr = 578
zArgumt = table: 0x1a9cdb0
zJobSta = 1
zJobMsg = “Polling node”

I also tried to add a few “sleep” and call the luup.job.status(zJobNbr, zDevice) a few times but always the code 1.

So I then tried the following:

[code]local zErrNbr = 0
local zErrMsg = “”
local zJobNbr = 0
local zArgumt = {}
local zDevice = 39
local zJobSta = 0
local zJobMsg = “”
local zluljob = {}

function zJobStatus(zluljob)
print (“device #” … zluljob.device_num)
print ("status " … zluljob.status)
print ("name " … zluljob.name)
print ("type " … zluljob.type)
print ("notes " … zluljob.notes)
end

luup.job_watch(“zJobStatus”)

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”,“Poll”,{},zDevice)
print (zErrNbr)
print (zErrMsg)
print (zJobNbr)
print (zArgumt)[/code]but I get a Runtime error: Line 18: attempt to call field ‘job_watch’ (a nil value) which is the line for LUUP_JOB_WATCH
I also tried to call the function like this luup.job_watch(“zJobStatus”,zDevice) but I got the same error.

Anyone has any idea? is what I’m attempting even feasible? if yes, any help would be appreciated

Thx
Claude

PS.: I’m doing this because I have 2 devices (1 thermostat and 1 heat-pump switch) that sometimes “lose” communication with my vera, and I then have to manually reset the devices… so I am trying to setup a scene that will run every few hours or so, and will attempts to poll these 2 devices, and if the poll fails, then I will send me an Alert on my phone So that I go check the devices with my own eyes and reset the breaker if necessary)

I could use something like this to reset my system when a serial devices loses communications, did you ever get it figured out?

I could also use this function (or any function that would alert me when an Aeon HEM has frozen - I use it to monitor a sump pump). I don’t know anything about programming but came across these:

[ul][li]Topic: luup.call_action return values - http://forum.micasaverde.com/index.php?topic=22975.0[/li]
[li]http://wiki.micasaverde.com/index.php/Luup_Requests#jobstatus[/li]
[li]Topic: forcing polling - http://forum.micasaverde.com/index.php/topic,6437.msg39587.html#msg39587[/li]
[li]Luup plugins <run/job/incoming/timeout> - http://wiki.micasaverde.com/index.php/Luup_Plugins_ByHand#.3Crun.2Fjob.2Fincoming.2Ftimeout.3E[/li][/ul]

Sorry - wish I could actually contribute something.

Hi guys,

yes and no. I think I did find the proper syntax (below)…[code]local zDevice = 9999 – ← put your device number here
local zErrNbr = 0
local zErrMsg = “”
local zJobNbr = 0
local zArgumt = {}
local zJobSta = 0
local zJobMsg = “”

function zTest_poll(zJobNum)
zReturnCode, zReturnMessage = luup.job.status(zJobNum,zDevice)

if zReturnCode == 0 then
	luup.call_timer("zTest_poll", 1, "10",  " " , zJobNum)   -- still POLLING?, try to get result again in 10 seconds /over and over until???
elseif zReturnCode == 4 then
	-- the POLLING of this device was successful... so nothing to do?
else
	-- the POLLING of the device seems to have failed??? Should do something here, like send an alert?!?!?
end

end

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”,“Poll”,{},zDevice) – sending the POLL command
luup.call_timer(“zTest_poll”, 1, “10”, " " , zJobNbr) – wait 10 seconds and try to get the result of the POLLING
[/code]
…which works fine when I paste it in [Test Luup code (Lua)] but I didn’t have time to implement it yet in a recurring scene, so I am not sure if it requires more fine tuning.

If you do give it a try a decide it needs improvements, please post your code change here for me

Thx
Claude

This does not work for me. Perhaps it’s the device I am attempting to poll but I always get a return of NIL in the luup code no matter the job status. I want to get the status of an alarm plugin and if no successful poll is possible then reboot Vera. Any suggestions?

[code]local zDevice = 18 – ← put your device number here
local zErrNbr = 0
local zErrMsg = “”
local zJobNbr = 0
local zArgumt = {}
local zJobSta = 0
local zJobMsg = “”

function zTest_poll(zJobNum)
zReturnCode, zReturnMessage = luup.job.status(zJobNum,zDevice)

if zReturnCode == nil then
	luup.call_timer("zTest_poll", 1, "10",  " " , zJobNum)   -- still POLLING?, try to get result again in 10 seconds /over and over until???
elseif zReturnCode == 4 then
	print ("4")-- the POLLING of this device was successful... so nothing to do?
    elseif zReturnCode == -1 then
	print ("-1")-- the POLLING of this device was successful... so nothing to do?
else
	os.execute( 'reboot' )-- the POLLING of the device seems to have failed??? Serial connection lost, REBOOT!
end

end

zErrNbr, zErrMsg, zJobNbr, zArgumt = luup.call_action(“urn:futzle-com:serviceId:CaddxNX584Security1”,“ZoneNameScan”,{Zone=1},zDevice) – sending the POLL command
luup.call_timer(“zTest_poll”, 1, “10”, " " , zJobNbr) – wait 10 seconds and try to get the result of the POLLING
[/code]

First you need to check if the device that you are trying to poll supports the Poll action. I’ll save you the trouble of asking on the plugin’s forum: the Caddx plugin does not respond do the Poll action. I think you knew this because you changed the service ID and action name to something that the plugin responds to. While I believe that you can make this work, because you are no longer using the HaService1/Poll action it’s no longer a big-P “Poll” in the Vera sense but a little-p “poll” in the generic sense of the word.

I’ve had zero experience calling the Luup job functions. The plugin itself does it through the HTTP interface, which “should” be the same as the Lua interface. That said, I’ve seen cases where a Z-Wave device behaves differently in Vera job control than a non-Z-Wave device. Just because the original code works for a Z-Wave device, there’s no guarantee that it’s correct for a device that runs as a Luup plugin.

Copious amounts of logging values to the Luup log, and watching what the plugin logs to the Luup log, will probably pinpoint the true situation. You will not only be debugging your own code but you might be probing the limits of the Vera job control API for plugin devices in general.

Futzle, as always, thanks for your generous sharing of knowledge! I have had some success polling the event lot of the plugin but my issue has always been getting the result of that job in order to determine if the NX8 is still responding on the serial line. I never get much time to really dive in deep into all of this due to my work travel schedule, but if I ever figure it out I’ll be sure to share. For now I would probably be better off picking up a new USB to serial adapter and cable, just to rule out those items as a cause of dropped communications. One other thing I noted this week was that I have a setting of 38400 on my baud rate instead of default (which I assume is 9600) so I may change that back to standard and see if it improves. The plugin loses communication with the serial device about once a month and can usually be corrected with a reboot. What prompted me to take another stab at a fix was that I accidentally set my alarm off last week, and while everything performed exactly as it should for the alarm event I noticed 5 minutes after the event that Vera had lost serial comms with the device.