whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.2k stars 221 forks source link

MQTT publish with QoS > 0 seems it doesn't working #138

Closed piebat closed 6 years ago

piebat commented 6 years ago

MQTT publish with QoS > 0 seems doesn't work. I tried to publish the message with QoS = 1 and 2, but this message raise:

201326596:can't publish to topic (enable persistence for a qos > 0)

I couldn't find documentation about how to change the persistence and seems that default is: MQTTCLIENT_PERSISTENCE_NONE instead than MQTTCLIENT_PERSISTENCE_DEFAULT.

The environment is: Lua RTOS beta 0.1. build 1523007799 commit 5d9b98a49aeb0a799c3949ba9bf904f591963756 Running from factory partition board type ESP32COREBOARD cpu ESP32 rev 1 at 240 Mhz spiffs0 start address at 0x310000, size 512 Kb, partition spiffs spiffs0 mounted

With QOS0 work fine.

bytebang commented 6 years ago

It works fine - but the documentation seems to be outdated. Try this:

client = mqtt.client("testclient","iot.eclipse.org", 1883, false, "", true, "var/mqtt")
client:connect("","")
client:publish("testclient","mytopic",mqtt.QOS1)

Line 1 creates a mqtt client with no security, but with persistence. The parameters are as follows:

  1. string: mqtt clientId (should be unique)
  2. string: mqtt broker
  3. int: port
  4. boolean: use security
  5. string: path to CA file (only needed if security is enabled with parameter 4)
  6. boolean: use persistence
  7. string: directory where the persistence files shuold live. (Its ok to use subdirs here - they are created automatically)

After you have connected to the broker you can use QOS1 or QOS2 as well.

jolivepetrus commented 6 years ago

@bytebang,

Thanks for the documentation issue. It has been updated.

piebat commented 6 years ago

@bytebang Thanks Ghunter, work fine.