from sensor import Sensor from socket_client import Client from config_utils import Config from apscheduler.schedulers.blocking import BlockingScheduler def update(sensor, client): client.send(sensor.get_environment()) if __name__ == "__main__": config = Config() interval = config.get_value("interval") sensor_id = config.get_value("sensor_id") host, port = config.get_data_center_config() sensor = Sensor(sensor_id) scheduler = BlockingScheduler() client = Client(host, port, scheduler) client.connect() scheduler.add_job(update, 'interval', seconds=interval, max_instances=100, id='update', args=[sensor, client]) client.update_job_started = True scheduler.start()
import cv2 from config_utils import Config from socket_client import Client from json import loads from random import randint config = Config() video_server_host, video_server_port = config.get_video_server_config() data_center_host, data_center_port = config.get_data_center_config() camera_host = config.get_value("camera_host") image_quality = config.get_value("image_quality") client_of_data_center = Client(data_center_host, data_center_port) client_of_data_center.connect() client_of_video_server = Client(video_server_host, video_server_port) client_of_video_server.connect() def capture(camera_id, camera_host, image_quality): if camera_host == "0": camera_host = 0 cap = cv2.VideoCapture(camera_host) while True: ret, frame = cap.read() encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), image_quality] image = cv2.imencode('.jpg', frame, encode_param)[1] image_byte = image.tobytes() client_of_video_server.send_to_video_server(camera_id, 50, image_byte)