We have moved at community.getvera.com

Author Topic: http post with Luup to communicate with my DVR  (Read 14912 times)

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
http post with Luup to communicate with my DVR
« on: September 04, 2012, 09:45:13 am »
Hello, I just want to communicate with my DVR when a sensor is triggered with HTTP post method. No experience with web services :-[

http://MyDVRServer/adminSettings.html?action=RecordStart&camID=1

How to simply Luup this command?

Thanx

chris

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #1 on: September 04, 2012, 10:11:02 am »
Ok! As usual, I answer to myself, nad hope it helps other dummies: ;D

local http = require("socket.http")
 
  -- 5 Second timeout
http.TIMEOUT = 5
 
  -- The return parameters are in a different order from luup.inet.wget(...)
 result, status = http.request("http://login:pswrd@ipserver/adminSettings.html?action=RecordStart&camID=1", "run=run")

Offline ketchoupi

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Re: http post with Luup to communicate with my DVR
« Reply #2 on: September 06, 2012, 04:07:50 pm »
hi

i'm trying to do this with zoneminder, change status of camera monitor to modect :

syntax is : http://www.ispyconnect.com/man.aspx?n=Zoneminder



my first camera is :
http://192.168.1.120/zm/index.php?view=watch&mid1
2nd:
http://192.168.1.120/zm/index.php?view=watch&mid2


after many examples, it's not ok :


local http = require("socket.http")

-- 5 Second timeout
http.TIMEOUT = 5

-- The return parameters are in a different order from luup.inet.wget(...)
result, status = http.request("http://192.168.1.120/zm/index.php?view=watch&mid1&newFunction=Modect&newEnabled=1&user=xxxxxxxx&pass=xxxxxxxx"), "run=run")

ECHEC code lua failed

version 3

local http = require("socket.http")

-- 5 Second timeout
http.TIMEOUT = 5

-- The return parameters are in a different order from luup.inet.wget(...)
result, status = http.request("http://login:password@192.168.1.120/zm/index.php?view=watch&mid1&newFunction=Modect&newEnabled=1"), "run=run")

ECHEC code lua failed

do you have any ideas?

thanks

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: http post with Luup to communicate with my DVR
« Reply #3 on: September 06, 2012, 04:35:09 pm »
Two comments:
a) You probably don't need the POST body ("run=run")
b) You have an extra end-parenthesis

Try this snippet (merged into your larger block, of course):
Code: [Select]
result, status = http.request("http://login:password@192.168.1.120/zm/index.php?view=watch&mid1&newFunction=Modect&newEnabled=1")

Offline ketchoupi

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Re: http post with Luup to communicate with my DVR
« Reply #4 on: September 06, 2012, 05:03:13 pm »
thanks

now code is ok but nothing change in zoneminder   ::)

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: http post with Luup to communicate with my DVR
« Reply #5 on: September 06, 2012, 05:09:55 pm »
It's possible it doesn't like that style of URL with the UN/PW encoded.  Try something more like the snippet at the bottom of this:
    http://svn.slimdevices.com/repos/jive/7.7/trunk/squeezeplay/src/luasocket-2.0.2/doc/http.html

where the UN/PW is passed as an [encoded] parameter to the URL call.

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #6 on: September 07, 2012, 02:45:42 am »
Hello guessed,
with http.request, I'm limited to send commands to VLC. I've seen that there is a Telnet interface with VLC. Is it possible to send a Telnet command with Vera?
My objective would be when a sensor is triggered in Vera, send a command on my fitpc2 where I have VLC to start recording the stream. Now with http.request, I'm just able to start reading the stream.
On the fitpc2 where I have VLC, I have a local command-line that works. But I am unable to activate this ".bat" file in order to do what I want.
So with your experience, what is the best way to do that?

Thanks, chris

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: http post with Luup to communicate with my DVR
« Reply #7 on: September 07, 2012, 03:26:51 am »
Chris,
I'm not familiar with VLC, but if there's a Remote interface ("listener") for commands then you can likely hookup Vera to talk to it.  It would really depend upon what commands that remote interface directly exposes, and if it exposes them in a manner that's accessible to Vera (a TCP "socket")

It sounds like it's already providing some sort of HTTP control/command interface but you'd need to read up on the specs to see if it has other interfaces, and what extra command (if any) they support that aren't already exposed via the HTTP interface.

It would likely require a whole bunch of experimentation, and a lot of patience to get going.  Not sure how your .BAT file ties into this though, unless VLC itself has some way to launch it via the interfaces your seeing.

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #8 on: September 07, 2012, 08:30:54 am »
Hello guessed,
thanks for taking time to answer. It sounds like VLC has different interfaces, like http, command-line and Telnet. With the command-line I'm able to do what I want, but only from the PC where the VLC is installed. With http.request, I'm able to launch a VLC stream from vera. But still not able to find the record option.

So one more question, is it possible to "Telnet" with a luup script from vera? If yes, I would investigate more, and be patient  ;)

chris

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: http post with Luup to communicate with my DVR
« Reply #9 on: September 07, 2012, 09:47:02 am »
In Lua, its possible to open a regular Socket to anything, and speak whatever you want down it.  When folks send clear text commands (not binary) down this Channel some refer to this as using Telnet protocol... somewhat of a misnomer, but we won't go into that here.

An acid test for this is whether you can run a command like
   telnet hostname port

Eg.telnet 192.168.33.24 5000

And get that to connect.  The IP and port will need to be those provided by the application you're attempting to connect to (like VLC)

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #10 on: September 07, 2012, 10:30:20 am »
Thanks!

What is funny is that the VLC Web Interface is written in Lua. And is OpenSource. So for a developper it could be a good challenge to do a VLC plugin! This plugin could have the basic following functionnalities:
Start recording
Stop recording
And this could be a nice solution to store the IP camera stream in our own NAS or PC, as this functionnality is not available now within Micasaverde. Storage will be only available on their servers, and will be an option.
chris

Offline ketchoupi

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Re: http post with Luup to communicate with my DVR
« Reply #11 on: September 08, 2012, 10:09:41 am »
may be is it possible with ssh access ?

http://forum.micasaverde.com/index.php/topic,11663.msg84044.html#msg84044

with script   .sh on ubuntu server? like

    Mise en mode monitor des cameras

    #!/bin/bash
    /home/scripts/ZM_change_cam1_Monitor.sh > /dev/null 2>&1
    /home/scripts/ZM_change_cam2_Monitor.sh > /dev/null 2>&1
    /home/scripts/ZM_change_cam3_Monitor.sh > /dev/null 2>&1
    etc...




    contenu des scripts par caméra
    ex: ZM_change_cam1_Monitor.sh

    #!/bin/bash
    curl -m 30 --connect-timeout 5 -f -k -s -L "192.168.1.120/zm/index.php?view=watch&mid1&newFunction=Modect&newEnabled=1"


with command : zmpkg.pl monitor on my zoneminder server, that change state my cam in monitor. i'm creating a state : surveillance and with this commande zmpkg.pl surveillance it's ok
now i'm searching to do this with veralite by ssh

do you have any idea?
« Last Edit: September 08, 2012, 01:43:14 pm by ketchoupi »

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #12 on: September 09, 2012, 04:55:41 am »
After some investigations, get the answer from VLC that due to security reasons, this command (start record and stop record with http requests) will not be available.

So I find a solution with ISpy Connect (freeware solution that supports http requests):
With this basic scene, triggered by a sensor, I can record on my fitpc2 (7Watts power only!) 30 seconds of video:

Code: [Select]
local http = require("socket.http")
-- 5 Second timeout
http.TIMEOUT = 5
 result, status = http.request("http://login:password@myIP:PORT/record?otid=2&oid=0")
luup.sleep(30000)
 result, status = http.request("http://login:password@myIP:PORT/recordstop?otid=2&oid=0")
:D hope it helps someone.

chris
« Last Edit: September 09, 2012, 06:05:49 am by oTi@ »

Offline jsauser11

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Re: http post with Luup to communicate with my DVR
« Reply #13 on: December 03, 2016, 05:48:54 pm »
After some investigations, get the answer from VLC that due to security reasons, this command (start record and stop record with http requests) will not be available.

So I find a solution with ISpy Connect (freeware solution that supports http requests):
With this basic scene, triggered by a sensor, I can record on my fitpc2 (7Watts power only!) 30 seconds of video:

Code: [Select]
local http = require("socket.http")
-- 5 Second timeout
http.TIMEOUT = 5
 result, status = http.request("http://login:password@myIP:PORT/record?otid=2&oid=0")
luup.sleep(30000)
 result, status = http.request("http://login:password@myIP:PORT/recordstop?otid=2&oid=0")
:D hope it helps someone.

chris
Know this is an old post, but I am trying to get this to work on a VeraPlus with UI7 and my iSpy server.
Had to change the "otid" to "ot" for compliance to current iSpy connect syntex, but scene still refuses to run.
The http string works fine when issued from a web browser, but does not run in a scene.
Maybe the syntax has changed in Vera?

Offline chris66

  • Sr. Member
  • ****
  • Posts: 318
  • Karma: +9/-8
Re: http post with Luup to communicate with my DVR
« Reply #14 on: February 08, 2017, 03:31:42 am »
Sorry, still in UI5, now using BlueIris with this command line: luup.inet.wget("http://myip:myport/admin?camera=CamNord&trigger&user=myusername&pw=mypassword")

Hope it helps.