|
@@ -6,26 +6,28 @@
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Software: PyCharm
|
|
@Software: PyCharm
|
|
"""
|
|
"""
|
|
-import time
|
|
|
|
import datetime
|
|
import datetime
|
|
-import logging
|
|
|
|
|
|
+import time
|
|
|
|
|
|
import requests
|
|
import requests
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
-from decimal import Decimal
|
|
|
|
|
|
|
|
from Ansjer.Config.gatewaySensorConfig import SMART_SCENE_TOPIC
|
|
from Ansjer.Config.gatewaySensorConfig import SMART_SCENE_TOPIC
|
|
|
|
+from Ansjer.config import CONFIG_INFO, AWS_IOT_SES_ACCESS_CHINA_ID, AWS_IOT_SES_ACCESS_CHINA_SECRET, \
|
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_REGION
|
|
|
|
+from Ansjer.config import LOGGER
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
from Controller.SensorGateway.SmartSocketController import SmartSocketView
|
|
from Controller.SensorGateway.SmartSocketController import SmartSocketView
|
|
from Model.models import FamilyRoomDevice, FamilyRoom, GatewaySubDevice, Device_Info, UserFamily, FamilyMember, \
|
|
from Model.models import FamilyRoomDevice, FamilyRoom, GatewaySubDevice, Device_Info, UserFamily, FamilyMember, \
|
|
UidSetModel, iotdeviceInfoModel, SmartScene, SceneLog, SocketInfo, SocketPowerStatistics, SocketSchedule, \
|
|
UidSetModel, iotdeviceInfoModel, SmartScene, SceneLog, SocketInfo, SocketPowerStatistics, SocketSchedule, \
|
|
CountryModel
|
|
CountryModel
|
|
|
|
+from Object.AWS.AWSIoTDataPlaneUtil import AWSIoTDataPlaneService
|
|
|
|
+from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
-from Object.RedisObject import RedisObject
|
|
|
|
|
|
|
|
|
|
|
|
class GatewayDeviceView(View):
|
|
class GatewayDeviceView(View):
|
|
@@ -277,15 +279,37 @@ class GatewayDeviceView(View):
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def reset_device(serial_number):
|
|
def reset_device(serial_number):
|
|
- # 下发设备进行重置
|
|
|
|
- LOGGER = logging.getLogger('info')
|
|
|
|
- SOCKET_TOPIC_NAME = 'loocam/smart-socket/{}' # 插座发布消息主题(因设备当前版本只能订阅一个主题)
|
|
|
|
- topic_name = SOCKET_TOPIC_NAME.format(serial_number)
|
|
|
|
- # 发布消息内容,重置设备
|
|
|
|
- msg = {'type': 6, 'data': {'device_reset': 1}}
|
|
|
|
- result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
|
|
|
|
- LOGGER.info('重置{}智能插座设备,发布MQTT消息结果{}'.format(serial_number, result))
|
|
|
|
- return True
|
|
|
|
|
|
+ """
|
|
|
|
+ 下发消息到设备
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ thing_name = 'LC_' + serial_number
|
|
|
|
+ if 'test' == CONFIG_INFO or CONFIG_INFO == 'cn':
|
|
|
|
+ # 创建IoT客户端
|
|
|
|
+ iot_data_plane = AWSIoTDataPlaneService(AWS_IOT_SES_ACCESS_CHINA_ID,
|
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_SECRET,
|
|
|
|
+ AWS_IOT_SES_ACCESS_CHINA_REGION)
|
|
|
|
+ # 更新影子为离线状态
|
|
|
|
+ data = {
|
|
|
|
+ "state": {
|
|
|
|
+ "reported": {
|
|
|
|
+ "online": 0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ res = iot_data_plane.update_thing_shadow(thing_name, data)
|
|
|
|
+ LOGGER.info('删除插座更新设备影子状态{}'.format(res))
|
|
|
|
+ # 下发设备进行重置
|
|
|
|
+ SOCKET_TOPIC_NAME = 'loocam/smart-socket/{}' # 插座发布消息主题(因设备当前版本只能订阅一个主题)
|
|
|
|
+ topic_name = SOCKET_TOPIC_NAME.format(serial_number)
|
|
|
|
+ # 发布消息内容,重置设备
|
|
|
|
+ msg = {'type': 6, 'data': {'device_reset': 1}}
|
|
|
|
+ result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
|
|
|
|
+ LOGGER.info('重置{}智能插座设备,发布MQTT消息结果{}'.format(serial_number, result))
|
|
|
|
+ return True
|
|
|
|
+ except Exception as e:
|
|
|
|
+ LOGGER.info('插座删除下发更改影子异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+ return False
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def gateway_device_list(cls, request_dict, response):
|
|
def gateway_device_list(cls, request_dict, response):
|
|
@@ -511,4 +535,4 @@ class GatewayDeviceView(View):
|
|
# (vvv(VVV)(VVV)vvv)
|
|
# (vvv(VVV)(VVV)vvv)
|
|
# 神兽保佑
|
|
# 神兽保佑
|
|
# 代码无BUG!
|
|
# 代码无BUG!
|
|
-#
|
|
|
|
|
|
+#
|