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;
}
}