This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Doorbird API
#1
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)
Reply
#2
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.
Reply
#3
How can I do that? Can you provide some example? I'm not really good at this level of programming :/
Reply
#4
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
Reply
#5
(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?
Reply
#6
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
Reply
#7
Thank You so much admin! I increased timeout and the error is gone! Smile
Reply
#8
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
Novice DIY with a HL and KNX basics trying to ...
Reply
#9
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...
Novice DIY with a HL and KNX basics trying to ...
Reply
#10
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)
Reply
#11
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
Novice DIY with a HL and KNX basics trying to ...
Reply
#12
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=**********')
Reply
#13
Thank you, it work fine now!
Novice DIY with a HL and KNX basics trying to ...
Reply
#14
(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?
Reply
#15
Sorry but we can only provide support for LM/Lua.
Reply


Forum Jump: