Open ssolmaz opened 7 years ago
Hi @ssolmaz,
please refer to PubSubClient API documentation here:
http://pubsubclient.knolleary.net/api.html
Section that you are looking for is this one:
boolean connect (clientID, username, password, willTopic, willQoS, willRetain, willMessage)
So basically you need at top to just add constant for username and password and on line 60 change connection according to mentioned documentation.
BR,
Martin
Thank you for the answer, Martin. Because I'm a beginner, I could not place a sketch the line. I still can not connect to mqtt. But with the following code I can use a different sketch.
const PROGMEM char MQTT_USER = "user"; const PROGMEM char MQTT_PASSWORD = "password";
// Attempt to connect if (client.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASSWORD)) {
Add the required user and password after the // sign in the code. Also add the necessary code for config.json to the README.md page. It is useful for beginner like me.
Thank you.
Hi @ssolmaz,
I could change the code but it would be untested. I do not have MQTT broker authenticated so I can't test it. Also I had originally problems with authentication (I have Mosquitto) so I turned it off. If your MQTT broker is in local network my suggestion is you do the same thing. Authentication just make things worse in such scenarion.
Martin
hi martin, I'm trying to use this sketch but my mqtt server has a username password. How do I add a code to this sketch? Can you help me please?