Compare commits
2 Commits
4db6cb0af0
...
0cf729e90e
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cf729e90e | |||
| 9d4750d37d |
@@ -12,6 +12,7 @@ class CameraMonitor:
|
|||||||
def __init__(self, config, logger):
|
def __init__(self, config, logger):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.last_detection = 0
|
||||||
|
|
||||||
def initialize_camera(self):
|
def initialize_camera(self):
|
||||||
"""
|
"""
|
||||||
@@ -27,12 +28,26 @@ class CameraMonitor:
|
|||||||
Log a scene change notification to the Scenesense server.
|
Log a scene change notification to the Scenesense server.
|
||||||
"""
|
"""
|
||||||
current_time = int(time.time())
|
current_time = int(time.time())
|
||||||
human_readable_time = datetime.utcfromtimestamp(current_time).strftime('%Y-%m-%d %H:%M:%S')
|
human_readable_time = datetime.utcfromtimestamp(
|
||||||
|
current_time
|
||||||
|
).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
description = f'Scene change detected at {human_readable_time}'
|
description = f'Scene change detected at {human_readable_time}'
|
||||||
payload = {'timestamp': current_time, 'description': description}
|
payload = {
|
||||||
|
'timestamp': current_time,
|
||||||
|
'description': description
|
||||||
|
}
|
||||||
|
headers = {
|
||||||
|
'Authorization': self.config['api_key']
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
current_time - self.last_detection >= self.config['detection_delay']
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
response = requests.post(self.config['api_url'], json=payload)
|
response = requests.post(
|
||||||
|
self.config['api_url'],
|
||||||
|
json=payload,
|
||||||
|
headers=headers
|
||||||
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
self.logger.info(f'Scene change logged: {description}')
|
self.logger.info(f'Scene change logged: {description}')
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
|
|||||||
7
camera-client/config.json.example
Normal file
7
camera-client/config.json.example
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"camera_address": "/dev/video1",
|
||||||
|
"sensitivity_threshold": 0.1,
|
||||||
|
"api_url": "http://scenesense-server/add_record",
|
||||||
|
"detection_delay": 5,
|
||||||
|
"api_key": "your_api_key_here"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user