-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
88 lines (67 loc) · 2.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import time
from pydroid_ipcam import *
import aiohttp
import asyncio
import sys
from thingin.thingin_requests import *
import uuid
import platform
import os
import json
update_frequency = 5
hue_url= "https://192.168.1.47/api/75WMpeSrs1ogZ6kxD79ez-fseyPxaCNkt-r8YL1z/lights/1/state"
print("###########################")
print("Program arguemnts : ")
for arg in sys.argv:
print(arg)
token = sys.argv[1]
domain_to_insert = sys.argv[2]
name = sys.argv[3]
ip_local = sys.argv[4]
camuser = sys.argv[5]
campwd = sys.argv[6]
print("###########################")
my_uuid = uuid.uuid3(namespace=uuid.NAMESPACE_DNS, name=name)
if platform.system() == "Windows":
thingindir = os.getcwd()+"\\thingin\\"
else:
thingindir = os.getcwd()+"/thingin/"
boostrap_data_file = open(thingindir+'boostrap_result.json', 'r')
boostrap_data = json.load(boostrap_data_file)
print("Updating existing data :")
print(boostrap_data)
luminance_uuid = ""
motion_uuid = ""
async def main():
async with aiohttp.ClientSession() as client:
cam = PyDroidIPCam(websession=client, host=ip_local, username=camuser, password=campwd, port=8080, ssl=False)
while(True):
time.sleep(update_frequency)
await cam.update()
try:
print_data(cam)
update_data(cam)
except Exception as e:
print(e)
def print_data(cam):
print("Camera availability ", cam.available)
print("Enabled sensors ", cam.enabled_sensors)
print("Motion events ", cam.sensor_data["motion_event"])
print("Luminance Value ", cam.sensor_data["light"])
print("Torch status ", cam.status_data["curvals"]["torch"])
def update_data(cam):
motion_update_result = put_motion_event_thingin(uuid=motion_uuid, iri=motion_iri, motion_data=cam.sensor_data["motion_event"], access_token=token)
luminance_update_result = put_luminance_thingin(uuid=luminance_uuid, iri=luminance_iri, luminance_data=cam.sensor_data["light"], access_token=token)
print("Motion data update result: ", motion_update_result)
print("Luminance data update: ", luminance_update_result)
# ##BOOTSTRAP DATA UUIDS LOADING FROM THINGIN RESPONSE"
luminance_iri = domain_to_insert+"androidIPCam.luminance-"+str(my_uuid)
motion_iri = domain_to_insert+"androidIPCam.movementDetection-"+str(my_uuid)
for node in boostrap_data:
if node["iri"] == luminance_iri:
luminance_uuid = node["uuid"]
if node["iri"] == motion_iri:
motion_uuid = node["uuid"]
# MAIN LOOP
loop = asyncio.get_event_loop()
loop.run_until_complete(main())