-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send MQTT server's username and password #91
Comments
Use |
Sorry to hijack but it's still open and the same issue. Here is the snippet of where I inserted it but tbh I have tried about 20 places to no avail. For the moment I have set my username to //start of my code that was previously connecting to mosquitto.org without needing credentials
void mqttSetup()
{
// You can provide a username and password for authentication
mqttClient.setUsernamePassword("mummy", "raspberry"); //where does this line go?
Serial.print("Attempting to connect to the MQTT server: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port));{
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT server!");
Serial.println();
}
void mqttRunning()
{ // call poll() regularly to allow the library to send MQTT keep alive which
// avoids being disconnected by the broker
mqttClient.poll();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time a message was sent
previousMillis = currentMillis;
//record mkr env values
float Rvalue = ENV.readTemperature();
float Rvalue2 = ENV.readHumidity();
float Rvalue3 = (ENV.readPressure()*10.5);
float Rvalue4 = ENV.readIlluminance();
float Rvalue5 = ENV.readUVA();
float Rvalue6 = ENV.readUVB();
float Rvalue7 = ENV.readUVIndex();
void mqttSetup()
{
// You can provide a username and password for authentication
mqttClient.setUsernamePassword("mummy", "raspberry");
Serial.print("Attempting to connect to the MQTT server: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port));{
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT server!");
Serial.println();
}
void mqttRunning()
{ // call poll() regularly to allow the library to send MQTT keep alive which
// avoids being disconnected by the broker
mqttClient.poll();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time a message was sent
previousMillis = currentMillis;
//record mkr env values
float Rvalue = ENV.readTemperature();
float Rvalue2 = ENV.readHumidity();
float Rvalue3 = (ENV.readPressure()*10.5);
float Rvalue4 = ENV.readIlluminance();
float Rvalue5 = ENV.readUVA();
float Rvalue6 = ENV.readUVB();
float Rvalue7 = ENV.readUVIndex(); |
Hi.
Using the library, is it possible to connect to an MQTT server (Mosquitto) thas requires authentication based on username and password?
Actually I'm using
mqttClient.connect(broker, port)
, but I don't know how to provide MQTT server's username and password.Any idea?
The text was updated successfully, but these errors were encountered: