onene平台连接第二个设备,订阅发布都成功了,就是没有数...-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3427|回复: 1

onene平台连接第二个设备,订阅发布都成功了,就是没有数...

[复制链接]
发表于 2020-6-6 00:27 | 显示全部楼层 |阅读模式
能不能创建数据上传啊。
这是代码
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_TempHumin("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_TempHumin("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)


 楼主| 发表于 2020-6-6 00:28 | 显示全部楼层
那位大师或者大神给看看感谢
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-1 04:58 , Processed in 0.114631 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表