瀏覽代碼

完善iot代码注释和函数名

locky 3 年之前
父節點
當前提交
844351d291
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 1 1
      Controller/IotCoreController.py
  2. 5 1
      Object/IOTCore/IotObject.py

+ 1 - 1
Controller/IotCoreController.py

@@ -124,7 +124,7 @@ class IotCoreView(View):
             region_id = Device_Region().get_device_region(ip)
 
             iotClient = IOTClient(region_id)
-            res = iotClient.create_keys_and_certificate(ThingNameSuffix, thingGroup, response)
+            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()
 
             iotdeviceInfoModel.objects.create(uid=uid,

+ 5 - 1
Object/IOTCore/IotObject.py

@@ -27,6 +27,7 @@ class IOTClient(IOTObject):
     def __init__(self, region_id=1):
 
         if region_id == 1:
+            # 中国宁夏
             self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_CHINA_REGION,
                                        aws_access_key_id=AWS_IOT_SES_ACCESS_CHINA_ID,
                                        aws_secret_access_key=AWS_IOT_SES_ACCESS_CHINA_SECRET)
@@ -35,6 +36,7 @@ class IOTClient(IOTObject):
             self.iotrole = AWS_IOT_SES_ACCESS_CHINA_ROLE
 
         if region_id == 2:
+            # 亚太新加坡
             self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_ASIA,
                                        aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
                                        aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
@@ -42,6 +44,7 @@ class IOTClient(IOTObject):
             self.iotrole = AWS_IOT_SES_ACCESS_FOREIGN_ROLE
 
         if region_id == 3:
+            # 美东弗吉尼亚
             self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_AMERICA,
                                        aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
                                        aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
@@ -49,6 +52,7 @@ class IOTClient(IOTObject):
             self.iotrole = AWS_IOT_SES_ACCESS_FOREIGN_ROLE
 
         if region_id == 4:
+            # 西欧爱尔兰
             self.client = boto3.client('iot', region_name=AWS_IOT_SES_ACCESS_FOREIGN_REGION_EUROPE,
                                        aws_access_key_id=AWS_IOT_SES_ACCESS_FOREIGN_ID,
                                        aws_secret_access_key=AWS_IOT_SES_ACCESS_FOREIGN_SECRET)
@@ -70,7 +74,7 @@ class IOTClient(IOTObject):
         }
         return res
 
-    def create_keys_and_certificate(self, ThingNameSuffix, thingGroup, response):
+    def register_to_iot_core(self, ThingNameSuffix, thingGroup, response):
         try:
             result = self.client.create_keys_and_certificate(setAsActive=True)
             res = {