body:
In the last condition in else if (see code marked with ***), I am not getting my screen with the laser/specklke fail, if both failflag 1 and failgflag 5 is there,  however it shows me laser fail instead. Please help to solve my error.

```
#include <UTFT.h>
#include <avr/pgmspace.h>
#include <SPI.h>
#include <avr/wdt.h>
extern uint8_t Retro8x16[];
extern unsigned int virtek3[];  //display pic
UTFT myDisplay(ST7735, 11, 13, 3, 2, 4);

int buttonhold = 0;
int state = HIGH;
int tim = 0;
int tim1 = 0;
int tim2 = 0;
int button = 1;

float volt = 0;
float volt1 = 0;
float volt2 = 0;
float volt3 = 0;
float volt4 = 0;
float volt5 = 0;
float volt6 = 0;
float volt7 = 0;
float volt8 = 0;
float volt9 = 0;
float volt10 = 0;
float volt11 = 0;
float volt12 = 0;
float volt13 = 0;
float volt14 = 0;
float volt15 = 0;
float volt16 = 0;
float volt17 = 0;
float volt18 = 0;
float volt19 = 0;
float volt20 = 0;
float volt21 = 0;
float vcc = 0.0;
float temp = 0.0;
float r1 = 10000.0;
float r2 = 2200.0;
int failflag = 0;

//void(* resetFunc) (void) = 0;

void setup()
{
    pinMode(18, INPUT);   //For NEXT button
    pinMode(20, OUTPUT);  //For Relay power
    pinMode(21, OUTPUT);  //For Relay power
    pinMode(14, INPUT);
    Serial.begin(9600);
    myDisplay.InitLCD();
    myDisplay.clrScr();
    myDisplay.setFont(Retro8x16);

                                                                                digitalWrite(20, HIGH);
    digitalWrite(20, HIGH);
    digitalWrite(21, LOW);

    attachInterrupt(digitalPinToInterrupt(18), next, LOW);
    myDisplay.fillScr(255, 255, 255);
    myDisplay.drawBitmap(20, 1, 126, 126, virtek3, 1);

   while (1) {
    delay(100);
    if (state == LOW) {
    break;
    }
  }
}

void next() {
    state = LOW;
    Serial.println(buttonhold);
    buttonhold++;
    if (buttonhold > 500) {
    //digitalWrite(21, LOW);
    resetFunc();
    }
  }

void loop()
{
  digitalWrite(20, LOW);
 digitalWrite(21, LOW);   //Relay is ON.
  myDisplay.clrScr();
  state = HIGH;
  buttonhold = 0;
  while (1) {
    failflag = 0;
    float voltage_value = 0;

    myDisplay.setColor(0, 255, 255);
    myDisplay.print("1.Voltage Test", 35, 0);

    myDisplay.setColor(255, 255, 255);
    myDisplay.print("(V)", 0, 20);
    myDisplay.print("LASER",50,20);
    myDisplay.print("SPECKLE",100,20);

delay(1000);

      //FOR ANALOG A4 PIN
      //A4 pin connected to TP2 of speckle
      float volt_b = 0;
       float volt_c = 0;
       float volt_d = 0;
      for (int i = 0; i < 1000; i++) {
      volt_b =(volt_b + (4.99 / 1024 * analogRead(A4)));
      }
      volt_b = volt_b / 1000;
      volt1 = volt_b / (r2 / (r1 + r2));

      myDisplay.setColor(255, 255, 255);
      myDisplay.print("TP2 :", 0, 38);

      myDisplay.setColor(0, 255, 255);
      myDisplay.print("NA", 60, 37);

      Serial.println(volt1);                      //ANALOG A4
      if (volt1 >= 5 && volt1 <= 7.30) {
      myDisplay.setColor(0, 255, 0);
      myDisplay.printNumF(volt1, 2, 120, 38);
      //myDisplay.print("  ", 130, 20);
      } else {
      myDisplay.setColor(0, 0, 255);
      myDisplay.printNumF(volt1, 2, 120, 38);
      //myDisplay.print(" ", 150, 38);
      failflag = 1;
      }

      delay(2000);

      digitalWrite(20, HIGH);
      digitalWrite(21, LOW);
       delay(2000);

      //FOR ANALOG A4 PIN
      //A4 pin connected to TP2/L of SPECKLE

      for (int i = 0; i < 1000; i++) {
      volt_b =(volt_b + (4.99 / 1024 * analogRead(A4)));
      }
      volt_b = volt_b / 1000;
      volt2 = volt_b / (r2 / (r1 + r2));

      myDisplay.setColor(255, 255, 255);
      myDisplay.print("TP2/L :", 0, 56);

      myDisplay.setColor(0, 255, 255);
      myDisplay.print("NA", 60, 56);

      Serial.println(volt2);                       //ANALOG A4
      if (volt2 >= 5 && volt2 <= 0.05) {
      myDisplay.setColor(0, 255, 0);
      myDisplay.printNumF(volt2, 2, 120, 56);
      //myDisplay.print("  ", 130, 20);
      } else {
      myDisplay.setColor(0, 0, 255);
      myDisplay.printNumF(volt2, 2, 120, 56);
      //myDisplay.print(" ", 150, 56);
      failflag = 1;
      }

      //FOR ANALOG A1 PIN
      //A1 pin connected to J1_1 of SENSOR
      volt = analogRead(A1);
      volt3 =(volt * 4.8) /1024;

      myDisplay.setColor(255, 255, 255);
      myDisplay.print("J1_1 :", 0, 74);

      Serial.println(volt3);                 //ANALOG A1
      if (volt3 >= 0 && volt3 <= 5.25) {
      myDisplay.setColor(0, 255, 0);
      myDisplay.printNumF(volt3, 2, 60, 74);
      //myDisplay.print("  ", 130, 20);
      } else {
      myDisplay.setColor(0, 0, 255);
      myDisplay.printNumF(volt3, 2, 60, 74);
      //myDisplay.print(" ", 150, 74);
      failflag = 5;
      }

      myDisplay.setColor(0, 255, 255);
      myDisplay.print("NA", 125, 74);

      //FOR ANALOG A0 PIN
      //A0 pin connected to J2_2 of SENSOR

      for (int i = 0; i < 1000; i++) {
      volt_b =(volt_b + (4.99 / 1024 * analogRead(A0)));
      }
      volt_b = volt_b / 1000;
      volt4 = volt_b / (r2 / (r1 + r2));

    //volt4 = volt_c - 2.7;

      myDisplay.setColor(255, 255, 255);
      myDisplay.print("J2_2 :", 0, 92);

      Serial.println(volt4);                //ANALOG A0
      if (volt4 >= 5 && volt4 <= 8.82) {
      myDisplay.setColor(0, 255, 0);
      myDisplay.printNumF(volt4, 2, 60, 92);
      //myDisplay.print("  ", 130, 20);
      } else {
      myDisplay.setColor(0, 0, 255);
      myDisplay.printNumF(volt4, 2, 60, 92);
      //myDisplay.print(" ", 150, 92);
      failflag = 5;
      }

      myDisplay.setColor(0, 255, 255);
      myDisplay.print("NA", 125, 93);

      digitalWrite(20, LOW);
      digitalWrite(20, LOW);
      delay(2000);

      if (failflag == 5) {
      myDisplay.setColor(0, 0, 255);
      myDisplay.print("LASER FAIL", 35, 108);
      delay(4000);
      state = 0;

      }

      else if (failflag == 1) {
      myDisplay.setColor(0, 0, 255);
      myDisplay.print("SPECKLE FAIL", 35, 108);
      delay(40000);
      state = 0;

      }

 // *** Here the condition not working START
    else if ((failflag == 5) && (failflag == 1)) {
      myDisplay.setColor(0, 0, 255);
      myDisplay.print("LASER/SPECKLE FAIL", 15, 108);
      delay(40000);
      state = 0;
      }
  // *** Here the condition not working END

```

title: If condition not working as expected

Answers: 2

body:
```
(failflag == 5) && (failflag == 1))
```

`failflag` can't be both 5 and 1 at the same time.

body:
As you ask for two different assignments for the same var its never gone to work this way. Two quick options:

Do binary addidition

     failflag = 0;
     if(errorA) failflag += 1;
     if(errorB) failflag += 2;
     if(errorC) failflag += 4;
     if(errorD) failflag += 8;

    //then you can decode combined errors as follows
    else if (failflag == 13) {
        Serial.println("Errors: A, C, D"); // 1 + 4 + 8 =13
    }

The other quick one is defining failflag as bool array

    bool failflag [5] = {00000}; // 5 elements

     if(errorA) failflag [0]= 1;
     if(errorB) failflag [1]= 1;
     if(errorC) failflag [2]= 1;
     if(errorD) failflag [3]= 1;

    //then you can decode combined errors as follows
    else if ( failflag [0] == 1 &&  failflag [2]== 1 && failflag [3]== 1) {
        Serial.println("Errors: A, C, D"); // 1 + 4 + 8 =13
    }

as we have failflag[i] as a bool we can condense the code to

    else if ( failflag [0] && failflag [2] && failflag [3]) {
        Serial.println("Errors: A, C, D"); // 1 + 4 + 8 =13
    }

Whatever suits your needs. As I said just 2 quick ones

**Edit** Cleaning up you question other things to change:

Get rid of the delay() (except in setup to initialize your hardware and in loop  during debuging.

The 21 float vars could be stores in a float array

     float myFloatVars [22]

  and write the values to the position

     myFloatVars [11] = myMeasureFunction();

you can do this even in a timed for loop doing a recurring FIFO function (kind of circle buffer), the first saved value is dumped if the array is full to put the next one in. So you are able to produce a "gliding" average, which is what you want


body:
I technically need your help, when I am working on my project, I found out that my server-side cannot send data to the client-side, my server-side is made with `WiFiServer(80)` so it is when my client-side do `client.print`, it can send to the server-side, and the server-side just easily send to the Python side with Serial, and Python can still send it to the server-side, but the server-side cannot send it to the client-side.  The basic [code is from this page](https://www.instructables.com/id/WiFi-Communication-Between-Two-ESP8266-Based-MCU-T/)

 1. Server Code

Here's the code:
```
#include <SPI.h>
#include <ESP8266WiFi.h>
#define led LED_BUILTIN
char ssid[] = "AP";
char pass[] = "Science_Fair";
WiFiServer server(80);
WiFiClient client;
IPAddress ip(10, 241, 241, 27);
IPAddress gateway(10, 241, 241, 254);
IPAddress subnet(255, 255, 255, 0);
int i;

void setup()
{
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
  }
  // Serial.println("Connected to WiFi");
  server.begin();
  pinMode(led, OUTPUT);
}

void loop()
{
  client = server.available();
  client.setTimeout(3000);
  Serial.setTimeout(2000);
  if (client)
  {

    // Serial.println("Available");
    if (client.connected())
    {
      Serial.println("Connected");
    }

    while (client.connected())
    {
      // Serial.println(".");

      String request = client.readStringUntil('e');
      if (request == "LR")
      {
        digitalWrite(led, LOW);
        Serial.println("LR");
        for (i = 0; i < 3; i++)
        {
          String reply = Serial.readStringUntil('e');
          if (reply == "WARN_B")
          {
            Serial.println("Confirm");
            client.print("WARN_Be");
            break;
          }
          yield();
        }
      }
      else if (request == "RR")
      {
        Serial.println("RR");
        for (i = 0; i < 3; i++)
        {
          String reply = Serial.readStringUntil('e');
          yield();
          if (reply == "WARN_A")
          {
            Serial.println("Confirm");
            client.print("WARN_Ae");
            break;
          }
          yield();
        }
        yield();
      }
      yield();
    }
  }
  // Serial.println("");
  client.stop();
}

```

 2. Client A Code
```
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#define PIR_A D3
#define PIR_B D8
#define led LED_BUILTIN
const char ssid[] = "AP";
const char pass[] = "Science_Fair";
SoftwareSerial DFPlayer_Mini(D1, D2);
WiFiClient client;
IPAddress server(10, 241, 241, 27);
IPAddress ip(10, 241, 241, 28);
IPAddress gateway(10, 241, 241, 254);
IPAddress subnet(255, 255, 255, 0);

void setup()
{
    pinMode(PIR_A, INPUT);
    pinMode(PIR_B, INPUT);
    pinMode(led, OUTPUT);
    DFPlayer_Mini.begin(9600);
    mp3_set_serial(DFPlayer_Mini);
    mp3_set_volume(30);
    WiFi.mode(WIFI_STA);
    WiFi.config(ip, gateway, subnet);
    WiFi.begin(ssid, pass);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(100);
    }
    Serial.begin(9600);
}

void loop()
{
    int i;
    float time = 0;
    int PIR_A_VAL = digitalRead(PIR_A);
    int PIR_B_VAL = digitalRead(PIR_B);
    client.connect(server, 80);
    client.setTimeout(1500);
    if (PIR_A_VAL == HIGH)
    {
        while (1)
        {
            time += 1;
            delay(1);
            if (time >= 1000)
            {
                Serial.println("OFD");
                for (i = 0; i < 40; i++)
                {
                    delay(100);
                    yield();
                }
                break;
            }
            else if (PIR_B_VAL == HIGH)
            {
                if (time == 1)
                {
                    client.print("RRe");
                    client.flush();
                    for (i = 0; i < 40; i++)
                    {
                        delay(100);
                        yield();
                    }
                    break;
                }
                break;
            }
            PIR_B_VAL = digitalRead(PIR_B);
            yield();
        }
    }
    else if (PIR_B_VAL == HIGH)
    {
        String fromServer = client.readStringUntil('e');
        yield();
        if (fromServer == "WARN_A")
        {
            mp3_play();
        }
        Serial.println("B Triggered");
        for (i = 0; i < 2; i++)
        {
            delay(1250);
            yield();
        }
    }
    Serial.println("OFL");
    client.stop();
}
```

 3. Client B Code
```
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#define PIR_A D7
#define PIR_B D8
#define led LED_BUILTIN
const char ssid[] = "AP";
const char pass[] = "Science_Fair";
SoftwareSerial DFPlayer_Mini(D1, D2);
WiFiClient client;
IPAddress server(10, 241, 241, 27);
IPAddress ip(10, 241, 241, 29);
IPAddress gateway(10, 241, 241, 254);
IPAddress subnet(255, 255, 255, 0);

void setup()
{
    pinMode(PIR_A, INPUT);
    pinMode(PIR_B, INPUT);
    pinMode(led, OUTPUT);
    DFPlayer_Mini.begin(9600);
    mp3_set_serial(DFPlayer_Mini);
    mp3_set_volume(30);
    WiFi.mode(WIFI_STA);
    WiFi.config(ip, gateway, subnet);
    WiFi.begin(ssid, pass);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(100);
    }
    Serial.begin(9600);
}

void loop()
{
    int i;
    float time = 0;
    int PIR_A_VAL = digitalRead(PIR_A);
    int PIR_B_VAL = digitalRead(PIR_B);
    client.connect(server, 80);
    client.setTimeout(1500);
    if (PIR_A_VAL == HIGH)
    {
        while (1)
        {
            time += 1;
            delay(1);
            if (time >= 1000)
            {
                Serial.println("OFD");
                for (i = 0; i < 40; i++)
                {
                    delay(100);
                    yield();
                }
                break;
            }
            else if (PIR_B_VAL == HIGH)
            {
                if (time == 1)
                {
                    client.print("LRe");
                    client.flush();
                    for (i = 0; i < 40; i++)
                    {
                        delay(100);
                        yield();
                    }
                    break;
                }
                break;
            }
            PIR_B_VAL = digitalRead(PIR_B);
            yield();
        }
    }
    else if (PIR_B_VAL == HIGH)
    {
        String warnStatus = client.readStringUntil('e');
        yield();
        if (warnStatus == "WARN_B")
        {
            mp3_play();
        }
        Serial.println("B Triggered");
        for (i = 0; i < 2; i++)
        {
            delay(1250);
            yield();
        }
    }
    Serial.println("OFL");
    client.stop();
}
```
I've tried:
 - Using `client.print` instead of `client.printf`
 - Using data with underlines instead of spaces
 - Added `client.flush`
 - Added `client.stop`
 - Changed NodeMCU
 - Checked wires
 - Checked power supply
 - Checked the data to send
 - Made the timeout longer
 - Checked speaker
But none of them is working

Please help me guys I'm in a rush, thank you!

title: NodeMCU Server side cannot send things to client side - multiple clients attached

Answers: 1

body:
I read through the instructable and found - hidden in the comments the following

> Author of the instructable: <br> Would you like to send message to the
> four clients in the same time?
>
> If it is right I can not support you. I am not a expert in this topic.
> My server sends message to the current client only which is triggering
> the server. Using my sketch you can send same message to the clients,
> but in different time. (Remark codebreaker007: which would not work anyway!)

So this solution you have in your code is supposed to work with only one client. So you have to implement yourself a kind of com-sequence wether sever triggered or client side.
Here a short how to add this functionality:

    #define MAX_SRV_CLIENTS 4 // max clients connecting

    WiFiClient serverClients[MAX_SRV_CLIENTS];

in the loop do the following:

      uint8_t i;
     for (i = 0; i < MAX_SRV_CLIENTS; i++) {
      //check if there are any new clients
      if (server.hasClient()) {
     //find free/disconnected client spot
      if (!serverClients[i] || !serverClients[i].connected()) {
        if (serverClients[i]) serverClients[i].stop();
        serverClients[i] = server.available();
        Serial.print("New client: "); Serial.print(i);
        break;
      }
     }

So you can differentiate between the clients and send with for loop to all or

     serverClients[2].print("WARN Client 2");

Hope this resolves the issue (And read also comments of instructables about problems - the author is actually a newbie)


body:
I have an array of Strings in my code:
```
String BitSequence [257];
```
Each string will have 23~64 characters. At one point in my code, I have to use "myString.remove()" command and I don't want to apply any changes to my original strings. I need to make a copy and perform my commands on the copied string. I did:
```
MycopyString = BitSequence [1];
```
but it doesn't work. What tricks do I need to do here to make a copy?

title: Copying String into another String

Answers: 4

body:
Do not work with the String class on Arduino. That said what to do?

Use char arrays (what an individual String is internally). Then you work with pointers or pointers to pointers. Guessing from the fragments (what type is MycopyString?) you gave, you create a pointer (?) to the element in the array.
Working with String class has two disadvantages.

  - You have to look into the lib to see what a function really does and
  - by reserving and releasing memory it fractures on the long (most of the time short) run your heap causing your AVR/ESP to crash.

The possibility to create two dimensional arrays

    i = 257;
    char myTwoDimArray [i][64] = {'\0','\0'}// 64 ... 63 chars + 1 terminator(!)

and then you operate with pointers either to the entry (i) or in the specified char array itself.

How to remove an entry You just write:

    i = 23;
    myTwoDimArray [i][0] = '\0';

by writing a zero terminator to the first index (starts with 0) of the 24th (!) element (again the index starts with 0) its deleted.

Commands to look for when operating with chars

    strcpy (targetChar, charToAdd); // Initializes the targetChar starts at index 0
    strcat (targetChar, charToAdd); // Appends to the targetChar starts at current index

converting numeric values to chars:

      char numBuffer [16] = {'\0'}; // Helper buffer for conversions

     itoa (myNumberValue,numBuffer,10);  // converts an integer to a base 10 (decimal) char
    itoa (myNumberValue,numBuffer,2);  // converts an integer to a base 2 (binary) char
    itoa (myNuberValue,numBuffer,16);  // converts an integer to a base 16 (hex) char

itoa initilizes a char array so we need the helper array:

    strcat (targetChar, numBuffer);

to convert float we use

    dtostrf(floatVariable, StringLengthIncDecimalPoint, numVarsAfterDecimal, numBuffer);

to convert chars back to int use

    int16_t myIntVar = atoi(numBuffer);

to convert chars back to floats use

    float myFloatVar = atof(numBuffer, decimalsToShow); // using just atof(numBuffer)
    gives you standard x.XX only 2 decimals

Hope this comprehensive intro to chars helps you for your current and future projects.

body:
> I don't want to apply any changes to my original strings

You should read about PROGMEM and/or the __FlashStringHelper ( F-Macro ) . Probably you can even handle that vast amount of constant texts on your Nano controller, which is meant to be a controller, not a text processing computer.

body:
Thank you for all the helpful answers.
I think also found a way to copy strings. Using "myString.substring(from,to)" I could resolve my problem. The command works on array strings as well.
```
mynewcopystring =mystring[2].substring(0,mystring[2].length());
```

body:
String has a constructor that takes other strings.

```
String mycopyString(BitSequence[1]);
```

will create a new String object named mycopyString with its value initialized to the value of `BitSequence[1]`.

See https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/ for more details


body:
We are developing a Web Console and REST API for the NodeMCU V3 ESP8266, using `ESPAsyncWebServer`. We are facing some difficulties to serve dynamic pages using File Containing Templates! We're unable to replace `REQ_HOST_ID` with `request->host()` using Template Processor! The following code is working fine when a static host name is supplied.

    // server->on("/", HTTP_GET, HomePage::index);

    void HomePage::index(AsyncWebServerRequest *request) {
        Serial.println(request->host());
        auto processor = [](const String &var) -> String {
            if (var == "REQ_HOST_ID"){
            //  return F(request->host()); //FIXME
                return F("10.10.10.1");
            }
            return String();
        };
        AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/www/index.html", String(), false, processor);
        response->addHeader("Server", "Academia Web Server");
        request->send(response);
    }

**Edited:**

Commented code causes a compile-time error and needs to be fixed to set the value of `request->host()`. `request->host().c_str()` causes the same error!

    /Users/Chorke/Documents/Arduino/libraries/AcademiaCoreWeb/src/pages/HomePage.cpp: In lambda function:
    /Users/Chorke/Documents/Arduino/libraries/AcademiaCoreWeb/src/pages/HomePage.cpp:16:22: error: 'request' is not captured
                 return F(request->host()); //FIXME
                          ^
    /Users/Chorke/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/WString.h:38:76: note: in definition of macro 'FPSTR'
     #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
                                                                                ^
    /Users/Chorke/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/WString.h:39:34: note: in expansion of macro 'PSTR'
     #define F(string_literal) (FPSTR(PSTR(string_literal)))
                                      ^
    /Users/Chorke/Documents/Arduino/libraries/AcademiaCoreWeb/src/pages/HomePage.cpp:16:20: note: in expansion of macro 'F'
                 return F(request->host()); //FIXME

Your help resolving this issue is highly appreciated.

title: How to respond dynamically by using File Containing Templates?

Answers: 1

body:
Fixed:

    auto processor = [request](const String &var) -> String {
        if (var == "REQ_HOST_ID"){
            return request->host().c_str();
        }
        return String();
    };

Two mistake causes compile time error:

 1. Needs to pass `request` to the `Lambda` expression
 2. Need not to wrap the dynamic value with `F()` macro


body:
I'll start a project using **NodeMCU V3 WiFi Module**, which uses **esp8266** chip. However, I am undecided as to which library to use. I don't want use a *serial bridge* with an arduino, I think it is better to use NodeMcu in *Standalone* *mode*.

So, here's my question: which library should I use? And, regarding the type of use, what is their difference? (**both libraries reference looks like the same for me**)

*p.s.: I also heard about the "WiFi.h" library. Does it work only on WiFi shields for arduino or does it also work on esp8266?*

title: What is the difference betwen “ESP8266Wifi.h” and “WiFiEsp.h” libraries?

Answers: 1

body:
It's quite simple:

* ESP8266WiFi.h - Runs on the ESP8266 to control the WiFi.
* WiFiEsp.h - Runs on an Arduino to communicate with an ESP8266 module with AT commands
* WiFi.h - Runs on an Arduino to work with the Arduino WiFi shield.

So the one you want, which is part of the ESP8266 core, is ESP8266WiFi.h.


body:
   Trying to get Wifi SSID and password dynamically from serial monitor and connecting to WiFi, tried the below program, but wifi is always in Connecting state only, it is not getting connected after receiving input from serial monitor.

    #include <WiFi.h>

    #define BAUDRATE 115200

    char ssid[50];
    char pass[50];

    void setup() {
      Serial.begin(BAUDRATE);
      Serial.println();
      Serial.print("Enter your WiFi credentials.\n");
      Serial.print("SSID: ");
      while (Serial.available() == 0) {
        // wait
      }
      Serial.readBytesUntil(10, ssid, 50);
      Serial.print(ssid);
    Serial.print("donessid");

      Serial.print("PASS: ");
      while (Serial.available() == 0) {
        // wait
      }
      Serial.readBytesUntil(10, pass, 50);
      Serial.print(pass);
     Serial.print("donepass");

      WiFi.begin(ssid, pass);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print("Connecting....");
      }
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }
    void loop()
    {}

title: Serial read SSID and PASSWORD WiFI connection failed in ESP32

Answers: 1

body:
Is your Serial Monitor setting set to "Both NL and CR"? Change it to "Newline" should works.

What happened is if your Serial Monitor has a setting of "Both NL and CR", when your press Enter, it generates a `\r\n`, the `Serial.readBytesUntil(10, ssid, 50)` picked up that `\r` at the end of the array, when you use it as SSID, it is not a valid SSID.


body:
So I just finished my weak project which is a remote controlled car.

My problem is that when I press the button for going reverse (as an example) while the opposite action is currently in progress, going forwards the built_in led flashes in the exact same pattern when the Arduino is restarted (you know, pressing the reset button) and the car just stops and becomes responsive again after the led stops doing it's thing.

I believe the problem might be with the functions that I made, those being Forward(), Reverse(), Left(), Right(), Stop();

Note that if i press 5 (which translates to Stop() in this case) it is behaving as expected.

Here's the code: (functions at the bottom)

```
#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

int IN1 = 12;
int IN2 = 11;
int IN3 = 10;
int IN4 = 9;

void setup()
{
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  Serial.begin(9600);

  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop()
{
  if (irrecv.decode(&results)){
        Serial.println(results.value, HEX);
        switch(results.value){

          case 0xFF18E7: // in fata  - 2
          Forward();
          break;

          case 0xFF4AB5: // in spate - 8
          Reverse();
          break;

          case 0xFF10EF: //   stanga - 4
          Left();
          break;

          case 0xFF5AA5: //  dreapta - 6
          Right();
          break;

          case 0xFF38C7: //   stop  - 5
          Stop();
          break;

        }
        irrecv.resume();
  }
}

void Forward()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  Serial.print("Motor 1 Forward");
  Serial.println();

  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Motor 2 Forward");
  Serial.println();
}

void Reverse()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  Serial.print("Motor 1 Reverse");
  Serial.println();

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Motor 2 Reverse");
  Serial.println();
}

void Left()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  Serial.print("Motor 1 Reverse");
  Serial.println();

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Motor 2 Forward");
  Serial.println();
}

void Right()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  Serial.print("Motor 1 Forward");
  Serial.println();

  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Motor 2 Reverse");
  Serial.println();
}

void Stop()
{
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    Serial.print("Motor 1 Stop");
    Serial.println();

    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    Serial.println("Motor 2 Stop");
    Serial.println();

}
```

title: Weird behavior when 2 functions are trying(?) to run at the same time

Answers: 0


body:
I have just learned something called 'communication protocols' in Arduino, while I was testing this code, it appears to me that every time I input a string "YELLOW_ON" while statement works perfectly fine, however after that the serial monitor input cannot receive strings anymore. after inputting the string "YELLOW_ON", I cannot input another string which is "YELLOW_OFF" may I know why that is the case?

    #include"Display.h"
    const int YELLOW_LED = 7;

    void setup()
    {
      pinMode(YELLOW_LED, OUTPUT);
      Serial.begin(9600);
    }

    void loop()
    {
      if (Serial.available())
      {
        INPUT_SERIAL();
      }
    }

    void INPUT_SERIAL()
    {
      String INPUT_INFO = Serial.readStringUntil('\n');
      Serial.println(INPUT_INFO);

      while (INPUT_INFO == "YELLOW_ON")
      {
        Display.show("ON");
        digitalWrite(YELLOW_LED, HIGH);
        delay(250);
        digitalWrite(YELLOW_LED, LOW);
        delay(250);
      }
      if (INPUT_INFO == "YELLOW_OFF")
      {
        Display.show("OFF");
        digitalWrite(YELLOW_LED, LOW);
      }
    }

title: Serial monitor reading input strings, but cannot stop a while statement

Answers: 1

body:
From your comments:

> I want the while loop to be there and I somehow want to stop it, is
> that possible?

=> yes - press the reset button.
When I started programming some decades ago one of the basics was NEVER use while loops.
Why? Because you might run into deadlocks like your code does. Options:

  - Check inside the while for a state change/input to break the while loop (worst choice)
  - Get rid of blocking code (while/delay() ) and work with if clauses (medium)
  - Get rid of blocking code (while/delay() ) and implement a state machine with switch case (better)

How to get rid of delays - IDE-file-examples-2 Digital - blinkwithoutdelay


body:
I am having some problems with retrieving data from another esp. I have two esp8266, one is the access point which has a nextion lcd hooked up to it. The access point reads button presses from the lcd then sends messages to the other esp(the station point) in order to turn on the respcetive digital pins. The station point has two dht22 sensors hooked up to it. I am now trying to sens the temperature data from one of the sensor to the access point to print the data to the screen but I am having some problems(either sending or retrieving the sensor data, not sure how to test it).
Here is the code for the access point:
```
//this is the acces point
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <Nextion.h>

//wifi stuff
WiFiServer server(80);
IPAddress IP(192, 168, 4, 15);
IPAddress mask = (255, 255, 255, 0);

//booleans for check
bool Red1=false;
bool Green1=false;
bool Blue1=false;
bool Red2=false;
bool Green2=false;
bool Blue2=false;
bool Relay1=false;
bool Relay2=false;
bool AmbientTemp=false;
//ints for temp data
//String tempOutside=" ";
String tempInside=" ";
String humOutside=" ";
String humInside=" ";
//buttons
// page id,id,""name"
NexButton b0 = NexButton(1,2,"b0");//red1
NexButton b1 = NexButton(1,3,"b1");//green1
NexButton b2 = NexButton(1,4,"b2");//blue1
NexButton b7 = NexButton(3,2,"b7");//relay1
NexButton b8 = NexButton(3,3,"b8");//relay2
NexButton b9 = NexButton(2, 14, "b9");
NexText t8 = NexText(2,10,"t8");//tremperature inside
NexText t9 = NexText(2,11,"t9");//temperature outside
NexText t10 = NexText(2,12,"t10");//humidity inside
NexText t11 = NexText(2,13,"t11");//humidity outside

NexTouch *nex_listen_list[] = {
  &b0,
  &b1,
  &b2,
  &b7,
  &b8,
  &b9,
  NULL
};
//led strip 1
void b0PushCallback(void *ptr) {
  Red1=true;

  }
void b1PushCallback(void *ptr) {
  Green1=true;
  Serial.println("Green1");
  }
void b2PushCallback(void *ptr) {
  Blue1=true;
  }
//relays
void b7PushCallback(void *ptr) {
  Relay1=true;
  }
void b8PushCallback(void *ptr) {
  Relay2=true;
  }
void b9PushCallback(void *ptr) {
  AmbientTemp=true;
  }

void setup() {
  Serial.begin(9600);
  nexInit();
  b0.attachPush(b0PushCallback,&b0);
  b1.attachPush(b1PushCallback,&b1);
  b2.attachPush(b2PushCallback,&b2);
  b7.attachPush(b7PushCallback,&b7);
  b8.attachPush(b8PushCallback,&b8);
  b9.attachPush(b9PushCallback,&b9);
  //wifi part
  WiFi.mode(WIFI_AP);
  WiFi.softAP("Wemos_AP", "Wemos_comm");
  WiFi.softAPConfig(IP, IP, mask);
  server.begin();
  Serial.println();
  Serial.println("accesspoint_bare_01.ino");
  Serial.println("Server started.");
  Serial.print("IP: "); Serial.println(WiFi.softAPIP());
  Serial.print("MAC:"); Serial.println(WiFi.softAPmacAddress());
}

void loop() {
  nexLoop(nex_listen_list);
  //wifi stuff again
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  //String request = client.readStringUntil('\r');
  Serial.println("********************************");
  //Serial.println("From the station: " + request);
  client.flush();
  //strip 1
  if (Red1==true){
    client.print("redOne\r");
    Serial.println("Red1");
    Red1=false;
    }
  if (Green1==true){
    client.println("greenOne\r");
    Green1=false;
    }
  if (Blue1==true){
    client.println("blueOne\r");
    Blue1=false;
    }
  //relays
  if (Relay1==true){
    client.println("relayOne\r");
    Relay1=false;
    }
  if (Relay2==true){
    client.println("relayTwo\r");
    Serial.println("Relay2");
    Relay2=false;
    }
  if (AmbientTemp==true){
    client.println("AmbientTemp\r");
    Serial.println("ambient temp");
    AmbientTemp=false;
    }
  String tempOutside=client.readStringUntil('\r');
  Serial.println("tempOutside: ");
  Serial.println(tempOutside);
  //t8.setText(tempOutside);
  //tempInside=client.readStringUntil('\b');
  //t9.setText(tempOutside);
  //humInside=client.readStringUntil('\e');
  //t10.setText(humInside);
  //humOutside=client.readStringUntil('\f');
  //t11.setText (humOutside);//halp
  //Serial.println(humOutside);
  //Serial.println("humoutside: ");
  //Serial.print("t11.txt=");
  //Serial.print(humOutside.toInt());
  //Serial.write(0xff);
  //Serial.write(0xff);
  //Serial.write(0xff);
  Serial.println("Byte sent to the station: ");
  //Serial.println(client.println("reeeeeeeeeeeeeeeeeeeee\r"));
  //Serial.println(client.println("IamAlive\r"));
  }
```

And here is the code for the access point:
```
#include <DHT.h>
#include <DHT_U.h>
#include <ESP8266WiFi.h>

#define DHTPIN 3 //outside
#define DHTPIN2 0 //inside
#define DHTTYPE DHT22//type of sensor that I am using
DHT dht(DHTPIN, DHTTYPE); //outside
DHT dht2(DHTPIN2, DHTTYPE); //inside

//pins
const int Red = 5;
const int Green = 4;
const int Blue = 14;
const int Relay1= 12;
const int Relay2= 13;
//booleans for on/off(state)
bool RedS=false;
bool GreenS=false;
bool BlueS=false;
bool Relay1S=false;
bool Relay2S=false;
bool AmbientTempS=false;

char ssid[] = "Wemos_AP";           // SSID of your AP
char pass[] = "Wemos_comm";         // password of your AP
IPAddress server(192,168,4,15);     // IP address of the AP
WiFiClient client;
void setup() {
  Serial.begin(9600);
  dht.begin();
  dht2.begin();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);           // connects to the WiFi AP
  Serial.println();
  Serial.println("Connection to the AP");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println("Connected");
  Serial.println("station_bare_01.ino");
  Serial.print("LocalIP:"); Serial.println(WiFi.localIP());
  Serial.println("MAC:" + WiFi.macAddress());
  Serial.print("Gateway:"); Serial.println(WiFi.gatewayIP());
  Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
  //pins
  pinMode(Red, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Blue, OUTPUT);
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  digitalWrite(Red, LOW);
  digitalWrite(Green, LOW);
  digitalWrite(Blue, LOW);
  digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, LOW);
}
void loop() {
  client.connect(server, 80);
  Serial.println("********************************");
  Serial.print("Byte sent to the AP: ");
  Serial.println(client.print("Anyo\r"));
  String answer = client.readStringUntil('\r');
  Serial.println("From the AP: "+answer);
  int h = dht.readHumidity(); //humidity for Outside
  int t = dht.readTemperature(); //temperaure for Outside
  int h2 = dht2.readHumidity(); //humidity for Outside
  int t2 = dht2.readTemperature(); //temperaure for Outside
  Serial.println("temp outside: ");
  Serial.println(t);
  Serial.println("Thing: ");
  //Serial.println("temp inside:");
  //Serial.println(t2);
  //client.print(String(t2)+'\b');
  //Serial.println("hum outside:");
  //Serial.println(h);
  //client.print(String(h)+'\e');
  //Serial.println("hum inside:");
  //Serial.println(h2);
  //Serial.println(client.print(String(h2)+"\f"));
  client.flush();
  //stuff
  client.println(String(t)+'\r');
  //stuff again
  if(answer=="redOne"){
    if (RedS==false){
      digitalWrite(Red, HIGH);
      RedS=true;
      Serial.println("Red1 ON");
      }
    else{
      digitalWrite(Red, LOW);
      RedS=false;
      Serial.println("Red1 OFF");
      }
    }
  if(answer=="greenOne") {
    if (GreenS==false){
      Serial.println("Green1 ON");
      GreenS=true;
      digitalWrite(Green, HIGH);
      }
    else{
      Serial.println("Green1 OFF");
      GreenS=false;
      digitalWrite(Green, LOW);
      }

    }
  if(answer=="blueOne") {
    if (BlueS==false){
      Serial.println("Blue1 ON");
      BlueS=true;
      digitalWrite(Blue, HIGH);
      }
    else{
      Serial.println("Blue1 OFF");
      BlueS=false;
      digitalWrite(Blue, LOW);
      }

    }
  if(answer=="relayOne") {
    if (Relay1S==false){
      Serial.println("Relay1 ON");
      Relay1S=true;
      digitalWrite(Relay1, HIGH);
      }
    else{
      Serial.println("Relay1 OFF");
      Relay1S=false;
      digitalWrite(Relay1, LOW);
      }

    }
  if(answer=="relayTwo") {
    if (Relay2S==false){
      Serial.println("Relay2 ON");
      Relay2S=true;
      digitalWrite(Relay2, HIGH);
      }
    else{
      Serial.println("Relay2 OFF");
      Relay2S=false;
      digitalWrite(Relay2, LOW);
      }
  if(answer=="AmbientTemp") {
    if (AmbientTempS==false){
      Serial.println("AmbientTemp ON");
      AmbientTempS=true;
      }
    else{
      Serial.println("AmbientTemp OFF");
      AmbientTempS=false;
      digitalWrite(Red, LOW);
      digitalWrite(Green, LOW);
      digitalWrite(Blue, LOW);
      }
   while(AmbientTempS==true){
    Serial.println("Ambient temp is on!");
    }

    }
  client.stop();
  delay(2000);
  }
}
```

Thank you and sorry for any mistakes, English is not my first language.

title: Problem sending strings to another ESP

Answers: 1

body:
Figured it out, not too sure what was causing it to not send messages but below is the code that is working.
<!-- language-all: lang-cpp -->

    #include <ESP8266WiFi.h>
    #include <DHT.h>
    #include <DHT_U.h>

    #define DHTPIN 3 //outside
    #define DHTPIN2 0 //inside
    #define DHTTYPE DHT22//type of sensor that I am using
    DHT dht(DHTPIN, DHTTYPE); //outside
    DHT dht2(DHTPIN2, DHTTYPE); //inside

    //pins
    const int Red = 5;
    const int Green = 4;
    const int Blue = 14;
    const int Relay1= 12;
    const int Relay2= 13;
    //booleans for on/off(state)
    bool RedS=false;
    bool GreenS=false;
    bool BlueS=false;
    bool Relay1S=false;
    bool Relay2S=false;
    bool AmbientTempS=false;

    char ssid[] = "Wemos_AP";           // SSID of your AP
    char pass[] = "Wemos_comm";         // password of your AP
    IPAddress server(192,168,4,15);     // IP address of the AP
    WiFiClient client;
    void setup() {
      Serial.begin(9600);
      dht.begin();
      dht2.begin();
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid, pass);           // connects to the WiFi AP
      Serial.println();
      Serial.println("Connection to the AP");
      while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
      }
      Serial.println();
      Serial.println("Connected");
      Serial.println("station_bare_01.ino");
      Serial.print("LocalIP:"); Serial.println(WiFi.localIP());
      Serial.println("MAC:" + WiFi.macAddress());
      Serial.print("Gateway:"); Serial.println(WiFi.gatewayIP());
      Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
      //pins
      pinMode(Red, OUTPUT);
      pinMode(Green, OUTPUT);
      pinMode(Blue, OUTPUT);
      pinMode(Relay1, OUTPUT);
      pinMode(Relay2, OUTPUT);
      digitalWrite(Red, LOW);
      digitalWrite(Green, LOW);
      digitalWrite(Blue, LOW);
      digitalWrite(Relay1, LOW);
      digitalWrite(Relay2, LOW);
    }
    void loop() {
      int h = dht.readHumidity(); //humidity for Outside
      int t = dht.readTemperature(); //temperaure for Outside
      int h2 = dht2.readHumidity(); //humidity for Outside
      int t2 = dht2.readTemperature(); //temperaure for Outside
      client.connect(server, 80);
      Serial.println("********************************");
      Serial.print("Byte sent to the AP: ");
      Serial.println(client.print("Muie PSD\r")); //sending data to esp8266
      String answer = client.readStringUntil('\r');
      Serial.println("From the AP: " + answer);
      if(answer=="redOne"){
        if (RedS==false){
          digitalWrite(Red, HIGH);
          RedS=true;
          Serial.println("Red1 ON");
          }
        else{
          digitalWrite(Red, LOW);
          RedS=false;
          Serial.println("Red1 OFF");
          }
        }
      if(answer=="greenOne") {
        if (GreenS==false){
          Serial.println("Green1 ON");
          GreenS=true;
          digitalWrite(Green, HIGH);
          }
        else{
          Serial.println("Green1 OFF");
          GreenS=false;
          digitalWrite(Green, LOW);
          }

        }
      if(answer=="blueOne") {
        if (BlueS==false){
          Serial.println("Blue1 ON");
          BlueS=true;
          digitalWrite(Blue, HIGH);
          }
        else{
          Serial.println("Blue1 OFF");
          BlueS=false;
          digitalWrite(Blue, LOW);
          }

        }
      if(answer=="relayOne") {
        if (Relay1S==false){
          Serial.println("Relay1 ON");
          Relay1S=true;
          digitalWrite(Relay1, HIGH);
          }
        else{
          Serial.println("Relay1 OFF");
          Relay1S=false;
          digitalWrite(Relay1, LOW);
          }

        }
      if(answer=="relayTwo") {
        if (Relay2S==false){
          Serial.println("Relay2 ON");
          Relay2S=true;
          digitalWrite(Relay2, HIGH);
          }
        else{
          Serial.println("Relay2 OFF");
          Relay2S=false;
          digitalWrite(Relay2, LOW);
          }
      if(answer=="AmbientTemp") {
        if (AmbientTempS==false){
          Serial.println("AmbientTemp ON");
          AmbientTempS=true;
          }
        else{
          Serial.println("AmbientTemp OFF");
          AmbientTempS=false;
          digitalWrite(Red, LOW);
          digitalWrite(Green, LOW);
          digitalWrite(Blue, LOW);
          }
       while(AmbientTempS==true){
        Serial.println("Ambient temp is on!");
        }

        }
      client.flush();
      client.stop();
      delay(2000);
      }
    }


body:
In my sketch when an interrupt gets triggered, a state variable is toggled from high to low and vice versa. Depending upon the variable state I have an if statement in the main loop that will call alarm_On function if state is high and the else part of the conditional statement will call alarm_Off function if the interrupt is triggered a second time. Thus I want this if condition to run only when the interrupt is triggered. In all other circumstances I want to run other code but if it concerns the same components e.g. the leds, the other code doesn't execute. If it's not a common component then it works fine. How can I overcome this "common component" issue?

     // Analog Input devices
    # define humiditySensor A5

    // Alarm input
    # define alarmButton 2 // Pushbutton

    // Output Devices
    # define redLed 10
    # define yellowLed 11
    # define greenLed 12
    # define waterPump 9 // LED on relay
    # define spk 5

    // Variables
    volatile byte alarm = LOW;

    void setup() {
      pinMode (alarmButton, INPUT);
      pinMode (redLed, OUTPUT);
      pinMode (yellowLed, OUTPUT);
      pinMode (greenLed, OUTPUT);
      pinMode (waterPump, OUTPUT);
      attachInterrupt(digitalPinToInterrupt(alarmButton), ISR_Alarm, RISING);
      Serial.begin(9600);
    }

    void loop() {
      if (alarm == 1) {
        alarm_On();
      } else if (alarm == 0) {
        alarm_Off();
      }
      int humVal = analogRead(humiditySensor);
      Serial.println(humVal);
      if (humVal >= 500) {
        digitalWrite(redLed, HIGH);
      } else {
        digitalWrite(redLed, LOW);
      }
    } // void loop

    void ISR_Alarm () {
      alarm = !alarm;  // toggle alarm function if pushed more than once
    }

    void alarm_On() {
      tone (spk, 100);
      digitalWrite(waterPump, HIGH);
      static byte ledState = LOW;
      static unsigned long oldTime = 0;
      if (millis() - oldTime >= 250) { // loop to blink leds in emergency
        oldTime = millis();
        if (ledState == LOW) {
          digitalWrite(redLed, HIGH);
          digitalWrite(yellowLed, HIGH);
          digitalWrite(greenLed, HIGH);
          ledState = HIGH;
        } else {
          digitalWrite(redLed, LOW);
          digitalWrite(yellowLed, LOW);
          digitalWrite(greenLed, LOW);
          ledState = LOW;
        }
      }
    } // end of alarm on function

    void alarm_Off () {
      noTone (spk);
      digitalWrite(redLed, LOW);
      digitalWrite(yellowLed, LOW);
      digitalWrite(greenLed, LOW);
      digitalWrite(waterPump, LOW);
    } // end of alarm off function

    void high_Humidity() {
      digitalWrite(waterPump, HIGH);
    }

    void low_Humidity() {
      digitalWrite(waterPump, LOW);
    }

title: Is there a better way to combine if statement with an ISR?

Answers: 1

body:
Your code is not blocked, but ON or OFF are called each loop so your change are to the "common" components are overwritten quite fast.

Do not track the state within the IRQ. You could do something like:

    volatile byte alarm = 1;
    byte alarm_state = 1;

    void ISR_Alarm () {
        alarm = 1;
    }

    void loop() {
        if (alarm){
            alarm = 0;

            if (alarm_state) {
                alarm_state = 0;
                alarm_Off();
            } else {
                alarm_state = 1;
                alarm_On();
            }
        }

        // other code
    }


body:
I recently purchased an Esp32 and am doing some tests using Arduino IDE.
In one of the tests, I am recording a lot of .txt files with some text inside them in the flash memory, however, I would like to know how I can check the remaining space in the flash memory. I'm checking the flash memory space with `Serial.println(ESP.getFlashChipSize());`, however, the returned value is always the same.

Is this the right command to check? Why is it always with the same value?

title: Checking size in flash memory Esp32

Answers: 3

body:
> Is this the right command to check? Why is it always with the same value?

The only way that size can change is if you desolder the can from the top of the ESP32 module, then desolder the flash chip, and replace it with one that has a different capacity.

The free space is not a function of the flash chip. It is a function of the filesystem you are using to store your data - be that SPIFFS or FAT.

You should check the manual for the filesystem you are using to find what functions there are pertaining to space usage.

body:
Serial.println(ESP.getFlashChipSize());
don't return the physical flash size, it just returns the flash size that you have selected in the Arduino IDE Flash size.
Just try to set Flash size "2MB (16Mb)"
And the result is '2097152'

body:
The file system on the ESP32 is stored in a portion of the flash memory, and managed by the SPIFFS (SPI Flash File System) library. You can use the `SPIFFS.info()` function to get information about the file system, including the total size and the used size.

Assuming you have SPIFFS:

    #include <ESP.h>
    #include <SPIFFS.h>

    void setup() {
      Serial.begin(9600);
      delay(1000);

      // Initialize the SPIFFS file system
      if (!SPIFFS.begin(true)) {
        Serial.println("Initialization failed!");
        return;
      }

      // size of the compiled program
      uint32_t program_size = ESP.getSketchSize();

      // size of the file system
      FSInfo fs_info;
      SPIFFS.info(fs_info);
      uint32_t file_system_size = fs_info.totalBytes;

      // used size of the file system
      uint32_t file_system_used = fs_info.usedBytes;

      // free size in the flash memory
      uint32_t free_size = ESP.getFlashChipSize() - program_size - file_system_size + file_system_used;

      Serial.print("Program size: ");
      Serial.print(program_size);
      Serial.println(" bytes");

      Serial.print("File system size: ");
      Serial.print(file_system_size);
      Serial.println(" bytes");

      Serial.print("File system used: ");
      Serial.print(file_system_used);
      Serial.println(" bytes");

      Serial.print("Free space: ");
      Serial.print(free_size);
      Serial.println(" bytes");
    }

    void loop() {
      // Do Nothing Here
    }


body:
    unsigned long milliseconds=millis();
    // if at time of reading the above milliseconds = 599999 ie 1 millisecond short of 600000 ie 10 minutes
    unsigned long minutes = (milliseconds/1000)/60;
    // this will return 9 instead of 10.

How do you round the result to 10 minutes? I don't mean adding 1 to final result. It has to be within the calculation.

title: How to round up millis() when divided into minutes?

Answers: 2

body:
Here is a simple trick how to switch from integer math to floating point math and use round function.

```c++
  unsigned long milliseconds = 599999;

  unsigned long minutes_long = (milliseconds/1000)/60;
  // minutes_long = 9

  double minutes_double = (milliseconds/1000.0)/60.0;
  // minutes_double = 9.99998...

  double minutes_rounded = round(minutes_double);
  // minutes_rounded = 10
```

There also exists a trick that allows calculation of `round` using integer math. It's perfect if you don't have enough memory for a cast.

```c++
  unsigned long milliseconds;

  milliseconds = 600000 - 30*1000 - 1;
  //milliseconds = 569999

  unsigned long minutes_9 = (milliseconds+30000)/60000;
  // minutes_9 = 9

  milliseconds = 600000 - 30*1000;
  //milliseconds = 570000

  unsigned long minutes_10 = (milliseconds+30000)/60000;
  // minutes_10 = 10
```

body:
To round to the nearest X in fixed point arithmetic: add 1/2 X (in the base units, msec, in this case) and divide by X (again, in the base units) so:
`milliseconds = (milliseconds + (30*1000L))/(60*1000L);`

The addition of 1/2 X causes a carry of one whole X if the fractional X in the original quantity was 1/2 X or greater. (Likewise, if the fractional X was less than 1/2 X, no carry will result).

Integer division naturally truncates any fractional amounts, so you'll be left with the rounded integer result.


body: I am using a wemosd1 MINI which has a ESP8266 module. I am using it for an IoT project, however a lot has been going wrong.  With libraries and version types. I want to start over but noticed that simply reinstalling arduino didnt do tha trick. How can i restart?

title: How can I start freshly? Libraries mess Wemos D1 Mini

Answers: 0


body:
I am completely new to programming with Arduino so please bear with me if this seems stupid.

I am using an Arduino Uno R3.
I have two sensors, a Soil Moisture sensor and an LDR Light Sensor. Both of them have one pin marked as A0 on them. So now, do I connect them both to A0 using a breadboard (Like how I am connecting multiple sensors' VCC to the 5V pin currently) OR do I use a different analog pin say A0 for one and A1 for the other? Will it make a difference?

title: Connecting two sensors to one analog pin

Answers: 2

body:
AO is not "Ay Zero", it's "Ay Oh", and stands for "Analog Output". It means it just sends a varying voltage. It really doesn't care where it's sent to, it just sends it.

It's up to you where you connect that *output* to. But suffice it to say it wants to be connected to an *input* that can read an *analog signal*. And the Arduino has 6 of them.

Which one you connect it to is entirely up to you - you just have to *read* from that analog input by using the right pin number in `analogRead()`.

body:
(https://i.stack.imgur.com/Rm3On.jpg)
you can simply connect one in the A0 and the other in the A1 since all those pins can be used for the same function


body:
I can't connect to the network.
Hardware used: **Arduino UNO** and **SIM900A GSM module**
Tutorial used: https://www.instructables.com/id/GSM-SIM900A-With-Arduino/
Sim card used: **Orange** (I set it on 2G frequency and disabled pin code)
**I am from Romania.**

Based on the tutorial above, once the connection is established successfully, the status/network LED on the SIM900A will blink continuously every 3 seconds. This does not happen to me, so it is a problem from the start. It keeps on searching for a network to connect.

Would you mind helping me, please?

Thank you so much!

title: SIM900A network connection

Answers: 0


body:
Why doesn't the code below work? Timer will count 370ms then function called to ON LED. Again 370ms then function called to OFF LED. Basically a toggle function.

```
int IN0 = 12;
int IN1 = 11;
int OUT1 = 10;
int OUT2 = 9;
int OUT3 = 7;
int OUT4 = 6;
int LED = 13;
unsigned int count = 370;
unsigned int tcount = 0;
bool tflag = 0, mflag = 0, sflag = 0, lflag = 0, rflag = 0;
int a, b;

void setup() {
  pinMode(IN0, INPUT);
  pinMode(IN1, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(OUT1, OUTPUT);
  pinMode(OUT2, OUTPUT);
  pinMode(OUT3, OUTPUT);
  pinMode(OUT4, OUTPUT);
  Timer1.initialize(a); // 370 miliseconds on time
  //Timer1.attachInterrupt(flash);
}

void flash_on() {
  //digitalWrite(LED, !digitalRead(LED));
  digitalWrite(LED, HIGH);
}

void flash_off() {
  //digitalWrite(LED, !digitalRead(LED));
  digitalWrite(LED, LOW);
}

void loop() {
  Timer1.attachInterrupt(flash_on);
  a = count;
  Timer1.attachInterrupt(flash_off);
  a = count;
}
```

title: Why doesn't this timer code work?

Answers: 1

body:
You should give `a` a value before calling `Timer1.initialize(a)`.

For example, like this:

    void setup() {
      ....
      a = count;
      Timer1.initialize(a); // 370 miliseconds on time
      ....
    }

Your `loop()` code will also not work like you expect it to.
As it is, you will be switching between two different ISRs very fast, without having any control over which of the two will be called once the Timer1 interrupt occurs.

It will be better to stick to one ISR that toggles the LED. That’s kind of the point of a Timer interrupt.


body:
I want to use a soil moisture sensor using arduino uno R3. I am using the analog output. The values are in the range of 100 to 1300 as in the readings mention in [this question]( https://arduino.stackexchange.com/questions/33873/understanding-soil-moisture-sensor-values).

May I know what exactly these numbers mean? I read in a website that:

> Most soil moisture sensors are designed to estimate soil volumetric water content based on the dielectric constant (soil bulk permittivity) of the soil.
>

So what are the units? Basically I want to base an estimate for the normal amount of soil moisture for typical loamy soil and I don't understand how to base this threshold based on the readings given by the sensor. It would be greater help if someone actually knows what an appropriate soil moisture threshold is for loamy soil.

I searched on the internet but the closest i could come to answers was this table and this particular entry:

> Table 1.1. Typical field capacity and wilting point values (m^3
 m^(–3)) for different soil textures

>Soil texture| Field capacity| Wilting point| Available water

>Loam    |0.27| 0.12| 0.15|

I am so sorry if I seem confused but I am very new to the whole of sensors and electronics
[This is the sensor that I am making use of](https://www.electronicscomp.com/sensors-module/sensors/soil-moisture-ph-sensor/soil-moisture-sensor-module-india)

title: What are the units of output of soil moisture sensor?

Answers: 1

body:
Those sensors have no units. If you can find a schematic you could possibly relate the value to the resistance of the soil, but you'd need to know the resistance that the soil is paired with to form the resistive divider.

All you can say from the numbers is "This is wet" or "This is dry". Normally you would use trial and error to determine what the values roughly relate to, and say that "Anything under X should trigger watering. Anything over Y should stop watering."


body:
I have a wemos d1 mini and a mpu 6060 sensor. I am trying to send the data from the sensor to Firebase. However i have come across a hurdle which i cant seem to solve. This is my error, can you help me out with this issue?

Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

    In file included from C:\Users\Zakaria\Documents\Arduino\libraries\firebase-arduino-master\src/Firebase.h:30:0,

                     from C:\Users\Zakaria\Desktop\WORKING_ACCELERAMETOR_BACKUP\WORKING_ACCELERAMETOR_BACKUP.ino:4:

    C:\Users\Zakaria\Documents\Arduino\libraries\firebase-arduino-master\src/FirebaseObject.h:109:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6

         std::shared_ptr<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;

               ^

    In file included from C:\Users\Zakaria\Desktop\WORKING_ACCELERAMETOR_BACKUP\WORKING_ACCELERAMETOR_BACKUP.ino:4:0:

    C:\Users\Zakaria\Documents\Arduino\libraries\firebase-arduino-master\src/Firebase.h:86:11: error: StaticJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6

       std::shared_ptr<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;

               ^

    Using library FirebaseJson at version 2.3.3 in folder: C:\Users\Zakaria\Documents\Arduino\libraries\FirebaseJson
    Using library firebase-arduino-master at version 0.1 in folder: C:\Users\Zakaria\Documents\Arduino\libraries\firebase-arduino-master
    Using library ArduinoJson at version 6.15.0 in folder: C:\Users\Zakaria\Documents\Arduino\libraries\ArduinoJson
    Using library ESP8266HTTPClient at version 1.2 in folder: C:\Users\Zakaria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266HTTPClient
    Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Zakaria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi
    Using library Wire at version 1.0 in folder: C:\Users\Zakaria\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\Wire
    exit status 1
    Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

title: Error compile board LOLIN(WEMOS) D1 R2 & mini

Answers: 0


body:
I experimenting with the interrupt ISR using Arduino Uno. In my circuit, I am taking two mechanical switches that are connected with Uno's interrupt pins, pins 2 and 3, and also taking a built-in LED to confirm the ISR call.

My logic is when I press switch1 (which is connected to pin 3) or I press switch2 (which is connected to pin 2) LEDs should be turned on/off by the interrupt service routine.

My problem is that when I pressed switch1 and both ISR are called multiple times.

Here's my code:

    const int mechanicalSwitchUpPin = 2, mechanicalSwitchDownPin = 3;

    volatile byte stateSwitchUp = HIGH, stateSwitchDown = HIGH;

    inline void upCallback()
    {

      Serial.println("u");

      stateSwitchUp = digitalRead(mechanicalSwitchUpPin);

    }

    inline void downCallback()
    {

      Serial.println("d");

      stateSwitchDown = digitalRead(mechanicalSwitchDownPin);

    }

    void setup()
    {

      Serial.begin(115200);

      pinMode(13, OUTPUT);

      pinMode(mechanicalSwitchUpPin, INPUT);

      pinMode(mechanicalSwitchDownPin, INPUT);

      digitalWrite(mechanicalSwitchUpPin, HIGH); //Enable Pull-Up resistor to this pin

      digitalWrite(mechanicalSwitchDownPin, HIGH);//Enable Pull-Up resistor to this pin

      attachInterrupt(digitalPinToInterrupt(mechanicalSwitchUpPin), upCallback, RISING);

      attachInterrupt(digitalPinToInterrupt(mechanicalSwitchDownPin), downCallback, RISING);

    }

    void loop()
    {

      !stateSwitchUp ? digitalWrite(13, HIGH) : digitalWrite(13, LOW);

      !stateSwitchDown ? digitalWrite(13, HIGH) : digitalWrite(13, LOW);

      delay(1);

    }

Here is the output during one short press/release of the button connected to pin 2:

    17:10:06.231 -> d

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> d

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> d

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> u

    17:10:06.231 -> d

    17:10:06.231 -> u

    17:10:06.264 -> u

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/MPrIX.png)

<!-- End schematic -->

title: One ISR should be called, but both ISR has been called on Arduino UNO

Answers: 0


body:
i really love to make a lot of things  but i always have this problem that i don't know how can i determine what battery(with how much voltage and amp)my circuit must have to work perfectly! please help me:( for example i have two circuits.circuit 1  includes:arduino uno ,2 servo motors and a DFplayer module and an led but i don't know is a 7.4 voltage Lipo battery with 1500mAh suitable for it or not???
and circuit 2 includes:arduino uno,L298 driver & 2 dc motors & 2 ultrasonics sensor but i don't know what battery does it need?
i really love to learn it (determine the battery  my self)

title: how do i know what battery(how much ampere and voltage) my circuit needs to work perfectly?

Answers: 1

body:
TL;DR: You really need to know what components you have and you need to find datasheets. In the datasheet, you find what voltage the component requires.

Don't care too much about amperes in the beginning. If you get the voltage right, each component will just draw as much current as it needs.

An Arduino Uno operates from 7 to 12 Volts, so 7.4 V is ok.

"Servo motor" is simply not enough information. There are servo motors for 4.8 V, some for 6 V and others for 12 V. There are even AC servo motors for 240 V~.

[DFPlayer](https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299) is for 3.2 V to 5 V, so it shouldn't be powered directly off the 7.4 V battery. Maybe it can be powered from a 5 V pin of the Arduino. Since [they power it from the 5 V pin](https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299#target_5), it seems to be possible.

Also "LED" is not a term that is good enough. Is it Infrared, Red, Yellow, Green, Violet, UV or white? Depending on the color, it needs something between 1.6 and 3.0 V. Therefore, you need a resistor. What's the use of the LED? Do you need to turn it on and off by Arduino, or can it just be always on from the Lipo battery?

The [L298N](https://www.st.com/en/motor-drivers/l298.html) has a supply voltage from 2.5 V to 46 V, so 7.4 V is fine.

Next, "DC motor" is not specific enough. I have seen 3 V, 5 V, 6 V, 12 V, 24 V.

Also, for ultrasonic, there are SR04 and SRF05. These two operate at 5 V. But if you have a different one, that may not be the case.


body:
Build my own 'Artnet to WS2812b Neopixel' boxes for lighting in a club. Working fine. I have 20 stripes with 50 pxls each. One ESP8266(NodeMCU) is feeding 6 stripes, so it gets 2 DMX universes via Artnet. Depending on the FPS(~20-40FPS) i'm sending, thats about 200-300kbp/s constant bitrate for each of the ESPs.
Every 4-8h one of my boxes freezes randomly. No pinging possible anymore. The other boxes continue working as usual. Only chance of resetting is to disconnect the power.
First, i thought the ESP gets to hot (installed at the clubs ceeling and the power supply is also in such a box) or the humidity is to high, but it must be a software problem (tested it in the oven, dont laugh ;)).
So why isn't the watchdog resetting? I am not able to provoke any of those freezes at home (only waiting)

The code is pretty straight forward:

1. test the leds

2. connect to wifi (if no wifi, go to 1)

Loop:

3. check UDP packets for Artnetdata

4. update the WS2812 with the fastled-lib

any ideas?

```
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#include <FastLED.h>

// ARTNET CODES
#define ARTNET_DATA 0x50
#define ARTNET_POLL 0x20
#define ARTNET_POLL_REPLY 0x21
#define ARTNET_PORT 6454
#define ARTNET_HEADER 17

WiFiUDP udp;

#define NUM_LEDS 50

CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
CRGB leds4[NUM_LEDS];
CRGB leds5[NUM_LEDS];
CRGB leds6[NUM_LEDS];

unsigned long previousMillis = 0;
int offset=0;

uint8_t uniData[514];
uint8_t maxuni=0;
uint16_t uniSize;
uint8_t hData[ARTNET_HEADER + 1];

const char* ssid     = "*";
const char* password = "*";

IPAddress local_ip(192, 168, 0, 111);
IPAddress gateway_ip(192, 168, 0, 1);
IPAddress subnet_ip(255, 255, 255, 0);

void setup() {
  WiFi.begin(ssid, password);
  WiFi.config(local_ip, gateway_ip, subnet_ip);

  while (WiFi.status() != WL_CONNECTED) {
   delay(500);

delay(2000); // sanity delay
FastLED.addLeds<WS2812, 1, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, 2, GRB>(leds2, NUM_LEDS);
FastLED.addLeds<WS2812, 3, GRB>(leds3, NUM_LEDS);
FastLED.addLeds<WS2812, 4, GRB>(leds4, NUM_LEDS);
FastLED.addLeds<WS2812, 5, GRB>(leds5, NUM_LEDS);
FastLED.addLeds<WS2812, 6, GRB>(leds6, NUM_LEDS);
initTest();

  }

  udp.begin(ARTNET_PORT); // Open ArtNet port
}

void loop() {

  if (udp.parsePacket()) {
    udp.read(hData, ARTNET_HEADER+1);
    if ( hData[0] == 'A' && hData[1] == 'r') { //checking first two letters, if its Artnet data
      if ( hData[8] == 0x00 && hData[9] == ARTNET_DATA) {
      uniSize = (hData[16] << 8) + (hData[17]);
      udp.read(uniData, uniSize);

      if(hData[14]>maxuni){maxuni=hData[14];}

     switch(hData[14]+1-maxuni){

      case 0: //for each DMX universe updating the pixels
         for (int j=50; j--;){
            leds[j].setRGB(uniData[j*3+offset],uniData[j*3+1+offset],uniData[j*3+2+offset]);
          leds2[j].setRGB(uniData[j*3+150+offset],uniData[j*3+151+offset],uniData[j*3+152+offset]);
          leds3[j].setRGB(uniData[j*3+300+offset],uniData[j*3+301+offset],uniData[j*3+302+offset]);
         }
         break;

      case 1:
         for (int j=50; j--;){
           leds4[j].setRGB(uniData[j*3+offset],uniData[j*3+1+offset],uniData[j*3+2+offset]);
          leds5[j].setRGB(uniData[j*3+150+offset],uniData[j*3+151+offset],uniData[j*3+152+offset]);
          leds6[j].setRGB(uniData[j*3+300+offset],uniData[j*3+301+offset],uniData[j*3+302+offset]);
         }
         break;
     }
}
}
}

FastLED.show();
}

void initTest()
{
//only at Startup checking the LEDs, so nothing special here....}
```

title: Freezing ESP8266 after 4-8h

Answers: 0


body:
I know the title is phrased terribly, but I'm not sure how to phrase it since I'm not sure of the name.

I have a servo, that I cannot connect to, except for the output spine/shaft (physically).  I need to get the output of that servo into an arduino, or raspberry pi.  So I need some kind of peripheral that can attach to the shaft of the servo, and tell me what position it's in.  I can't figure out how to find what part I need, because I can't google for the name of it correctly.  I've tried servo input shaft, and many other things that don't make sense.

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/nqv9O.png

**More Info.**

I have a servo on a machine, and I can not interface with this servo in any way but physically.  I can't read the output from it electronically, and the signals are proprietary.  I can't take anything apart, all I can do is put something physically on it.

So, the issue is, I need to (based on nothing but the position of the servo shaft) figure out what position that 3rd party servo is at.

With that information, I'm then going to man in the middle, and attach another servo to my device, and change the value to what I want.

So if the factory servo is at 50%, and I know that by using something like a rotary encoder, if that ends up being the answer, I then could add x% to my actual servo.

title: What is the name of a peripheral which reads servo output data physically?

Answers: 1

body:
What you need is an `absolute rotary encoder`.

It will provide feedback about the absolute rotational position of the servo shaft.

An encoder that uses `gray code` is preferred because only one binary bit changes between adjacent positions.


body:
Something I'd like information on is whether it is possible to upload a SPIFFS filesystem image to the ESP8266. In theory it might work: It can be uploaded over USB, and according to the logs the flash location changes, but that's about it. PlatformIO also seems to offer an Upload SPIFFS option in a platform that's set to an OTA port, but that could just be it not checking the upload type.

So, what I want to know is how I can configure (or otherwise make) a SPIFFS image OTA-uploadable. I have two main OTA methods: Option One is the default Arduino OTA library, and Option Two is a re-skin of the OTA method-whose-name-is-forgettable where I can upload a file on a webpage hosted by the ESP8266 and it will read the file and update its firmware.

I'm assuming that there's a configuration parameter for this somewhere, but I don't know where to start looking, and the documentation on these libraries has a few very basic examples that don't cover complex or advanced use cases.

(The web server--though essentially unrelated to this issue, it's a great example--is the most egregious of these; the code is complex and now templated too, so I can't make sense of it, and the "examples" consist largely of compressed javascript that doesn't show the user anything. Then you get to the interesting stuff like actually getting the real size of an uploading file, or want to know how uploading things actually works (or why it fails), or you want to serve a file piecemeal by assembling bits of text (in the same way that debug statements usually make use of multiple Serial.print() statements), and there's just *nothing*)

title: OTA-program SPIFFS on the ESP8266

Answers: 1

body:
Basicly OTA supports the upload of *.bin files. Wether this contains compiled code or a filesystem (SPIFFS/LittleFS) is irrelevant. **BUT** The space for the OTA (partition) has to be min the size of the *.bin plus an overhead for processing. So with 4MB at all, you would need 2.5MB OTA for 1.5MB App/SPIFFS.
To tweak partition sizes (or custom partitions) you have to go into the boards.txt file.
[OTA - Details and Info here](https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html)

[File system - Details and Info here](https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html)


body:
Is it possible to use ultrasonic sensors maybe HC SR04 type as unlock sensors? I'm figuring out if it can replace matrix keypad?

For example 6 HC SR04 are used to be an input sensor waiting for a pattern to unlock a certain thing? Usually, in matrix keypad we will push [ 6,0,1,7] as the password is it possible to replace that with ultrasonic sensors as the receiver of input, and if it i possible, what type of code to be used?

title: Ultrasonic Sensor as Unlock Sensor

Answers: 1

body:
Short answer: yes.

General answer: you can use any input device for use as unlock mechanism. You can use a keypad, several single buttons, you can even use a single ultrasonic sensor (and depending on the distance differences from that sensor create a pattern), you can use a microphone, a temperature sensor (that will be tricky to unlock something though).

I would start with a typical example of an ultrasonic sensor sketch and program a pattern recognition algorithm in it. How that sketch would look like exactly, depends on your requirements (how you want to store the pattern, should it be hardcoded or changeable).

First try one sensor, than try multiple (I never tried, but I guess it's possible). If not by a default library, you have to write your own (that will be tricky possibly). Than think about the pattern recognition (values of the ultrasonic sensor in the correct order), than about changing/storing the 'code'.


body:
I am having trouble with a "simple" command parser; I'm guessing I'm doing something wrong with memory allocation - appreciate any pointers :)

For context: I'm running on an Arduino Uno (if it matters). The commands I expect are of the form `<key1=value1;key2=value2;key3=value3>`. For simplicity here (as well as for my own failed attempts at debugging), I've removed everything extraneous, so that this code just prints back to the serial monitor whatever the current value associated with the key "text" is every time a command enclosed in < > is encountered.

This seems to work correctly until after the first time the key is found; then it behaves somewhat unpredictably - haven't yet been able to discern the pattern.  But, for instance, if I send:
```
<a=5>
-> EMPTY
<b=7;text=here;d=9>
-> here
<d=abc>
-> here
<d=ghi;e=afds>
-> afds
```
That last displayed value is wrong, since no new key of text was sent over serial. The complete code is here:
```

// command indicators
char START_MARKER = '<';
char END_MARKER = '>';

const int MAX_KEY_VALUE_PAIRS = 3;  // maximum number of key-value pairs in message
const int MAX_ELEMENT_CHARS = 25;  // the maximum number of characters (+1 for terminator) in a key or a value

// message format: <key1=value1;key2=value2;key3=value3>
const int MAX_MESSAGE_CHARS = (MAX_KEY_VALUE_PAIRS * (MAX_ELEMENT_CHARS + 1)) * 2 + (MAX_KEY_VALUE_PAIRS - 1) + 2;  // maximum message size

char received_chars[MAX_MESSAGE_CHARS];  // <- EDIT#1
char received_chars[30] ={'\0'};
bool new_data = false;

char *text;  // the value identified by the "text" keyword, i.e.: in <text=abc;time=814a>, text would be abc.

void ParseData(char *str) {
  // This picks off the ;-delimited key-value pairs and assigns them to a multi-dim array
  char * pch;
  int pairs_count = 0;
  char config[MAX_KEY_VALUE_PAIRS][2][MAX_ELEMENT_CHARS];

  pch = strtok(str, "=");

  while (pch != NULL)
  {
    strcpy(config[pairs_count][0], pch);
    pch = strtok(NULL, ";");
    if (pch == NULL) break;

    strcpy(config[pairs_count][1], pch);
    pairs_count++;
    pch = strtok(NULL, "=");
    if (pch == NULL) break;
  }

  for(int i=0;i<pairs_count;i++) {
    if (strcmp(config[i][0], "text")==0) text = config[i][1];
  }
  Serial.println(text);
}

void ReadSerial(){
  // After calling ReceiveText to empty the buffer, if a complete command has been found,
  // parse that command.
  new_data = ReceiveText();
  if (new_data == true) {
    char temp_chars[MAX_MESSAGE_CHARS];  // temporary array for use when parsing
    strcpy(temp_chars, received_chars);
    received_chars[0] = '\0';  // <- EDIT#2
    ParseData(temp_chars);
  }
}

boolean ReceiveText() {
  // This dumps the characters on the buffer so far received_chars, searching for an END_MARKER
  // along the way; if it finds one, it goes back to find a START_MARKER; if that is also found,
  // the string within is the ;-delimited set of key value pairs
  static boolean recv_in_progress = false;
  static byte ndx = 0;
  char rc;

  boolean new_data = false;
  while (Serial.available() > 0 && new_data == false) {
    rc = Serial.read();

    if (recv_in_progress == true) {
      if (rc != END_MARKER) {
        received_chars[ndx] = rc;
        ndx++;
        if (ndx >= MAX_MESSAGE_CHARS) {
          ndx = MAX_MESSAGE_CHARS - 1;
        }
      } else {
        received_chars[ndx] = '\0'; // terminate the string
        recv_in_progress = false;
        ndx = 0;
        new_data = true;
      }
    } else if (rc == START_MARKER) {
        recv_in_progress = true;
    }
  }
  return new_data;
}

void setup() {
  Serial.begin(9600);
  text = (char*)malloc(25);
  strcpy(text, "EMPTY");
  received_chars[0] = '\0';
}

void loop() {
  ReadSerial();
}
```

Thanks!

title: Unpredictable behavior on parsing key-value delimited input from serial

Answers: 2

body:
Welcome to the I forgot to empty my buffer char club (I lost some days finding a simlar problem)

     strcpy(temp_chars, received_chars)  // strcpy empties temp_chars and adds the received_chars

but you have no (for me) visible routine to empty received_chars

Do this either by setting

    received_chars[0] ='\0'; // set the pointer to first index

or

     received_chars ="0";

or

    strcpy(received_chars,"0");

after you used the buffer content. By using

    static byte ndx = 0;

you just set the pointer and then start to write, as a safequard you should first reset the end terminator and then start to write. This is probably the reason you see characters even if no key is pressed due to a still "full" charbuffer.
To prevent heap corruption define your received_chars as a fixed arraybefore setup:

    char received_chars[128] ={'\0'}; // 127 chars + terminator

if you use malloc you have to use free, but doing that with a lot of dynamic data causes heap fracturing -> crash in the end

**EDIT**

The program does now the following

  - ignores all char not enclosed by <>
  - check for text and displays everything after = and before;
  - ignores everything after ; if its not text= again
  - if its text= again ignores the first and only displays the second param

You do not need strtok here as it deletes chars I use a modified substring routne for char arrays.
Here is the code working as described above:

    // command indicators
    const char START_MARKER = '<';
    const char END_MARKER = '>';

    const uint8_t MAX_KEY_VALUE_PAIRS = 3;  // maximum number of key-value pairs in message
    const uint8_t MAX_ELEMENT_CHARS = 25;  // the maximum number of characters (+1 for terminator) in a key or a value

    // message format: <key1=value1;key2=value2;key3=value3>
    const uint8_t MAX_MESSAGE_CHARS = (MAX_KEY_VALUE_PAIRS * (MAX_ELEMENT_CHARS + 1)) * 2 + (MAX_KEY_VALUE_PAIRS - 1) + 2;  // maximum message size

    //char received_chars[MAX_MESSAGE_CHARS] = {'\0'};// <- EDIT#1
    char received_chars[256] = {'\0'};
    bool new_data = false;
    char text[25] =  {'\0'};      // the value identified by the "text" keyword, i.e.: in <text=abc;time=814a>, text would be abc.

    void ParseData(char *str) {
      // This picks off the ;-delimited key-value pairs and assigns them to a multi-dim array
      char * pch;
      int pairs_count = 0;
      char config[MAX_KEY_VALUE_PAIRS][2][MAX_ELEMENT_CHARS];

      pch = strtok(str, "=");

      while (pch != NULL)  {
        strcpy(config[pairs_count][0], pch);
        pch = strtok(NULL, ";");
        if (pch == NULL) break;

        strcpy(config[pairs_count][1], pch);
        pairs_count++;
        pch = strtok(NULL, "=");
        if (pch == NULL) break;
      }

      for (uint8_t i = 0; i < pairs_count; i++) {
        if (strcmp(config[i][0], "text") == 0) strcpy (text,config[i][1]);
      }
      Serial.println(text);
    }

    void ReadSerial() {
      // After calling ReceiveText to empty the buffer, if a complete command has been found,
      // parse that command.
      new_data = ReceiveText();
      if (new_data == true) {
        char temp_chars[MAX_MESSAGE_CHARS];  // temporary array for use when parsing
        strcpy(temp_chars, received_chars);
        received_chars[0] = '\0';  // <- EDIT#2
        ParseData(temp_chars);
      }
    }

    bool ReceiveText() {
      // This dumps the characters on the buffer so far received_chars, searching for an END_MARKER
      // along the way; if it finds one, it goes back to find a START_MARKER; if that is also found,
      // the string within is the ;-delimited set of key value pairs
      static boolean recv_in_progress = false;
      static byte ndx = 0;
      char rc;

      bool new_data = false;
      while (Serial.available() > 0 && new_data == false) {
        rc = Serial.read();

        if (recv_in_progress == true) {
          if (rc != END_MARKER) {
            received_chars[ndx] = rc;
            ndx++;
            if (ndx >= MAX_MESSAGE_CHARS) {
              ndx = MAX_MESSAGE_CHARS - 1;
            }
          } else {
            received_chars[ndx] = '\0'; // terminate the string
            recv_in_progress = false;
            ndx = 0;
            new_data = true;
          }
        } else if (rc == START_MARKER) {
          recv_in_progress = true;
        }
      }
      return new_data;
    }

    void setup() {
      Serial.begin(115200);
       strcpy (text, "EMPTY");
     //  text = (char*)malloc(25);
    //  received_chars[0] = '\0';
    }

    void loop() {
      ReadSerial();
    }

If you could describe what you really want in the end I'm sure we can help with some basic routines.

body:
The problem was that, in the variables I wanted to keep (i.e.: text in the code below), I was assigning the value of a pointer to the parsed string which is reused the next time a command is found, rather than copying the string.

Fixed code below - see comment Fig#1. There's also a second fix, although that wasn't causing the problem behavior.

```
// command indicators
char START_MARKER = '<';
char END_MARKER = '>';

const int MAX_KEY_VALUE_PAIRS = 3;  // maximum number of key-value pairs in message
const int MAX_ELEMENT_CHARS = 25;  // the maximum number of characters (+1 for terminator) in a key or a value

// message format: <key1=value1;key2=value2;key3=value3>
const int MAX_MESSAGE_CHARS = (MAX_KEY_VALUE_PAIRS * (MAX_ELEMENT_CHARS + 1)) * 2 + (MAX_KEY_VALUE_PAIRS - 1) + 2;  // maximum message size

char received_chars[MAX_MESSAGE_CHARS];
bool new_data = false;

char *text;  // the value identified by the "text" keyword, i.e.: in <text=abc;time=814a>, text would be abc.

void ParseData(char *str) {
  // This picks off the ;-delimited key-value pairs and assigns them to a multi-dim array
  char * pch;
  int pairs_count = 0;
  char config[MAX_KEY_VALUE_PAIRS][2][MAX_ELEMENT_CHARS];

  pch = strtok(str, "=");

  while (pch != NULL)
  {
    strcpy(config[pairs_count][0], pch);
    pch = strtok(NULL, ";");
    if (pch == NULL) break;

    strcpy(config[pairs_count][1], pch);
    pairs_count++;
    pch = strtok(NULL, "=");
    if (pch == NULL) break;
  }

  for(int i=0;i<pairs_count;i++) {
    if (strcmp(config[i][0], "text")==0) strcpy(text, config[i][1]);  // Fix#1
  }
  Serial.println(text);
}

void ReadSerial(){
  // After calling ReceiveText to empty the buffer, if a complete command has been found,
  // parse that command.
  new_data = ReceiveText();
  if (new_data == true) {
    char temp_chars[MAX_MESSAGE_CHARS];  // temporary array for use when parsing
    strcpy(temp_chars, received_chars);
    received_chars[0] = '\0';  // Fix #2 - wasn't causing this problem, but still was wrong
    ParseData(temp_chars);
  }
}

boolean ReceiveText() {
  // This dumps the characters on the buffer so far received_chars, searching for an END_MARKER
  // along the way; if it finds one, it goes back to find a START_MARKER; if that is also found,
  // the string within is the ;-delimited set of key value pairs
  static boolean recv_in_progress = false;
  static byte ndx = 0;
  char rc;

  boolean new_data = false;
  while (Serial.available() > 0 && new_data == false) {
    rc = Serial.read();

    if (recv_in_progress == true) {
      if (rc != END_MARKER) {
        received_chars[ndx] = rc;
        ndx++;
        if (ndx >= MAX_MESSAGE_CHARS) {
          ndx = MAX_MESSAGE_CHARS - 1;
        }
      } else {
        received_chars[ndx] = '\0'; // terminate the string
        recv_in_progress = false;
        ndx = 0;
        new_data = true;
      }
    } else if (rc == START_MARKER) {
        recv_in_progress = true;
    }
  }
  return new_data;
}

void setup() {
  Serial.begin(9600);
  text = (char*)malloc(25);
  strcpy(text, "EMPTY");
  received_chars[0] = '\0';
}

void loop() {
  ReadSerial();
}
```

Thanks to Codebreaker007 for the help.


body:
So I am running my project on a NodeMCU, but I don't know how to let it add a yield in front of an else if. It will give me an error like this:

>Arduino:1.8.12 (Windows 10), 開發板:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Sketch + WiFi Settings, 115200"

>G:\資優班\科展\程式碼\Front_End\Main_Code_V5\Main_Server\Main_Server.ino: In function 'void loop()':

>Main_Server:84:5: error: 'else' without a previous 'if'

>exit status 1
'else' without a previous 'if'

>This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here's the code:

```
#include <SPI.h>
#include <ESP8266WiFi.h>

#define MAX_SRV_CLIENTS 2
#define led LED_BUILTIN

WiFiServer server(80);
WiFiClient serverClients[MAX_SRV_CLIENTS];
IPAddress ip(10, 241, 241, 27);
IPAddress mask(255, 255, 255, 0);
IPAddress gateway(10, 241, 241, 254);
char ssid[] = "AP";
char pass[] = "Science_Fair";

void setup() {
  Serial.begin(9600);
  WiFi.config(ip, gateway, mask);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    yield();
  }
  server.begin();
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {
  uint8_t i;
  Serial.setTimeout(10);
  for (i = 0; i < MAX_SRV_CLIENTS; i++) {
    Serial.println("Pre 1");
    if (server.hasClient()) {
      Serial.println("Pre 2");
      if (!serverClients[i] || !serverClients[i].connected()) {
        Serial.println("Pre 3");
        if (serverClients[i]) {
          Serial.println("Pre 4");
          serverClients[i].stop();
          Serial.println("Pre 5");
        }
        Serial.println("Pre 6");
        serverClients[i] = server.available();
        Serial.println("Pre 7");
        serverClients[i].setTimeout(10);
        Serial.println("Pre 8");
        Serial.print("New client: ");
        Serial.println("Pre 9");
        Serial.println(i);
        Serial.println("Pre 10");
        break;
      }
    }
    yield();
  }
  for (i = 0; i < MAX_SRV_CLIENTS; i++) {
    String fromClient = serverClients[i].readStringUntil('e');
    Serial.println("P1");
    yield();
    if (fromClient == "LR") {
      Serial.println("LR");
      String reply = Serial.readStringUntil('e');
      Serial.println("P2");
      yield();
      if (reply == "Warn_B") {
        yield();
        Serial.println("Confirm");
        Serial.println("P3");
        for (i = 0; i < MAX_SRV_CLIENTS; i++) {
          serverClients[i].print("Warn_B");
          Serial.println("P4");
          yield();
        }
      }
    }
    yield(); // this is the yield I need to add
    else if (fromClient == "RR") {
      Serial.println("RR");
      Serial.println("P5");
      String reply = Serial.readStringUntil('e');
      Serial.println("P6");
      yield();
      if (reply == "Warn_A") {
        Serial.println("P7");
        Serial.println("Confirm");
      }
      for (i = 0; i < MAX_SRV_CLIENTS; i++) {
        serverClients[i].print("Warn_A");
        Serial.println("P8");
        yield();
      }
    }
    yield();
  }
}
```

I need the `yield()` there but I don't know how to let it still do the else if. Please help me guys, thanks!

title: How to add a yield before else if?

Answers: 1

body:
First of all do yourself a favour and listen to your IDE

    This report would have more information with
     "Show verbose output during compilation"
    option enabled in File -> Preferences.

and in an if else there is no in between so either let it run as a state machine especially inyour case A != B != C != other:

    void subfunction(){
      if(A){
      // code to run
      return;
      }
     yield();
     if(B){
      // code to run
      return;
      }
     yield();
     if(C){
      // code to run
      return;
      }
     else{}  // to catch if not A or B or C
     yield();
    }

or implement switch case (Pseudo code)

     switch(fromClient){
        case "LR":
          //code to run
          yield();
          break;
        case "RR":
          //code to run
          yield();
          break;
        default:
          //code to run
          yield();
          break;
      }

Id else chains are prone to errors as in your case its A != B != C != other


body:
I am using 3 Esp32 modules. One being master and other two being nodes.
Nodes are connecting to the master's AP. Master is connected with GSM module to execute the web api.
Master esp is having a Async Webserver which takes the http requests from the nodes and executes the appropriate web api. This web api returns the result and finally this result is sent back to the node as the response to the http request.

While running this code, Randomly on any request i face wdt reset.

Hence my question is, how should i handle the wdt resets and keep my program running softly.

    E (32706) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
    E (32706) task_wdt: - async_tcp (CPU 0/1)
    E (32706) task_wdt: Tasks currently running:
    E (32706) task_wdt: CPU 0: IDLE0
    E (32706) task_wdt: CPU 1: async_tcp
    E (32706) task_wdt: Aborting.
    abort() was called at PC 0x400e1cc3 on core 0
    Backtrace: 0x4008c434:0x3ffbe170 0x4008c665:0x3ffbe190 0x400e1cc3:0x3ffbe1b0 0x40084771:0x3ffbe1d0 0x4016aaf3:0x3ffbc0d0 0x400e307a:0x3ffbc0f0 0x4008a361:0x3ffbc110 0x40088b7d:0x3ffbc130

My Code Snippet is given below,

**Master**

    HttpClient http(gsmClient, "www.mydummyserver.com", 80);
    AsyncWebServer server(80);

    const char* ssid = "ESP32-Access-Point";
    const char* password = "123456789";
    IPAddress ip(192,168,5,2);
    IPAddress gateway(192,168,5,1);
    IPAddress subnet(255,255,255,0);
    const char* PARAM_MESSAGE = "message";

    void notFound(AsyncWebServerRequest *request) {
        request->send(404, "text/plain", "Not found");
    }

    void setup() {

      Serial.begin(115200);
      WiFi.mode(WIFI_AP);
      delay(100);
      WiFi.softAPConfig(ip, gateway, subnet);
      WiFi.softAP(ssid, password);

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
            request->send(200, "text/plain", "Hello, world");
        });

     server.on("/myApi", HTTP_POST, [] (AsyncWebServerRequest *request) {

            String message;
            if (request->hasParam(PARAM_MESSAGE)) {
                message = request->getParam(PARAM_MESSAGE)->value();
            } else {
                message = "No message sent";
            }

            http.setTimeout(20000);
            String postData = "Param1=abcd&Param2=pqrs";
            http.beginRequest();
            http.post("http://www.mydummyserver.com/testapi.php");
            http.sendHeader("Content-Type", "application/x-www-form-urlencoded");
            http.sendHeader("Content-Length", postData.length());
            http.beginBody();
            http.print(postData);
            http.endRequest();
            int statusCode = http.responseStatusCode();
            String response = http.responseBody();

            Serial.print("Status code: ");
            Serial.println(statusCode);
            Serial.print("Response: ");
            Serial.println(response);
            request->send(200, "text/plain", "Response: " + message);

        });

     server.onNotFound(notFound);

        server.begin();

    }

    void loop() {

    }

**Node**

    HTTPClient httpClient;

    void setup() {

      Serial.begin(115200);

      WiFi.begin("ESP32-Access-Point", "123456789");

      Serial.print("WiFi ");

      while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(10);

      }

      Serial.println("connected:" + WiFi.SSID());

    }

    void executeApi() {

      Serial.println("Executing Api...");

      httpClient.setTimeout(20000);
      httpClient.begin("http://192.168.5.2/myApi");
      httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      String contentStr = "Param1=abcd&Param2=pqrs";

      int httpResponseCode = httpClient.POST(contentStr);

      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);

      httpClient.end();

    }

    String cmd = "";
    void loop() {

      if (Serial.available() > 0) {

        cmd = (Serial.readStringUntil('\n'));

        if (cmd.length() > 0) {

          if (cmd == "api") {
            executeApi();

          }

        }

      }

    }

For sulutions i have tried following things,

a. I tried to write this into the loop() function.

     while(true){
       delay(1);
     }

b. Tried disabling the wdt

    disableCore0WDT()
    disableCore1WDT()

but none of these giving good results.

title: AsyncWebServer giving wdt reset

Answers: 2

body:
The following recommendations, as you aren't providing enough relevant info:

- Install [ESP-exception decoder](https://github.com/me-no-dev/EspExceptionDecoder) and analyse your backtrace - Post it here so we can see in detail what caused the wdt
- AsyncWebServer tends to cause this behavior if a response takes too long; a well placed `yield()` sometimes helps to prevent this behavior - to analyse you need ESP-exeption decoder
- As `loop()` is running on core1 some/no process (idle) on core0 can cause the behavior. You can look up "task assignment to cores" on how to manually distribute the tasks (or send a `yield()` timed to core0 to reset the wdt)
- Placing time-outs in combination with sleep/deep sleep (although you don't seem to use them) are also causes for wdt resets
- A hackey trick is to set `CONFIG_ASYNC_TCP_USE_WDT 0`, but it is OK for testing

If you look into async_tcp for the possible culprit you see one line `xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);`

Here is an example of how I use it to prevent wdt resets. Place in `setup()`:

```c++
disableCore0WDT();
disableCore1WDT();
disableLoopWDT(); // You forgot this one !
```

and because of this routine in the async_tcp lib:

```c++
static void _async_service_task(void *pvParameters) {
  lwip_event_packet_t * packet = NULL;
  for (;;) {
    if (_get_async_event(&packet)) {
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_add(NULL) != ESP_OK) {
        log_e("Failed to add async task to WDT");
      }
      #endif
      _handle_async_event(packet);
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_delete(NULL) != ESP_OK) {
        log_e("Failed to remove loop task from WDT");
      }
      #endif
    }
  }
  vTaskDelete(NULL);
  _async_service_task_handle = NULL;
}

I set the `CONFIG_ASYNC_TCP_USE_WDT 0` and it works so far.

body:
**Short answer**
----------------
**increase the size of the _async_queue in AsyncTCP.cpp**

    _async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));

**from 32 to 64 or even higher if you can spare the space**

**Detailed (but possibly incorrect) explanation:**
--------------------------------------------------

After looking at the OS calls, I found that in AsyncTCP.cpp

The event queue is created as:

    _async_queue = xQueueCreate(32, sizeof(lwip_event_packet_t *));

Later the items are added with a Timeout of portMAX_DELAY, for example:

    static inline bool _send_async_event(lwip_event_packet_t ** e){
        return _async_queue && xQueueSend(_async_queue, e, portMAX_DELAY) == pdPASS;
    }

Since (at least when using the AsyncWebserver), both the queueing and the dequeuing are done on the same task (async_tcp), as soon as there are 32 events in the queue the moment the next event is to be added, the task will block indefinitely, causing the TWDT to be triggered.

So the solution might be to have the event queueing/dequeueing done in different tasks (maybe intended, since it already is an os queue) or increase the queue size to a value that will not be reached. Since the queue items are not that large, I just increased it to 256 to be on the safe side.

**I am not sure if this explanation is correct, since I can't find the code where async_tcp feeds or kicks the watchdog during normal operation. So if someone knows how it works and could tell me, it would be greatly appreciated.**