Ver código fonte

Loocam网关设备注册到aws iot core使用"Loocam_Device_"前缀

locky 3 anos atrás
pai
commit
e548d6c20f
2 arquivos alterados com 15 adições e 6 exclusões
  1. 13 4
      Controller/IotCoreController.py
  2. 2 2
      Object/IOTCore/IotObject.py

+ 13 - 4
Controller/IotCoreController.py

@@ -91,6 +91,7 @@ class IotCoreView(View):
 
             uid = request_dict.get('uid', '')
             uid_code = request_dict.get('uid_code', None)
+            companyMark = '11A'
             if not uid:
                 # 使用序列号
                 serial_number = request_dict.get('serial_number', None)
@@ -104,6 +105,7 @@ class IotCoreView(View):
                     return response.json(404)
 
                 serial = serial_number[0:6]
+                companyMark = serial_number[-3:]
                 try:
                     SerialNumberModel.objects.get(serial_number=serial)
                 except:
@@ -123,7 +125,6 @@ class IotCoreView(View):
                 iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(uid=uid)
             # 判断设备是否已注册证书
             if not iotdeviceInfo_qs.exists():
-                thingGroup = device_version + '_' + language
                 # 设备模拟国外环境测试
                 # if SERVER_TYPE == 'Ansjer.us_config.formal_settings':  # 国外正式配置使用固定ip进行测试
                 #     ip = '67.220.90.13'
@@ -131,11 +132,19 @@ class IotCoreView(View):
                 #     ip = CommonService.get_ip_address(request)
                 ip = CommonService.get_ip_address(request)
                 region_id = Device_Region().get_device_region(ip)
-
                 iotClient = IOTClient(region_id)
-                res = iotClient.register_to_iot_core(ThingNameSuffix, thingGroup, response)
-                token_iot_number = hashlib.md5((str(uuid.uuid1()) + str(int(time.time()))).encode('utf-8')).hexdigest()
 
+                # 拼接物品名
+                if companyMark == '11A':
+                    ThingName = 'Ansjer_Device_' + ThingNameSuffix
+                elif companyMark == '11L':
+                    ThingName = 'Loocam_Device_' + ThingNameSuffix
+                else:
+                    ThingName = ThingNameSuffix
+                thingGroup = device_version + '_' + language
+                res = iotClient.register_to_iot_core(ThingName, thingGroup, response)
+
+                token_iot_number = hashlib.md5((str(uuid.uuid1()) + str(int(time.time()))).encode('utf-8')).hexdigest()
                 iotdeviceInfoModel.objects.create(uid=uid,
                                                   serial_number=serial,
                                                   endpoint=res[0]['endpoint'],

+ 2 - 2
Object/IOTCore/IotObject.py

@@ -58,7 +58,7 @@ class IOTClient:
         }
         return res
 
-    def register_to_iot_core(self, ThingNameSuffix, thingGroup, response):
+    def register_to_iot_core(self, ThingName, thingGroup, response):
         try:
             result = self.client.create_keys_and_certificate(setAsActive=True)
             res = {
@@ -136,7 +136,7 @@ class IOTClient:
                     },
                 }
             }
-            ThingName = 'Ansjer_Device_' + ThingNameSuffix
+
             templateBody = json.dumps(templateBody)
             parameters = {"ThingName": ThingName,
                           "thingGroupName": thingGroupName,