首页 文章

NodeMCU无法使用TLS连接到Bluemix

提问于
浏览
4

我尝试将NodeMCU与IBM Bluemix IoT Foundation连接起来 . 不安全的MQTT连接非常出色,可以将数据从BMP180推送到 Cloud 端 . 但是,当我开始使用TLS时,它将无法连接到代理 . 我尝试与mqtt.fx Build TLS连接并且工作正常,看起来NodeMCU就是问题所在 . 如果我运行此代码:

orgID="****"
BROKER = orgID..".<bluemix>"
BRPORT = 8883

CLIENTID = "d:"..orgID..":generic_esp:generic_esp_01"
print("ClientID: "..CLIENTID)
BRPWD  = "***********"

BRUSER = "use-token-auth"

local function publish()
   dofile('sensor.lc')
   m:publish('iot-2/evt/esp8266/fmt/json',payload,1,0, 
            function(conn) print('Payload published') end)
end

m = mqtt.Client(CLIENTID, 120, BRUSER, BRPWD)
c = false

print('MQTT Init')
m:on('offline', function(con) print('mqtt offline'); c = false end)
m:connect(BROKER, BRPORT, 1, function(conn) 
   print('MQTT connected: '..BROKER..':'..BRPORT) 
   c = true 
   publish()
end)

tmr.alarm(1, 1000, 1, function() 
    if not c then
      print('MQTT reconnecting')
      m:close()
      c = false
      m:connect(BROKER, BRPORT, 1, function(conn) print('.. MQTT reconnected: '..BROKER..':'..BRPORT); c = true end)
    end
    if c then
      publish()
    end
 end)

esp8266只打印“MQTT重新连接”,无法连接 . 我的代码有问题,或者在NodeMCU 1.4中没有完全支持TLS,但是?

1 回答

  • 2

    我在我们的一个试验台上 grab 了你的客户问候:

    0000 16 03 02 00 33 01 00 00 2f 03 02 00 00 00 00 d0 0010 b1 a1 3a 07 1c 1b 3e f2 fc 03 91 d6 18 b5 ae 5d 0020 77 65 37 f5 07 10 45 d1 7e 1a ea 00 00 08 00 2f 0030 00 35 00 05 00 04 01 00

    这看起来像TLS v1 . 1 客户问候 . 通常客户会用它可以做的"best"打招呼并向下协商 . 在这种情况下,IoTF将简单地关闭连接,因为它仅支持TLS 1.2 . 您能否检查一下您的设备是否设置为执行TLS 1.2?

相关问题