MissiaL/hikvision-client

How can I get messages about the movement?

Closed this issue · 6 comments

Hi, how can I get messages about the movement?

Hi! I'm going to work this problem. I found solution
I will soon release an update where you can receive events

This is done. Tell me, is everything working ?
https://github.com/MissiaL/hikvision-client/releases/tag/0.1.8

Excellent work, it works!
When motion in the frame is present, then everything works. But when there is no movement for a few seconds, an error occurs

from hikvisionapi import Client

client = Client('http://192.168.0.64', 'admin', 'admin')
client.count_events = 1 # The number of events that need to(default = 1)
response = client.Event.notification.alertStream(method='get')

print response
[{u'EventNotificationAlert': {u'@xmlns': u'http://www.hikvision.com/ver20/XMLSchema', u'macAddress': u'b4:a3:82:38:6f:91', u'protocol': u'HTTP', u'eventDescription': u'Motion alarm', u'portNo': u'80', u'@version': u'2.0', u'channelID': u'1', u'activePostCount': u'1', u'dateTime': u'2018-03-21T19:33:44+05:00', u'eventState': u'active', u'eventType': u'VMD', u'DetectionRegionList': {u'DetectionRegionEntry': {u'sensitivityLevel': u'33', u'regionID': u'1', u'RegionCoordinatesList': {u'RegionCoordinates': [{u'positionX': u'403', u'positionY': u'403'}, {u'positionX': u'643', u'positionY': u'643'}, {u'positionX': u'643', u'positionY': u'643'}, {u'positionX': u'403', u'positionY': u'403'}]}}}, u'channelName': u'Camera 01', u'ipAddress': u'192.168.0.64'}}]
[{u'EventNotificationAlert': {u'@xmlns': u'http://www.hikvision.com/ver20/XMLSchema', u'macAddress': u'b4:a3:82:38:6f:91', u'protocol': u'HTTP', u'eventDescription': u'Motion alarm', u'portNo': u'80', u'@version': u'2.0', u'channelID': u'1', u'activePostCount': u'1', u'dateTime': u'2018-03-21T19:33:45+05:00', u'eventState': u'active', u'eventType': u'VMD', u'DetectionRegionList': {u'DetectionRegionEntry': {u'sensitivityLevel': u'33', u'regionID': u'1', u'RegionCoordinatesList': {u'RegionCoordinates': [{u'positionX': u'403', u'positionY': u'403'}, {u'positionX': u'643', u'positionY': u'643'}, {u'positionX': u'643', u'positionY': u'643'}, {u'positionX': u'403', u'positionY': u'403'}]}}}, u'channelName': u'Camera 01', u'ipAddress': u'192.168.0.64'}}]
Traceback (most recent call last):
  File "hikapi.py", line 6, in <module>
    response = client.Event.notification.alertStream(method='get')
  File "/home/user/.local/lib/python2.7/site-packages/hikvisionapi/hikvisionapi.py", line 34, in __call__
    return self.client.request(self.method_name, **kwargs)
  File "/home/user/.local/lib/python2.7/site-packages/hikvisionapi/hikvisionapi.py", line 150, in request
    response = self._prepared_request(*args, **kwargs)
  File "/home/user/.local/lib/python2.7/site-packages/hikvisionapi/hikvisionapi.py", line 143, in _prepared_request
    response = self.stream_request(method, full_url, **data)
  File "/home/user/.local/lib/python2.7/site-packages/hikvisionapi/hikvisionapi.py", line 120, in stream_request
    for chunk in response.iter_lines(chunk_size=1024, delimiter=b'--boundary'):
  File "/home/user/.local/lib/python2.7/site-packages/requests/models.py", line 789, in iter_lines
    for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
  File "/home/user/.local/lib/python2.7/site-packages/requests/models.py", line 752, in generate
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.0.64', port=80): Read timed out.

I changed the timeout in hikvisionapi.py and the error disappeared.
def __init__(self, host, login=None, password=None, timeout=999):

You can set timeout as big number