tuanpmt / esp_mqtt

MQTT client library for ESP8266
http://tuanpm.net/post/esp_mqtt/
MIT License
1.14k stars 400 forks source link

Extend init method to allow 0-length client IDs if MQTTv311 is set #127

Closed someburner closed 7 years ago

someburner commented 7 years ago

Adds support for 0 length client IDs. This is extremely helpful if you have more than a couple ESPs running around. Most brokers should support this- tested on libmosquitto, which has had support for this since v1.4 and also with iot.eclipse.org.

Basically if the v311 broker detects a 0 length client ID it will use libuuid to automatically generate a 16 byte UUID. This avoids having to rely on the ESPs questionable ability to generate unique, random numbers, not to mention a bit of saved memory & code complexity.

I also changed the init method to return a bool since if you have v31 set there's not much point if you dont assign a client ID. But this might break stuff for people that have left it as is.. I recommend defaulting to 311. This could probably be made a bit cleaner and I haven't tested against sdk2.0 or w/ SSL.

Example of what the broker does w v311 set and NULL passed in for client ID: selection_026

tuanpmt commented 7 years ago

Thanks