nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

MQTT TLS issue #980

Closed trahloff closed 8 years ago

trahloff commented 8 years ago

I try to connect the NodeMCU with the IBM Bluemix IoT Foundation. The unsecured MQTT connect works splendid and pushes data from a BMP180 to the cloud. However, when I start using TLS it won't connect to the broker. I tried to make a TLS connection with MQTT.fx and it works fine, it seems like the NodeMCU is the problem. If I run this code:

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)

the esp8266 just prints "MQTT reconnecting" and can't connect.

marcelstoer commented 8 years ago

It's too early too rule out a bug in NodeMCU MQTT but as per #719 and since you a) don't have a (publicly) reproducible test case and b) created the same issue on SO it should be tracked there first.