mlesniew / PicoMQTT

ESP MQTT client and broker library
GNU Lesser General Public License v3.0
219 stars 25 forks source link

Custom port #7

Closed fbritop closed 11 months ago

fbritop commented 1 year ago

Is it possible to setup the port manually? I cannot find any public method to it

dasflaigsi commented 1 year ago

I would guess you can put in into constructor Client::Client(const char * host, uint16_t port, const char * id, const char * user, const char * password, unsigned long reconnect_interval_millis)

Therefore PicoMQTT::Client mqtt("broker.hivemq.com", 12345);

mlesniew commented 1 year ago

@dasflaigsi is correct, the client's constructor allows specifying optional parameters. The 2nd parameter is the port number. It defaults to 1883.

Here's the constructor declaration: https://github.com/mlesniew/PicoMQTT/blob/master/src/PicoMQTT/client.h#L46

FWallenwein commented 11 months ago

Can't find a way to do the same for a Server ? Is there any way to set a custom port for a MQTT Server ?

mlesniew commented 11 months ago

Looks like the Server didn't have a constructor that would allow this. It's fixed in v0.3.4, now you can do:

PicoMQTT::Server mqtt(1234 /* custom port */);