소스 검색

联动摄像头

locky 1 년 전
부모
커밋
e09c0a13d0
2개의 변경된 파일49개의 추가작업 그리고 9개의 파일을 삭제
  1. 10 1
      AnsjerPush/Config/gatewaySensorConfig.py
  2. 39 8
      Controller/gatewayController.py

+ 10 - 1
AnsjerPush/Config/gatewaySensorConfig.py

@@ -9,12 +9,14 @@
 SMART_SCENE_TOPIC = 'loocam/gateway_sensor/smart_scene/{}'
 GET_SCENE_TOPIC = 'loocam/gateway_sensor/get_scene/{}'
 SMART_SOCKET_TOPIC = 'loocam/smart-socket/{}'
+ANSJER_GENERIC_TOPIC = 'ansjer/generic/{}'
 
 # 设备类型
 DEVICE_TYPE = {
     'gateway': 200,
     'socket': 201,
-    'switch': 202
+    'switch': 202,
+    'C516': 24
 }
 
 # 传感器类型
@@ -65,4 +67,11 @@ EVENT_TYPE = {
     # 插座电源
     'socket_power_on': 2010,
     'socket_power_off': 2011,
+    # 摄像头
+    'detection_reminder_on': 1002,
+    'detection_reminder_off': 1003,
+    'snapshot': 1004,
+    'record_video': 1005,
+    'human_tracking_on': 1006,
+    'human_tracking_off': 1007,
 }

+ 39 - 8
Controller/gatewayController.py

@@ -12,7 +12,8 @@ import pytz
 import requests
 from django.views.generic.base import View
 
-from AnsjerPush.Config.gatewaySensorConfig import SENSOR_TYPE, EVENT_TYPE, DEVICE_TYPE, SMART_SOCKET_TOPIC
+from AnsjerPush.Config.gatewaySensorConfig import SENSOR_TYPE, EVENT_TYPE, DEVICE_TYPE, SMART_SOCKET_TOPIC, \
+    ANSJER_GENERIC_TOPIC
 from AnsjerPush.config import LOGGER, XM_PUSH_CHANNEL_ID
 from Model.models import SensorRecord, GatewaySubDevice, GatewayPush, Device_Info, SceneLog, SmartScene, CountryModel, \
     EffectiveTime
@@ -532,6 +533,7 @@ class GatewayView(View):
                                     if index == task_list_len - 1:
                                         scene_id = smart_scene['id']
                                     kwargs = {
+                                        'sensor_event_type': event_type,
                                         'device_type': task['device_type'],
                                         'event_type': task['event_type'],
                                         'serial_number': task['serial_number'],
@@ -647,9 +649,10 @@ class GatewayView(View):
         return time_frame_dict, time_frame_next_day_dict
 
     @staticmethod
-    def pub_mqtt(device_type, event_type, serial_number, delay_time, scene_id=0):
+    def pub_mqtt(sensor_event_type, device_type, event_type, serial_number, delay_time, scene_id=0):
         """
         发布mqtt消息
+        @param sensor_event_type: 传感器事件类型
         @param device_type: 设备类型
         @param event_type: 事件类型
         @param serial_number: 序列号
@@ -657,16 +660,44 @@ class GatewayView(View):
         @param scene_id: 场景id
         @return:
         """
+        msg = {}
+        # 插座
         if device_type == DEVICE_TYPE['socket']:
             topic_name = SMART_SOCKET_TOPIC.format(serial_number)
             status = 1 if event_type == EVENT_TYPE['socket_power_on'] else 0
-            msg = {
-                'type': 1,
-                'data': {'deviceSwitch': status}
+            msg['type'] = 1
+            msg['data'] = {
+                'deviceSwitch': status
             }
-            if delay_time:
-                time.sleep(delay_time)
-            CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
+
+        # 摄像头
+        elif device_type == DEVICE_TYPE['C516']:
+            topic_name = ANSJER_GENERIC_TOPIC.format(serial_number)
+            if event_type == EVENT_TYPE['detection_reminder_on']:
+                msg['commandType'] = 'detection_reminder'
+                msg['enable'] = 1
+            elif event_type == EVENT_TYPE['detection_reminder_off']:
+                msg['commandType'] = 'detection_reminder'
+                msg['enable'] = 0
+            elif event_type == EVENT_TYPE['snapshot']:
+                msg['commandType'] = 'snapshot'
+                msg['eventType'] = sensor_event_type
+            elif event_type == EVENT_TYPE['record_video']:
+                msg['commandType'] = 'record_video'
+            elif event_type == EVENT_TYPE['human_tracking_on']:
+                msg['commandType'] = 'human_tracking'
+                msg['enable'] = 1
+            elif event_type == EVENT_TYPE['human_tracking_off']:
+                msg['commandType'] = 'human_tracking'
+                msg['enable'] = 0
+            else:
+                return
+        else:
+            return
+
+        if delay_time:
+            time.sleep(delay_time)
+        CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
 
         # 没有设备任务时,最后一个任务上报场景日志
         if scene_id: