继续操作前请注册或者登录。
提交 ebe06f77 authored 作者: zxd's avatar zxd

发送emqq

上级 81a400a1
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
"serial_no": "WF00000001", "serial_no": "WF00000001",
"measurements": [ "measurements": [
{ {
"measurement": "door", "measurement": "temperature",
"type": 0, "type": 0,
"random_type": 1, "random_type": 1,
"port": "c", "port": "a",
"port_address": 1 "port_address": 0
} }
] ]
}, },
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
"serial_no": "WF00000002", "serial_no": "WF00000002",
"measurements": [ "measurements": [
{ {
"measurement": "door", "measurement": "temperature",
"type": 0, "type": 0,
"random_type": 1, "random_type": 1,
"port": "c", "port": "a",
"port_address": 1 "port_address": 0
} }
] ]
}, },
...@@ -36,11 +36,11 @@ ...@@ -36,11 +36,11 @@
"serial_no": "WF00000003", "serial_no": "WF00000003",
"measurements": [ "measurements": [
{ {
"measurement": "door", "measurement": "temperature",
"type": 0, "type": 0,
"random_type": 1, "random_type": 1,
"port": "c", "port": "a",
"port_address": 1 "port_address": 0
} }
] ]
} }
......
...@@ -14,7 +14,7 @@ sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..')) ...@@ -14,7 +14,7 @@ sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
sys.path.append("..") sys.path.append("..")
client_id = f'' client_id = f''
topic = "/a1hjFmQV0zo" topic = "/ILSA-HW-TM0212"
username = "admin" username = "admin"
password = "public" password = "public"
...@@ -28,10 +28,10 @@ cmdTemplate = """ ...@@ -28,10 +28,10 @@ cmdTemplate = """
"time": {time}, "time": {time},
"mqttTopic": "{topic}/{devSn1}/user/group/data", "mqttTopic": "{topic}/{devSn1}/user/group/data",
"type": "data", "type": "data",
"deviceName": "105104012101126339", "deviceName": "{devName}",
"group": "saaspri", "group": "saaspri",
"network": "wifi", "network": "wifi",
"middleware": "hub" "middleware": "emq"
}} }}
""" """
...@@ -69,7 +69,7 @@ cmdResponse = """ ...@@ -69,7 +69,7 @@ cmdResponse = """
def getTelemetry(param): def getTelemetry(param):
t = time.time() t = int(time.time())
l = len(param) l = len(param)
tjsons = [] tjsons = []
for i in range(l): for i in range(l):
...@@ -108,13 +108,15 @@ def on_message_come(lient, userdata, msg): ...@@ -108,13 +108,15 @@ def on_message_come(lient, userdata, msg):
cmd = msgJson.get("cmd") cmd = msgJson.get("cmd")
devSn = msgJson.get("devSN") devSn = msgJson.get("devSN")
id = msgJson.get("id") id = msgJson.get("id")
responseTopic = msg.topic + "/response" responseTopic = msg.topic[0:msg.topic.rfind('/', 1)] + "/group/cmd/response"
info = cmdResponse.format(devSn=devSn, cmd=cmd, time=str(time.time()), id=id, topic=responseTopic, devSn1=devSn) info = cmdResponse.format(devSn=devSn, cmd=cmd, time=str(int(time.time())), id=id, topic=responseTopic,
devSn1=devSn)
on_publish(lient, responseTopic, info, 1) on_publish(lient, responseTopic, info, 1)
def on_publish(lient, topic, payload, qos): def on_publish(lient, topic, payload, qos):
print("发送:" + payload)
lient.publish(topic, payload, qos) lient.publish(topic, payload, qos)
...@@ -138,7 +140,7 @@ def run(ip, port, msg, topicSn, sn): ...@@ -138,7 +140,7 @@ def run(ip, port, msg, topicSn, sn):
# 订阅 # 订阅
serverClient = connect_mqtt(ip=ip, port=port) serverClient = connect_mqtt(ip=ip, port=port)
on_mqtt_connect(serverClient=serverClient, ip=ip, port=port) on_mqtt_connect(serverClient=serverClient, ip=ip, port=port)
on_subscribe(serverClient, serverTopic=topic + "/" + sn + "/user/group/cmd") on_subscribe(serverClient, serverTopic="/ILSA-HW-TM0212" + "/" + sn + "/user/cmd")
client = connect_mqtt(ip=ip, port=port) client = connect_mqtt(ip=ip, port=port)
...@@ -149,8 +151,8 @@ def run(ip, port, msg, topicSn, sn): ...@@ -149,8 +151,8 @@ def run(ip, port, msg, topicSn, sn):
def test(data): def test(data):
while True: while True:
tel = getTelemetry(data.get("measurements")) tel = getTelemetry(data.get("measurements"))
cmd = cmdTemplate.format(devSN=data.get("serial_no"), telemetry=tel, time=str(time.time()), cmd = cmdTemplate.format(devSN=data.get("serial_no"), telemetry=tel, time=str(int(time.time())),
devSn1=data.get("serial_no"), topic=topic) devSn1=data.get("serial_no"), topic=topic, devName=data.get("serial_no"))
cmdJson = json.loads(cmd) cmdJson = json.loads(cmd)
topicSn = cmdJson.get("mqttTopic") topicSn = cmdJson.get("mqttTopic")
# print(cmd) # print(cmd)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论