debug: remove hardcoded STA credentials
This commit is contained in:
@@ -2088,149 +2088,6 @@ void connectStaWifi() {
|
||||
delay(500);
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
|
||||
Serial.println("STA debug: connecting to home WiFi...");
|
||||
WiFi.begin("WardAP", "Ward5213");
|
||||
|
||||
unsigned long staStart = millis();
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - staStart < 15000) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.print("STA debug connected, IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
} else {
|
||||
Serial.println("STA debug connection failed or timed out");
|
||||
}
|
||||
delay(250);
|
||||
|
||||
WiFi.begin(staSsids[i].c_str(), staPasswords[i].c_str());
|
||||
|
||||
unsigned long start = millis();
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - start < 8000) {
|
||||
server.handleClient();
|
||||
oledLoop();
|
||||
delay(100);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
activeStaSsid = staSsids[i];
|
||||
Serial.println("STA WiFi connected");
|
||||
Serial.print("STA SSID: ");
|
||||
Serial.println(activeStaSsid);
|
||||
Serial.print("STA IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
return;
|
||||
}
|
||||
|
||||
wl_status_t status = WiFi.status();
|
||||
Serial.print("STA WiFi attempt failed. Status: ");
|
||||
Serial.println((int)status);
|
||||
|
||||
wifi_ap_record_t apInfo;
|
||||
if (esp_wifi_sta_get_ap_info(&apInfo) == ESP_OK) {
|
||||
Serial.print("Connected AP RSSI: ");
|
||||
Serial.println(apInfo.rssi);
|
||||
} else {
|
||||
Serial.println("No AP association info available.");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("All STA WiFi attempts failed. AP remains available.");
|
||||
}
|
||||
|
||||
void maintainStaWifi() {
|
||||
if (wifiNetworkCount <= 0) return;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) return;
|
||||
|
||||
if (millis() - lastStaReconnectAttempt < STA_RECONNECT_INTERVAL_MS) return;
|
||||
|
||||
lastStaReconnectAttempt = millis();
|
||||
|
||||
Serial.println("STA WiFi disconnected. Trying saved networks by priority...");
|
||||
connectStaWifi();
|
||||
}
|
||||
|
||||
void printNetworkStatus() {
|
||||
Serial.println("Network:");
|
||||
Serial.print(" AP IP: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
Serial.print(" Saved STA Networks: ");
|
||||
Serial.println(wifiNetworkCount);
|
||||
Serial.print(" Active STA SSID: ");
|
||||
Serial.println(activeStaSsid.length() ? activeStaSsid : "(none)");
|
||||
Serial.print(" STA Connected: ");
|
||||
Serial.println(WiFi.status() == WL_CONNECTED ? "true" : "false");
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.print(" STA IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void buildConfigDocument(JsonObject doc) {
|
||||
doc["device_name"] = appConfig.deviceName;
|
||||
|
||||
doc["hardware_profile"] = HARDWARE_PROFILE;
|
||||
doc["output_count"] = MAX_RELAYS;
|
||||
|
||||
JsonArray relaysArray = doc.createNestedArray("relays");
|
||||
for (int i = 0; i < MAX_RELAYS; i++) {
|
||||
JsonObject relay = relaysArray.createNestedObject();
|
||||
relay["id"] = appConfig.relays[i].id;
|
||||
relay["name"] = appConfig.relays[i].name;
|
||||
relay["role"] = appConfig.relays[i].role;
|
||||
relay["hardware_channel"] = appConfig.relays[i].hardwareChannel;
|
||||
relay["hardware_profile"] = HARDWARE_PROFILE;
|
||||
relay["pin"] = appConfig.relays[i].pin;
|
||||
relay["enabled"] = appConfig.relays[i].enabled;
|
||||
relay["available"] = appConfig.relays[i].available;
|
||||
}
|
||||
|
||||
JsonObject bms = doc.createNestedObject("bms");
|
||||
bms["enabled"] = appConfig.bms.enabled;
|
||||
bms["name"] = appConfig.bms.name;
|
||||
bms["address"] = appConfig.bms.address;
|
||||
bms["address_type"] = appConfig.bms.addressType;
|
||||
|
||||
doc["temperature_sensor_count"] = appConfig.tempSensorCount;
|
||||
|
||||
JsonArray temps = doc.createNestedArray("temperature_sensors");
|
||||
for (int i = 0; i < MAX_TEMP_SENSORS; i++) {
|
||||
JsonObject temp = temps.createNestedObject();
|
||||
temp["id"] = appConfig.tempSensors[i].id;
|
||||
temp["name"] = appConfig.tempSensors[i].name;
|
||||
temp["address"] = appConfig.tempSensors[i].address;
|
||||
temp["enabled"] = appConfig.tempSensors[i].enabled;
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
temp["high_alert_enabled"] = appConfig.tempSensors[i].highAlertEnabled;
|
||||
temp["high_alert_f"] = appConfig.tempSensors[i].highAlertF;
|
||||
}
|
||||
}
|
||||
|
||||
void buildWifiConfigDocument(JsonObject wifi, bool includePasswords) {
|
||||
wifi["ap_enabled"] = true;
|
||||
wifi["sta_enabled"] = wifiNetworkCount > 0;
|
||||
wifi["network_count"] = wifiNetworkCount;
|
||||
wifi["active_ssid"] = activeStaSsid;
|
||||
wifi["sta_connected"] = WiFi.status() == WL_CONNECTED;
|
||||
wifi["ap_ip"] = WiFi.softAPIP().toString();
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
wifi["sta_ip"] = WiFi.localIP().toString();
|
||||
} else {
|
||||
wifi["sta_ip"] = "";
|
||||
}
|
||||
|
||||
JsonArray networks = wifi.createNestedArray("networks");
|
||||
for (int i = 0; i < wifiNetworkCount; i++) {
|
||||
JsonObject network = networks.createNestedObject();
|
||||
network["index"] = i + 1;
|
||||
|
||||
Reference in New Issue
Block a user