I have compared the value ofI have compared the value of the result of const char* ssid = networks[network]["ssid"]; with const char* _ssid = "MySSID"; using strcmp and it returns 0, so I can't figure out why it's not working. It works if I replace networks[network]["ssid] with my SSID (though I need to replace the password with the string literal as well, otherwise it stays on status code 6, disconnected).
I can't figure out what it is about ArduinoJson, but it seems that the result of grabbing a string doesn't return a string that is formatted correctly for WiFi.begin, but it satisfies strcmp?
Edit:
I modified the result of const char* ssid = networks[network]["ssid"]; with const char* _ssid = "MySSID"; using strcmp andcode quite a bit in an effort to get it returns 0, so I can't figure out why it's not workingto work. It works if I replace networks[network]["ssid] with my SSID (though I need to replaceam no longer passing the passwordArduinoJson object, I'm now passing a struct with the string literal as welldata, otherwiseand it stays on status code 6, disconnected)still doesn't work.
I can't figure out what it is about ArduinoJson, but it seems that Is this the resultwork of grabbing a string doesn't return a stringsome advanced c++ constants/pointers stuff that is formatted correctly for WiFi.begin, but it satisfies strcmp?I don't seem to understand?
#include <ArduinoJson.h>
#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#include <vector>
#include <elapsedMillis.h>
#include "config.h"
#include "restserver.h"
#include "scanwifiserver.h"
AsyncWebServer *Server = new AsyncWebServer(80);
ScanWifiServer *scanWifi;
RestServer *restServer;
struct Network {
const char* ssid;
const char* password;
};
std::vector<JsonDocument>vector<Network> readAP(fs::FS &fs) {
//fs.remove("/ap.txt");
File file = fs.open("/ap.txt");
std::vector<JsonDocument>vector<Network> networks;
if (!file) {
#ifdef DEBUG
Serial.println("Failed to open file for reading");
#endif
return networks;
}
while (file.available()) {
DynamicJsonDocument networkn(JSON_CAPACITY);
deserializeJson(network,auto s = file.readStringreadStringUntil('\n');
deserializeJson(n, s);
struct Network network = {n["ssid"], n["password"]};
networks.push_back(network);
Serial.println(networks.back(const char *)network["ssid"].ssid);
}
file.close();
return networks;
}
void setup() {
#ifdef DEBUG
Serial.begin(BAUDRATE);
delay(50002000);
#endif
SPIFFS.begin();
auto networks = readAP(SPIFFS);
if (networks.size() > 0) {
Serial.println("Networks:");
int network = 0;
Serial.println(networks.size());
while (WiFi.status() != WL_CONNECTED && network < networks.size()) {
const char* ssid = networks[network]["ssid"];networks[network].ssid;
const char* password = networks[network]["password"];networks[network].password;
Serial.printlnprintf("%s, %s\n", ssid, password);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delayif (500WiFi.status(); == WL_CONNECT_FAILED || WiFi.status() == WL_NO_SSID_AVAIL)
Serial.print(WiFi.status());
break;
if (WiFi.status delay(500);
== WL_CONNECT_FAILED || WiFi.status() == WL_NO_SSID_AVAIL)
Serial.print(WiFi.status());
break;}
}
Serial.println("");
network++;
}
if (WiFi.status() == WL_CONNECTED) Serial.println("Connected");
else networks.clear();
}
if (networks.size() == 0) {
Serial.println("Starting ScanWifiServer");
WiFi.mode(WIFI_AP_STAWIFI_AP);
scanWifi = new ScanWifiServer(Server);
Server->begin();
MDNS.begin("grow");
MDNS.addService("http", "tcp", 80);
}
}
void loop() {}