CayenneMQTTWiFiClient.begin called without WIFI being connected

I get the error "CayenneMQTTWiFiClient.begin called without WIFI being connected.

This is on a Wemos D1 mini Pro, sometimes it connects but mostly not and I’m less than 10 feet from the router.
This is the program:

#define SENSOR_PIN D5 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 1
#define ESP8266_LED D6

int previousState = 0;
int currentState = 1;
int sensorValue = digitalRead(D5);
void setup()

{
pinMode(SENSOR_PIN, INPUT_PULLUP);
pinMode(ESP8266_LED, OUTPUT);

digitalWrite(ESP8266_LED, HIGH);
Serial.begin(115200);
Cayenne.begin(username, password, clientID);
Serial.print(“Connecting”);
while(WiFi.status() != WL_CONNECTED)
{
delay (500);
Serial.print(“.”);
}
// Serial.print();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
digitalWrite(ESP8266_LED, LOW);

}

void loop()
{
Cayenne.loop();
Serial.print(WiFi.RSSI());
Serial.println(sensorValue);
currentState = digitalRead(SENSOR_PIN);
if (currentState != previousState) {
Cayenne.virtualWrite(VIRTUAL_CHANNEL, currentState);

previousState = currentState;

}
}

i did not understand what is the issue. can you share the entire serial monitor output by adding #define CAYENNE_DEBUG in your code.

CayenneMQTTWiFiClient.begin called without WIFI being connected. Either use begin (…, ssid, wifipassword) to establish the connection here. Or setup the WIFI connection manually before calling this variant of the begin function
[83] IP: 0.0.0.0
[85] Connecting to mqtt.mydevices.com:1883
[89] Network connect failed

i guess you are using the wrong code. use this https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/feature/gsm-support/examples/Connections/ESP8266/ESP8266.ino

The problem was this line:
Cayenne.begin(username, password, clientID);
I changed it to:
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

And now it works fine

1 Like