srwi / ESPEssentials

Essentials to get you started with your Arduino projects using the ESP8266 and ESP32.
GNU Lesser General Public License v2.1
26 stars 5 forks source link

Unable to set custom wifi parameters #9

Closed gtrig closed 1 year ago

gtrig commented 1 year ago

How to configure custom parameters in wifi manager?

I tried this:

`#include

char mqtt_address[40]; char mqtt_username[40]; char mqtt_password[40];

void setup() { Serial.begin(115200); ESPEssentials::init("Growatt-Wifi");

WiFiManagerParameter custom_mqtt_address("mqtt_address", "MQTT server address", mqtt_address, 40); WiFiManagerParameter custom_mqtt_username("mqtt_username", "MQTT username", mqtt_username, 40); WiFiManagerParameter custom_mqtt_password("mqtt_password", "MQTT password", mqtt_password, 40);

ESPEssentials::Wifi.addParameter(&custom_mqtt_address); ESPEssentials::Wifi.addParameter(&custom_mqtt_username); ESPEssentials::Wifi.addParameter(&custom_mqtt_password);

ESPEssentials::WebServer.on("/reset_wifi", HTTP_GET, [&]() { ESPEssentials::WebServer.send(200, "text/plain", "Wifi settings reset."); ESPEssentials::Wifi.resetSettings(); });

}

void loop() { ESPEssentials::handle(); }`

but when I reset wifi settings first of all no extra fields is shown and when I try to save the new wifi details I get *wm:[ERROR] WiFiManagerParameter is out of scope

on serial output.

srwi commented 1 year ago

Hi @gtrig, have you tried your code with just using WifiManager directly rather than ESPEssentials? On first sight it looks like you would have to declare custom_mqtt_address etc. in the global scope, but I haven't worked with that yet.