nodemcu / nodemcu-firmware

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

ESP32: IDFv5.0 Fix mqtt module #3607

Closed serg3295 closed 11 months ago

serg3295 commented 11 months ago

The mqtt module does not work with IDFv5.0 I think an additional user_config checks were added in new espressif/esp-mqtt submodule.

Error log:

NodeMCU ESP32 build unspecified powered by Lua 5.3.5 [5.3-int32-singlefp] on IDF v5.0.2

new m:  userdata: 0x3ffcac84

> m:connect('mqtt://192.168.1.31')
W (131404) mqtt_client: Transport config set, but overridden by scheme from URI: transport = 1, uri scheme = mqtt
W (131404) mqtt_client: Client asked to stop, but was not started
Lua error:  stdin:1: MQTT library failed to start
stack traceback:
    [C]: in method 'connect'
    stdin:1: in main chunk
    [C]: in ?
    [C]: in ?

> m:connect('192.168.1.31')
E (159984) mqtt_client: No scheme found
E (159984) mqtt_client: Failed to create transport list
Lua error:  stdin:1: Error starting mqtt client
stack traceback:
    [C]: in method 'connect'
    stdin:1: in main chunk
    [C]: in ?
    [C]: in ?

This PR fixes that error.

serg3295 commented 11 months ago

Small fixes. Select next parameter in mqtt:connect() when port or secure are nil Test cases:

m:connect('mqtt://192.168.1.31', nil, nil, 0, function()
    print("MQTT connected! Full uri.")
  end,
  function(client)
    print("MQTT disconnected! Full uri.")
  end
)

-- or
m:connect('mqtt://192.168.1.31', nil, 0)
serg3295 commented 11 months ago

Sorry, my last commit incorrectly handles the case mqtt:connect("server", function(client) print("connected") end, handle_mqtt_error) An additional check on port==nil, secure==nil is required before n++;

Fixed.

jmattsson commented 11 months ago

Thank you for the PR @serg3295 ! Merge has been done!