onene平台连接第二个设备,订阅发布都成功了,就是没有数...
能不能创建数据上传啊。这是代码
timer = tmr.create()
timer2 = tmr.create()
timer3 = tmr.create()
cfg = {}
cfg.ssid = "Reno10"
cfg.pwd = "hg888888"
wifi.setmode(wifi.STATION)
wifi.sta.config(cfg)
wifi.sta.connect()
led_pin = 7
dht_pin = 5
DeviceId_T3BDJF = "600853691"
ProductId_JFJK = "350320"
AuthoInfo_T3BDJF = "202006011816"
DeviceId_T2XJJF = "601394998"
ProductId_JFJK = "350320"
AuthoInfo_T2XJJF = "202006041242"
host = "183.230.40.39"
port = 6002
gpio.mode(7,gpio.OUTPUT)
gpio.write(7,gpio.LOW)
gpio.mode(8,gpio.OUTPUT)
gpio.write(8,gpio.LOW)
function reconnect()
if wifi.sta.getip() == nil then
print("disconnect,Waiting for IP ...")
else
timer:stop()
print("connect success")
print(wifi.sta.getip())
client_TempHumi = mqtt.Client(DeviceId_T3BDJF,120,ProductId_JFJK,AuthoInfo_T3BDJF,0)
client_TempHumi:connect(host,port,0,function(client)
print("connection to server success!T3BDJF")
end)
client_fmq = mqtt.Client(DeviceId_T2XJJF,120,ProductId_JFJK,AuthoInfo_T2XJJF,0)
client_fmq:connect(host,port,0,function(client)
print("connection to server success!T2XJJF")
end)
timer2:alarm(1500, tmr.ALARM_AUTO,T3BDJF)
timer3:alarm(4500, tmr.ALARM_AUTO,T2XJJF)
end
end
function T3BDJF()
status, temp, humi, temp_dec, humi_dec = dht.read11(dht_pin)
print("T3BDJF-Temp:"..temp,"T3BDJF-humi:"..humi)
weather = {}
weather.Temperature = temp
weather.Humidity = humi
state,weather_message = pcall(sjson.encode,weather)
payload = string.char(3,0,string.len(weather_message))..weather_message
--client_TempHumi:publish(topic, payload, qos, retain[, function(client)])
client_TempHumi:publish("$dp", payload, 0, 0, function(client)
print("pudlish(shujvshangchuan) success!T3BDJF")
end)
client_TempHumi:subscribe("$dp",0, function(client)
print("subscribe(dingyuekaiguan) success!T3BDJF")
end)
client_TempHumi:on("message", function(client,topic,message)
print(message)
if (message == "1") then
gpio.write(7,gpio.HIGH)
else
gpio.write(7,gpio.LOW)
end
end)
end
function T2XJJF()
status, temp, humi, temp_dec, humi_dec = dht.read11(dht_pin)
print("T2XJJF-temp:"..temp,"T2XJJF-humi:"..humi)
weather = {}
weather.Temperature = temp
weather.Humidity = humi
state,weather_message = pcall(sjson.encode,weather)
payload = string.char(3,0,string.len(weather_message))..weather_message
--client_TempHumi:publish(topic, payload, qos, retain[, function(client)])
client_TempHumi:publish("$dp", payload, 0, 0, function(client)
print("pudlish(shujvshangchuan) success!T2XJJF")
end)
client_TempHumi:subscribe("$dp",0, function(client)
print("subscribe(dingyuekaiguan) success!T2XJJF")
end)
client_TempHumi:on("message", function(client,topic,message)
print(message)
if (message == "1") then
gpio.write(8,gpio.HIGH)
else
gpio.write(8,gpio.LOW)
end
end)
end
timer:alarm(1000, tmr.ALARM_AUTO, reconnect)
那位大师或者大神给看看感谢
页:
[1]