prampec / IotWebConf

ESP8266/ESP32 non-blocking WiFi/AP web configuration Arduino library
MIT License
523 stars 140 forks source link

WiFi is constantly lost #282

Closed alex22-coder closed 7 months ago

alex22-coder commented 7 months ago

This code works great.

`int arr_index = 0; int input = 0; String res; String temp;

void loop() { // input = analogRead(0); < ------------------------ commented // -- doLoop should be called as frequently as possible. iotWebConf.doLoop();

if (arr_index == 50){ arr_index = 0; res = temp + "]}"; temp = "{\"uid\":[" + String(input); } else{ arr_index++; temp += "," + String(input); } }`

But if I uncomment the analogRead() function, everything collapses, after each request the WiFi breaks and the connection is re-connected.

All code

`/**

/**

include

include

// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point. const char thingName[] = "thing";

// -- Initial password to connect to the Thing, when it creates an own Access Point. const char wifiInitialApPassword[] = "smrtTHNG8266";

// -- Method declarations. void handleRoot(); void handleFetch();

DNSServer dnsServer; WebServer server(80);

IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword);

void setup() { Serial.begin(115200); Serial.println(); Serial.println("Starting up...");

// -- Initializing the configuration. iotWebConf.init();

// -- Set up required URL handlers on the web server. server.enableCORS(1); server.on("/", handleRoot); server.on("/a", handleFetch); server.on("/config", []{ iotWebConf.handleConfig(); }); server.onNotFound([](){ iotWebConf.handleNotFound(); });

Serial.println("Ready."); }

int arr_index = 0; int input = 0; String res; String temp;

void loop() { // input = analogRead(0); // -- doLoop should be called as frequently as possible. iotWebConf.doLoop();

if (arr_index == 50){ arr_index = 0; res = temp + "]}"; temp = "{\"uid\":[" + String(input); } else{ arr_index++; temp += "," + String(input); } }

/**

void handleFetch(){ // -- Let IotWebConf test and handle captive portal requests. if (iotWebConf.handleCaptivePortal()) { // -- Captive portal request were already served. return; } server.send(200, "application/json", res); } `

alex22-coder commented 7 months ago

I understand, WiFi and analogRead() not working together in the ESP8266