Compare commits

...

2 Commits

Author SHA1 Message Date
0cf729e90e added detection delay feature for preventing bulk record generation
added headers and API Key parts
Changes to be committed:
	modified:   camera-client/camera_monitor.py
2023-09-21 23:02:01 +03:30
9d4750d37d added config.json example file
Changes to be committed:
	new file:   camera-client/config.json.example
2023-09-21 23:01:17 +03:30
2 changed files with 33 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ class CameraMonitor:
def __init__(self, config, logger):
self.config = config
self.logger = logger
self.last_detection = 0
def initialize_camera(self):
"""
@@ -27,18 +28,32 @@ class CameraMonitor:
Log a scene change notification to the Scenesense server.
"""
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}'
payload = {'timestamp': current_time, 'description': description}
try:
response = requests.post(self.config['api_url'], json=payload)
response.raise_for_status()
self.logger.info(f'Scene change logged: {description}')
except requests.exceptions.RequestException as e:
self.logger.error(f'Error connecting to Scenesense server: {e}')
except requests.exceptions.HTTPError as e:
self.logger.error(f'HTTP error: {e}')
payload = {
'timestamp': current_time,
'description': description
}
headers = {
'Authorization': self.config['api_key']
}
if (
current_time - self.last_detection >= self.config['detection_delay']
):
try:
response = requests.post(
self.config['api_url'],
json=payload,
headers=headers
)
response.raise_for_status()
self.logger.info(f'Scene change logged: {description}')
except requests.exceptions.RequestException as e:
self.logger.error(f'Error connecting to Scenesense server: {e}')
except requests.exceptions.HTTPError as e:
self.logger.error(f'HTTP error: {e}')
def detect_scene_change(self, previous_frame, current_frame):
"""

View 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"
}