Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By SmelyZajko
#82959 Using hints from tutorials, I wrote a simple wifi server and client that only relay the characters received from the serial line (connected using USB to a PC) over the wifi to the other peer, and inc/dec a variable accordingly (see the code below). I used Arduino IDE (1.8.9) to write this code in a plain C/C++. The problem I am encountering is that this code works fine only after a power cycle (I have to unplug the USB cable from the module and plug it back again). If I only press the HW reset button on the module, or after I send a new version of the code (most of the times) everything works fine, except of the Serial.available() or Serial.read() functions. They simply see nothing arriving from the PC over USB/serial line. But replugging the USB and reconnecting the Putty terminal program (i.e. a full power cycle) resolves it, and everything works again. It always works properly after the power cycle, but most of the times fails after the RST button (or new version upload). Somehow the ESP serial module remains stuck or does not properly initialize when the module is reset without complete power loss. The same behavior on server and client. Replacing the module for a different one - same result. I used the most recent NodeMCU/ESP board settings downloaded yesterday using Arduino board manager. Do you, please, have any hints how to resolve this?

The code:

server:

Code: Select all#include <ESP8266WiFi.h>

const char* ssid = "my ssid"; //replace this with your WiFi network name
const char* password = "my passwd"; //replace this with your WiFi network password

WiFiServer server(12345);
int a;

void setup()
{
  a = 0;
  pinMode(D5, OUTPUT);  // piezo spkr
  delay(1000);
  Serial.begin(115200);
  delay(1000);
  tone(D5, 1720);

  Serial.flush();  //irrelevant whether this is here or not
  Serial.print("Wifi.begin()");
  WiFi.begin(ssid, password);

  Serial.println();
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  tone(D5, 220);

  Serial.println("success!");
  Serial.print("Server IP Address is: ");
  Serial.println(WiFi.localIP());

  delay(1000);
  noTone(D5);

  server.begin();
}

int read_and_process_packet(WiFiClient *client)
{
  char packet_type = client->read();
  switch (packet_type)
  {
    case 'a': a--; Serial.println(a); break;
    case 'q': a++; Serial.println(a); break;
    case '-': return 0;
  }
  return 1;
}

void loop() {
  WiFiClient client = server.available();
  if (client) {

    if (client.connected()) {
      Serial.println("Connected to client");

      while (client.connected())
      {
        if (!read_and_process_packet(&client)) break;
        if (Serial.available())
        {
          char c = Serial.read();
          client.write(c);
        }
        delay(50);
      }
      client.stop();
      Serial.println("Client left");
    }
  }
  delay(1);
}


client:

Code: Select all#include <ESP8266WiFi.h>

// Replace these with your WiFi network settings
const char* ssid = "my ssid"; //replace this with your WiFi network name
const char* password = "my passwd"; //replace this with your WiFi network password

int a;

WiFiClient client;
char server_ip[20];

void setup()
{
  a = 0;
  pinMode(D5, OUTPUT);
  delay(1000);

  Serial.begin(115200);
  delay(1000);
  Serial.flush();  //irrelevant whether this is here or not

  Serial.print("Enter server IP: ");

  char *p = server_ip;
  for (int i = 0; i < 4; i++)
  {
    int ip = read_number();
    p = print_num(p, ip); 
    if (i < 3)
      p = print_char(p, '.');
  }
  Serial.println();

  tone(D5, 1720);

  Serial.print("Wifi.begin()");
User avatar
By SmelyZajko
#83000
QuickFix wrote:Just a first thought: you don't have anything (LED, pull-up/down resistor, ...) connected to D3, D4 and/or D8?


Thanks for the hint. I think sometimes yes, not sure if all the time, I had to return the modules to the user already meanwhile. But even then, why would power down behave differently than hard reset if everything else is the same?

I am new to ESP, why are these pins D3, D4, D8 an issue?
https://www.instructables.com/id/NodeMC ... nd-Pinout/
I see D8 is RTS. Is RTS enabled, or is it used by the bootloader for some kind of mode selection?
And how about the D3, D4 - what are the issues there?
User avatar
By QuickFix
#83020 A reset is electrically not actually resetting the capacitors (or capacitance and other electrical effects in electronics) and such, but (in essence) is only clearing software buffers, setting the pointer back to zero and maybe some other basic stuff (but there are other's here that know much more about the exact internal details than I do).

But if you put GPIO0, 2 and/or 15 (D3, D5, D8) in a wrong state at boot (because some capacitance left from a previous run while doing a reset pulls the GPIO the wrong way), there's a possibility it doesn't boot at all (and the ESP is quite picky the on the state of those GPIO's at boot).