mirror of
https://github.com/kerwincui/FastBee.git
synced 2025-10-13 11:54:03 +08:00
固件添加设备信息订阅,解决设备状态同步问题
This commit is contained in:
@@ -45,6 +45,7 @@ String ntpServer = "http://wumei.live:8080/iot/tool/ntp?deviceSendTime=";
|
||||
|
||||
// 订阅的主题
|
||||
String prefix = "/" + productId + "/" + deviceNum;
|
||||
String sInfoTopic = prefix + "/info/get";
|
||||
String sOtaTopic = prefix + "/ota/get";
|
||||
String sNtpTopic = prefix + "/ntp/get";
|
||||
String sPropertyTopic = prefix + "/property/get";
|
||||
@@ -154,6 +155,12 @@ void callback(char *topic, byte *payload, unsigned int length)
|
||||
printMsg("固件版本:"+newVersion);
|
||||
printMsg("下载地址:"+downloadUrl);
|
||||
}
|
||||
else if (strcmp(topic, sInfoTopic.c_str()) == 0)
|
||||
{
|
||||
printMsg("订阅到设备信息...");
|
||||
// 发布设备信息
|
||||
publishInfo();
|
||||
}
|
||||
else if (strcmp(topic, sNtpTopic.c_str()) == 0)
|
||||
{
|
||||
printMsg("订阅到NTP时间...");
|
||||
@@ -235,7 +242,8 @@ void connectMqtt()
|
||||
if (connectResult)
|
||||
{
|
||||
printMsg("连接成功");
|
||||
// 订阅(OTA、NTP、属性、功能、实时监测)
|
||||
// 订阅(OTA、NTP、属性、功能、实时监测、信息)
|
||||
mqttClient.subscribe(sInfoTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sOtaTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sNtpTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sPropertyTopic.c_str(), 1);
|
||||
@@ -243,6 +251,7 @@ void connectMqtt()
|
||||
mqttClient.subscribe(sPropertyOnline.c_str(), 1);
|
||||
mqttClient.subscribe(sFunctionOnline.c_str(), 1);
|
||||
mqttClient.subscribe(sMonitorTopic.c_str(), 1);
|
||||
printMsg("订阅主题:" + sInfoTopic);
|
||||
printMsg("订阅主题:" + sOtaTopic);
|
||||
printMsg("订阅主题:" + sNtpTopic);
|
||||
printMsg("订阅主题:" + sPropertyTopic);
|
||||
|
@@ -44,6 +44,7 @@ String ntpServer = "http://wumei.live:8080/iot/tool/ntp?deviceSendTime=";
|
||||
|
||||
// 订阅的主题
|
||||
String prefix = "/" + productId + "/" + deviceNum;
|
||||
String sInfoTopic = prefix + "/info/get";
|
||||
String sOtaTopic = prefix + "/ota/get";
|
||||
String sNtpTopic = prefix + "/ntp/get";
|
||||
String sPropertyTopic = prefix + "/property/get";
|
||||
@@ -149,6 +150,12 @@ void callback(char *topic, byte *payload, unsigned int length)
|
||||
printMsg("固件版本:"+newVersion);
|
||||
printMsg("下载地址:"+downloadUrl);
|
||||
}
|
||||
else if (strcmp(topic, sInfoTopic.c_str()) == 0)
|
||||
{
|
||||
printMsg("订阅到设备信息...");
|
||||
// 发布设备信息
|
||||
publishInfo();
|
||||
}
|
||||
else if (strcmp(topic, sNtpTopic.c_str()) == 0)
|
||||
{
|
||||
printMsg("订阅到NTP时间...");
|
||||
@@ -230,7 +237,8 @@ void connectMqtt()
|
||||
if (connectResult)
|
||||
{
|
||||
printMsg("连接成功");
|
||||
// 订阅(OTA、NTP、属性、功能、实时监测)
|
||||
// 订阅(OTA、NTP、属性、功能、实时监测、信息)
|
||||
mqttClient.subscribe(sInfoTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sOtaTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sNtpTopic.c_str(), 1);
|
||||
mqttClient.subscribe(sPropertyTopic.c_str(), 1);
|
||||
@@ -238,6 +246,7 @@ void connectMqtt()
|
||||
mqttClient.subscribe(sPropertyOnline.c_str(), 1);
|
||||
mqttClient.subscribe(sFunctionOnline.c_str(), 1);
|
||||
mqttClient.subscribe(sMonitorTopic.c_str(), 1);
|
||||
printMsg("订阅主题:" + sInfoTopic);
|
||||
printMsg("订阅主题:" + sOtaTopic);
|
||||
printMsg("订阅主题:" + sNtpTopic);
|
||||
printMsg("订阅主题:" + sPropertyTopic);
|
||||
|
@@ -52,6 +52,7 @@ authCode=""
|
||||
|
||||
# 订阅的主题
|
||||
prefix = "/" + productId + "/" + deviceNum
|
||||
sInfoTopic = prefix + "/info/get"
|
||||
sOtaTopic = prefix + "/ota/get"
|
||||
sNtpTopic = prefix + "/ntp/get"
|
||||
sPropertyTopic = prefix + "/property/get"
|
||||
@@ -96,7 +97,7 @@ def on_connect(client,userdata,flags,rc):
|
||||
printMsg("连接成功")
|
||||
# 放在on_connect下可以保证重连重新订阅
|
||||
# 订阅(OTA、NTP、属性、功能、实时监测)
|
||||
|
||||
client.subscribe(sInfoTopic, 1)
|
||||
client.subscribe(sOtaTopic, 1)
|
||||
client.subscribe(sNtpTopic, 1)
|
||||
client.subscribe(sPropertyTopic, 1)
|
||||
@@ -105,6 +106,7 @@ def on_connect(client,userdata,flags,rc):
|
||||
client.subscribe(sFunctionOnline, 1)
|
||||
client.subscribe(sMonitorTopic, 1)
|
||||
|
||||
printMsg("订阅主题:" + sInfoTopic)
|
||||
printMsg("订阅主题:" + sOtaTopic)
|
||||
printMsg("订阅主题:" + sNtpTopic)
|
||||
printMsg("订阅主题:" + sPropertyTopic)
|
||||
@@ -166,6 +168,10 @@ def on_message(client,userdata,msg):
|
||||
downloadUrl = jsonData["downloadUrl"]
|
||||
printMsg("固件版本:"+newVersion)
|
||||
printMsg("下载地址:"+downloadUrl)
|
||||
elif(msg.topic==sInfoTopic):
|
||||
printMsg("订阅到设备信息指令...")
|
||||
# 发布设备信息
|
||||
publishInfo()
|
||||
elif(msg.topic==sNtpTopic):
|
||||
printMsg("订阅到NTP时间...");
|
||||
jsonData=json.loads(msg.payload)
|
||||
|
Reference in New Issue
Block a user