I'm trying to improve the EPD47 weather station with ESP32.
Because i want it to be portable from WiFi to different WiFi i thought about using the AutoConnect Library. Making a Hotspot and connecting to a WiFI, then use it in my normal Script.
The AutoConnectCredential.h allows access to the stored WiFi Paswords.
So the things i used in my script are:
static uint8_t ssid_test[32], password_test[64];
void creds(){
AutoConnectCredential ac(0);
station_config_t entry;
uint8_t count = ac.entries(); // Get number of entries.
for (int8_t i = 0; i < count; i++) { // Loads all entries.
ac.load(i, &entry);
Serial.print(String((char *)entry.ssid));
memcpy(ssid_test, entry.ssid, 32);
memcpy(password_test, entry.password, 64);
Serial.print((char *)password_test);
//ssid_test = (char *)entry.ssid; //WiFi SSID Names
//password_test = (char *)entry.password; //WiFi Passwords
if (StartWiFi() == WL_CONNECTED) {
Serial.println("Connected... or such");
}
//Connect to each WiFi Here...
}
}
uint8_t StartWiFi() {
Serial.println("\r\nConnecting to: " + String((char *)ssid_test));
IPAddress dns(8, 8, 8, 8); // Use Google DNS
WiFi.disconnect();
WiFi.mode(WIFI_STA); // switch off AP
WiFi.setAutoConnect(true);
WiFi.setAutoReconnect(true);
//WiFi.begin(ssid_test.c_str(), password_test.c_str());
WiFi.begin((char *)ssid_test, (char *)password_test);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("STA: Failed!\n");
WiFi.disconnect(false);
delay(500);
WiFi.begin((char *)ssid_test, (char *)password_test);
}
if (WiFi.status() == WL_CONNECTED) {
wifi_signal = WiFi.RSSI(); // Get Wifi Signal strength now, because the WiFi will be turned off to save power!
Serial.println("WiFi connected at: " + WiFi.localIP().toString());
}
else {
Serial.println("WiFi connection *** FAILED ***");
//NoWiFiTurnOff();
}
return WiFi.status();
}
The problem is the SerialPrint does show the correct name for WiFI SSID and Password, but it won't connect.
I'm not really a good programer but i assume something went wrong with the conversion?
Anyone has an idea?
Here's a fragment of the code I use to connect to WiFi. It prints the WiFi.status while it's connecting and could give you an indication of why it won't connect.
Wouldn't ESP8266WiFiMulti be more appropriate? I have two Wireless Access points in my home in addition to the router. I code the router and access points into my code and on startup the node selects the strongest AP and logs on.
definitly the easiest way. But my plan is to gift this device to my boss, so it needs to work in any future WiFI network.
Therefore the Hotspot from AutoConnect library as that has a built in Webpage to connect to any WiFI.
Okay...... it works.... i have no clue why... but using you're connection Method it actually works...
C:\Users\Haldi\Documents\Arduino\OWM_EPD47_epaper_v2.9\OWM_EPD47_epaper_v2.9.ino
Starting...
Failed to obtain time
Haldi123412346 6 6 6 3
WiFi connected,
MAC Address: 40:F5:20:55:3B:9C
IP address: 192.168.236.129
The strangest thing is that AFTER your short Test code when the script continues it even connects using the old method which didn't work before...