Author Topic: Controlling Foscam R2  (Read 206 times)

Offline bergyman

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Controlling Foscam R2
« on: October 22, 2017, 02:24:33 pm »
Hi,

Currently wrestling with a couple different issues:
1) I'd like to be able to have a script in a scene that once I remotely turn the camera on waits about 3 minutes for the camera to boot up, moves the camera to a pre-set position, takes a picture, moves it to a second preset position, takes a picture.
I have LUUP scripts in scenes that use the CGI of the camera to move to preset positions that are functioning correctly. I've been unable to use the CGI to snap a picture off, and I cannot figure out a way to make the entire thing wait 3 minutes before executing. I've read Vera times this out after 60 seconds and it takes longer than that for the camera to boot up and connect to the network.
Any help here would be appreciated.

Offline GaryTTirn

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Controlling Foscam R2
« Reply #1 on: October 25, 2017, 11:45:23 am »
To delay LUUP execution you can use call_delay-function

Something like this :

function delayed
  luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },123)
  luup.log("Delayed: Power off, Device : 123")
  return true
end -- delayed

-- Main()
luup.log("Main Code starting")

--Execute delayed action by function delayed
luup.call_delay("delayed",<delay in seconds>)

return true
« Last Edit: October 27, 2017, 10:51:50 am by GaryTTirn »

Offline bergyman

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Controlling Foscam R2
« Reply #2 on: October 25, 2017, 12:20:44 pm »
Thanks for the answer!
I've since moved on to using PLEG to accomplish this and it's working fine.
Though I AM curious as to a couple things here:
1) How do you access the log file you're logging to?
2) How could you log the value of a variable? I know nothing about LUA.

Offline GaryTTirn

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Controlling Foscam R2
« Reply #3 on: October 27, 2017, 11:07:43 am »
1) How do you access the log file you're logging to?

http://<VERA-IP>/cgi-bin/cmh/log.sh?Device=LuaUPnP
or
SSH into vera and less, cat or tail /var/log/cmh/LuaUPnP.log

2) How could you log the value of a variable? I know nothing about LUA.

Just concat the variable name to the luup.log call, lua takes care of converting numbers to strings.

https://www.lua.org/pil/3.4.html

local sID = 197
local tID = 198
luup.log("Var sID : " .. sID .. "Var tID: " .. tID)

log-function LUUP extension description is here :
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_log