Forráskód Böngészése

修改mqtt物品名

peng 3 éve
szülő
commit
ca119a00df
1 módosított fájl, 9 hozzáadás és 4 törlés
  1. 9 4
      Service/CommonService.py

+ 9 - 4
Service/CommonService.py

@@ -477,21 +477,26 @@ class CommonService:
             return False
 
     @staticmethod
-    def req_publish_mqtt_msg(thing_name, topic_name, msg):
+    def req_publish_mqtt_msg(identification_code, topic_name, msg):
         """
         通用发布MQTT消息函数
-        @param thing_name: 物品名
+        @param identification_code: 标识码
         @param topic_name: 主题名
         @param msg: 消息内容
         @return: boolean
         """
-        if not all([thing_name, topic_name]):
+        if not all([identification_code, topic_name]):
             return False
 
+        if identification_code.endswith('11L'):
+            thing_name = 'LC_' + identification_code
+        else:
+            thing_name = 'Ansjer_Device_' + identification_code
+
         try:
             # 获取数据组织将要请求的url
             iot = iotdeviceInfoModel.objects.filter(
-                thing_name__icontains=thing_name).values(
+                thing_name=thing_name).values(
                 'endpoint', 'token_iot_number')
             if not iot.exists():
                 return False