We have moved at community.getvera.com

Author Topic: Polling a device from LUUP, trying to get the "status" of the poll  (Read 3485 times)

Offline fouclo62

  • Full Member
  • ***
  • Posts: 105
  • Karma: +2/-0
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: [Select]
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)

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: [Select]
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)
« Last Edit: November 09, 2014, 02:17:13 am by fouclo62 »

Offline fouclo62

  • Full Member
  • ***
  • Posts: 105
  • Karma: +2/-0
Polling a device from LUUP, trying to get the "status" of the poll
« Reply #1 on: November 13, 2014, 10:40:58 am »
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: [Select]
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)

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: [Select]
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)

Offline YzRacer

  • Full Member
  • ***
  • Posts: 139
  • Karma: +0/-0
Re: Polling a device from LUUP, trying to get the "status" of the poll
« Reply #2 on: February 17, 2015, 03:06:44 pm »
I could use something like this to reset my system when a serial devices loses communications, did you ever get it figured out?

Offline fcol

  • Sr. Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Re: Polling a device from LUUP, trying to get the "status" of the poll
« Reply #3 on: March 05, 2015, 10:35:06 pm »
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:

Sorry - wish I could actually contribute something.

Offline fouclo62

  • Full Member
  • ***
  • Posts: 105
  • Karma: +2/-0
Re: Polling a device from LUUP, trying to get the "status" of the poll
« Reply #4 on: March 17, 2015, 03:30:13 pm »
Hi guys,

yes and no.  I think I did find the proper syntax (below)...
Code: [Select]
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
...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
« Last Edit: March 20, 2015, 11:45:50 am by fouclo62 »

Offline YzRacer

  • Full Member
  • ***
  • Posts: 139
  • Karma: +0/-0
Re: Polling a device from LUUP, trying to get the "status" of the poll
« Reply #5 on: October 02, 2015, 09:13:02 pm »
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: [Select]
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

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
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.

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.
« Last Edit: October 02, 2015, 10:01:55 pm by futzle »

Offline YzRacer

  • Full Member
  • ***
  • Posts: 139
  • Karma: +0/-0
Re: Polling a device from LUUP, trying to get the "status" of the poll
« Reply #7 on: October 04, 2015, 01:13:33 pm »
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.