Skip to content

Commit

Permalink
Merge pull request #10 from psyciknz/image-playback
Browse files Browse the repository at this point in the history
Image playback and Mqtt auth
  • Loading branch information
psyciknz authored Feb 14, 2020
2 parents 4f06985 + e07072c commit a591623
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ config.ini
*.pyc
.pytest_cache/*
build.config
image.jpg
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "2.7"
- "3.7"
# command to run tests
install: pip install -r requirements.txt
script: pytest
script: pytest test_onreceive.py
277 changes: 259 additions & 18 deletions CameraEvents.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM __BASEIMAGE_ARCH__/python:2.7.15-jessie
FROM __BASEIMAGE_ARCH__/python:3.7.2-stretch

__CROSS_COPY qemu/qemu-__QEMU_ARCH__-static /usr/bin/

Expand Down
83 changes: 83 additions & 0 deletions Tests/test_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import pytest
import CameraEvents
import datetime
try:
#python 3+
from configparser import ConfigParser
except:
# Python 2.7
from ConfigParser import ConfigParser

class dummy_mqtt(object):
pass
def publish(self,topic,payload):
pass

def create_device():
device_cfg = {}
channels = {}
device_cfg["channels"] = channels
#device_cfg.set(["channels"]
device_cfg["Name"] = "test"
device_cfg["user"] = "user"
device_cfg["password"] = "pass"
device_cfg["auth"] = "digest"
device_cfg["mqtt"] = "localhsot"
device_cfg["protocol"] = "http"
device_cfg["host"] = "192.168.1.108"
device_cfg["port"] = 80
device_cfg["alerts"] = False
device_cfg["snapshotoffset"] = 0
client = dummy_mqtt()
client.connected_flag = True

basetopic = "CameraEvents"

device = CameraEvents.DahuaDevice("Camera", device_cfg, client,basetopic)
return device

def read_config():
cp = ConfigParser()
filename = {"config.ini","conf/config.ini"}
dataset = cp.read(filename)

try:
if len(dataset) != 1:
raise ValueError( "Failed to open/find all files")
camera_items = cp.items( "Cameras" )
for key, camera_key in camera_items:
#do something with path
camera_cp = cp.items(camera_key)
camera = {}
#temp = cp.get(camera_key,"host")
camera["host"] = cp.get(camera_key,'host')
except Exception as ex:
pass

def test_dahua_create():
device = create_device()
assert device is not None

def test_dahua_take_snapshot():
device = create_device()
device.host = 'cam-nvr.andc.nz'
device.user = 'IOS'
device.password = 'Dragon25'
image = device.SnapshotImage(1,"Garage","message",nopublish=True)
assert image is not None
if len(image) > 600:
sized = True
assert sized is True

def test_dahua_search_images():
device = create_device()
device.host = 'cam-nvr.andc.nz'
device.user = 'IOS'
device.password = 'Dragon25'
starttime = datetime.datetime.now() - datetime.timedelta(minutes=25)
endtime = datetime.datetime.now()
result = device.SearchImages(2, starttime,endtime,"")
assert result is not None
#if len(image) > 600:
# sized = True
#assert sized is True
10 changes: 7 additions & 3 deletions config-master.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ IP=mqtt.andc.nz
;MQTT Port
Port=1883
;MQTT username, without qoutes
Mqtt_Username = ''
User=
;MQTT password, without qoutes
;MQTT password, without qoutes
BaseTopic = 'CameraEvents'
Password=
;Base MQTT Topic
BaseTopic=CameraEvents

[Slack]
token=api_token_here

[Cameras]
camera1=Example1
Expand Down
Binary file added movie.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ paho-mqtt
pycurl
ConfigParser
requests
imageio
Slacker

0 comments on commit a591623

Please sign in to comment.