Logic Machine Forum
Doorbird API - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Doorbird API (/showthread.php?tid=2508)



Doorbird API - MantasJ - 10.03.2020

Hello,

Has anyone succesfully integrated "Doorbird" API into LM? I ask this, because I face a problem and don't understand why it appears. API documentation is here: https://www.doorbird.com/downloads/api_lan.pdf?rev=0.27 I use the "monitor request" function, which gives me a live stream of doorbell and motion sensor events. My problem is sometimes that the log gives: Error code 509, which means that stream is busy (509  Bandwidth Limit Exceeded. 509  Bandwidth Limit Exceeded. Maximum number of clients reached.) - but why? I don't have it opened anywehere else, so I don't understand. If the problem somewhy goes away and there is no 509 error, then the result is just nil. What am I doing wrong? If I'm trying to watch the stream from my browser then everything works fine... Here is my code:

Quote:require('json')
local http = require('socket.http')

res, err = http.request('http://192.168.100.211/bha-api/monitor.cgi?ring=doorbird,motionsensor&http-user=hereItypeUsername&http-password=hereItypePassword', '')

log(res, err)



RE: Doorbird API - admin - 10.03.2020

You cannot use HTTP library for this, you have to use raw sockets. Streaming is not a standard HTTP request because it does not end.


RE: Doorbird API - MantasJ - 10.03.2020

How can I do that? Can you provide some example? I'm not really good at this level of programming :/


RE: Doorbird API - admin - 11.03.2020

Try this resident script (sleep time = 0), change USER and PASS to your auth data. It will log all incoming data (log(line)). This is to check if there are any errors during communication. If everything is working then comment/delete this line.

Code:
if not sock then
  host = '192.168.100.211'
  port = 80
  path = '/bha-api/monitor.cgi?ring=doorbell,motionsensor&http-user=USER&http-password=PASS'

  sock = require('socket').tcp()
  sock:settimeout(10)
  res, err = sock:connect(host, port)

  if res then
    sock:send(
      'GET ' .. path .. ' HTTP/1.1\r\n' ..
      'Host: ' .. host .. '\r\n\r\n'
    )
  else
    alert('connect failed: ' .. tostring(err))
    sock:close()
    sock = nil
    os.sleep(5)
  end
end

line, err = sock:receive()

if line then
  log(line)

  if line:find('doorbell:') then
    status = line:split(':')[2]
    log('doorbell', line)
  elseif line:find('motionsensor:') then
    status = line:split(':')[2]
    log('motionsensor', status)
  end
else
  alert('receive failed: ' .. tostring(err))
  sock:close()
  sock = nil
end



RE: Doorbird API - MantasJ - 11.03.2020

(11.03.2020, 06:59)admin Wrote: Try this resident script (sleep time = 0), change USER and PASS to your auth data. It will log all incoming data (log(line)). This is to check if there are any errors during communication. If everything is working then comment/delete this line.
Code:
if not sock then
  host = '192.168.100.211'
  port = 80
  path = '/bha-api/monitor.cgi?ring=doorbell,motionsensor&http-user=USER&http-password=PASS'

  sock = require('socket').tcp()
  sock:settimeout(10)
  res, err = sock:connect(host, port)

  if res then
    sock:send(
      'GET ' .. path .. ' HTTP/1.1\r\n' ..
      'Host: ' .. host .. '\r\n\r\n'
    )
  else
    alert('connect failed: ' .. tostring(err))
    sock:close()
    sock = nil
    os.sleep(5)
  end
end

line, err = sock:receive()

if line then
  log(line)

  if line:find('doorbell:') then
    status = line:split(':')[2]
    log('doorbell', line)
  elseif line:find('motionsensor:') then
    status = line:split(':')[2]
    log('motionsensor', status)
  end
else
  alert('receive failed: ' .. tostring(err))
  sock:close()
  sock = nil
end

Thank You! It seems it does work, but it has a strange behaviour - I get the data fine, but I still get alert: "receive failed:timeout" - is this something I should worry about and check out or I could just comment the alert line and ignore it?


RE: Doorbird API - admin - 11.03.2020

Try increasing timeout:
Code:
sock:settimeout(60)

If you are still getting timeout errors you can check for "closed" error only like this:
Code:
elseif err == 'closed' then
  alert('receive failed: ' .. tostring(err))
  sock:close()
  sock = nil
end



RE: Doorbird API - MantasJ - 11.03.2020

Thank You so much admin! I increased timeout and the error is gone! Smile


RE: Doorbird API - Firechief - 03.07.2020

Hi all,

I bought a Doorbird Video Doorstation D1101V wich can open the sliding gate with the integrated relay and the Doorbird IP I/O expansion module wich allows me to also open the 2 garage doors and the front door. For the moment the garage doors are controlled by the remotes and KNX buttons inside the garage over a switch actuator with a script attached: ON - 0.5s delay - OFF.
Is it possible and can someone help me to reconnect the KNX buttons in the garage (trough script or something) so I can control the garage doors as before. It should be possible trough API with
Code:
http://<device-ip>/bha-api/open-door.cgi?<parameter>=<value>
So what i'm looking for I think is to put this command behind a physical button.
Thx in advance


RE: Doorbird API - Firechief - 13.07.2020

Can someone help me please?
Event-based script on groupadress 5/0/1

value = grp.getvalue('5/0/1')

if value == true then
Send http://<device-ip>/bha-api/open-door.cgi?<parameter>=<value>

end

Something like this, but i don't think it's that easy...


RE: Doorbird API - admin - 13.07.2020

Send HTTP request like this:
Code:
http = require('socket.http')
res, err = http.request('http://<device-ip>/bha-api/open-door.cgi?<parameter>=<value>')
log(res, err)



RE: Doorbird API - Firechief - 13.07.2020

Thx Admin,

This is what i made of it:

Code:
--Doorbird Relay aansturen via http

value = grp.getvalue('5/0/2')

if value == true then
 
    http = require('socket.http')
  res, err = http.request('http://192.168.xxx.xxx/bha-api/open-door.cgi?r=xxxxxx@2?http-user=xxxxxx0001&http-password=**********')
    log(res, err)


end
 
and this is what i get as log:

Code:
* arg: 1
  * string: {
"BHA": {
"RETURNCODE": "0"
}
}
* arg: 2
  * number: 503
 
Relay doesn't switch


RE: Doorbird API - admin - 13.07.2020

Your URL is incorrect - it has two question marks. Second question mark should be an ampersand:
Code:
res, err = http.request('http://192.168.xxx.xxx/bha-api/open-door.cgi?r=xxxxxx@2&http-user=xxxxxx0001&http-password=**********')



RE: Doorbird API - Firechief - 13.07.2020

Thank you, it work fine now!


RE: Doorbird API - felixRo - 10.10.2022

(11.03.2020, 06:59)admin Wrote: Try this resident script (sleep time = 0), change USER and PASS to your auth data. It will log all incoming data (log(line)). This is to check if there are any errors during communication. If everything is working then comment/delete this line.

Code:
if not sock then
  host = '192.168.100.211'
  port = 80
  path = '/bha-api/monitor.cgi?ring=doorbell,motionsensor&http-user=USER&http-password=PASS'

  sock = require('socket').tcp()
  sock:settimeout(10)
  res, err = sock:connect(host, port)

  if res then
    sock:send(
      'GET ' .. path .. ' HTTP/1.1\r\n' ..
      'Host: ' .. host .. '\r\n\r\n'
    )
  else
    alert('connect failed: ' .. tostring(err))
    sock:close()
    sock = nil
    os.sleep(5)
  end
end

line, err = sock:receive()

if line then
  log(line)

  if line:find('doorbell:') then
    status = line:split(':')[2]
    log('doorbell', line)
  elseif line:find('motionsensor:') then
    status = line:split(':')[2]
    log('motionsensor', status)
  end
else
  alert('receive failed: ' .. tostring(err))
  sock:close()
  sock = nil
end
Hello together, i think the code you provided does not fit for python, so i changed it a bit to make it work.. But i still receive error-code 504 back for this. Could you provide a solution which fits for python?


RE: Doorbird API - admin - 11.10.2022

Sorry but we can only provide support for LM/Lua.