hirotakaster / MQTT

MQTT for Photon, Spark Core
Other
216 stars 118 forks source link

Support for changing server address after constructing object #50

Closed nitej closed 7 years ago

nitej commented 7 years ago

Would it be possible to support changing the server address after constructing the mqtt object? This would be useful if one wants to change the mqtt broker address without reflashing.

hirotakaster commented 7 years ago

hi @foodbag , okay, I will update initialize method to public. then disconnect/connect like this.

mqtt.publish("topic/", "hoge"); 
mqtt.disconnect();
mqtt.initialize("example.com", NULL, 1883, callback, MQTT_MAX_PACKET_SIZE);
mqtt.publish("topic/", "hoge");
nitej commented 7 years ago

That would be great. Thanks!

nitej commented 7 years ago

Using the initialize method to update the broker address may cause a memory leak if called multiple times before resetting. It might be safer to update just the domain/ip and port rather than reinitializing.