Description
Hardware:
Board: ttgo (and other)
Core Installation/update date: 10/3/2018
IDE name: Arduino IDE 1.8.7
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10
Description:
I try to install new release of arduino-esp and faced with some picularities in my sketch behavior.
win 10, arduino 1.8.7 , esptool 2.3.1, mkspiffs 0.2.3, xtensa 1.22.0-80-g6c443a-5.2.0.
TTGO board.
Early all work fine - i send HTTP packets from PC to ESP32 and recieve answer about 30 "fps". But after i install new version of IDF (download by arduino "https://dl.espressif.com/dl/package_esp32_index.json") then answer not sends or sends with long timeouts. It seemed that new wificlient.cpp work different in compare with old version.
For example i try to use standard arduino example like SimpleWiFiServer.ino and they also freeze answers...
I print IP adress of esp32 in mozilla firefox (or another program) and after about 3-5 sec i see in debug that HTTP recieved by ESP32 and answered, mozilla some time recive answer, but some time no. Early answer returned very fast.
After i see in debug "client disconnected" then after 100ms i see "new client"! but client.available() == 0 and program spin in while(client.connected()) cycle. Then are timeout event (?) after 5-10sec
[D][WiFiClient.cpp:452] connected(): Disconnected: RES: 0, ERR: 128
and client.connected == 0 - program moove later.
The analysis of debug output shows that client.stop() command not make client.connected() == 0 and in second cycle we catch in infinite while(client.connected()) loop.
What i do wrong? How i can do fast series of HTTP request/answer to esp32? Why in old version (06/2017) all was fine?
Sketch: (leave the backquotes for code formatting)
//Change the code below by your sketch
#include <WiFi.h>
const char* ssid = "myssid";
const char* password = "mypass";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode(5, OUTPUT); // set the LED pin mode
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
int value = 0;
void loop() {
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
//client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("analog input ");
client.print("AI0");
client.print(" is ");
client.print(analogRead(A0));
client.println("<br />");
client.println("</html>");
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(5, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(5, LOW); // GET /L turns the LED off
}
}
}
// close the connection:
client.stop();
Serial.println("Client Disconnected.");
}
}
Debug Messages:
ets Jun 8 2016 00:22:57
17:52:57.076 ->
17:52:57.076 -> rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
17:52:57.076 -> configsip: 0, SPIWP:0xee
17:52:57.076 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:52:57.076 -> mode:DIO, clock div:1
17:52:57.076 -> load:0x3fff0018,len:4
17:52:57.116 -> load:0x3fff001c,len:952
17:52:57.116 -> load:0x40078000,len:6084
17:52:57.116 -> load:0x40080000,len:7936
17:52:57.116 -> entry 0x40080310
17:52:57.316 ->
17:52:57.316 -> Connecting to nae
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START
17:52:57.396 -> [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 0 - WIFI_READY
.[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 7 - STA_GOT_IP
17:52:58.396 -> [D][WiFiGeneric.cpp:389] _eventCallback(): STA IP: 192.168.1.210, MASK: 255.255.255.0, GW: 192.168.1.1
17:52:58.396 -> .
17:52:58.396 -> WiFi connected.
17:52:58.396 -> IP address:
17:52:58.396 -> 192.168.1.210
New Client.
17:53:51.764 -> GET / HTTP/1.1
17:53:51.764 -> Host: 192.168.1.210
17:53:51.764 -> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
17:53:51.764 -> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
17:53:51.804 -> Accept-Language: en-US,en;q=0.5
17:53:51.804 -> Accept-Encoding: gzip, deflate
17:53:51.804 -> Connection: keep-alive
17:53:51.804 -> Upgrade-Insecure-Requests: 1
17:53:51.804 ->
Client Disconnected.
17:53:51.884 -> New Client.
[D][WiFiClient.cpp:452] connected(): Disconnected: RES: 0, ERR: 128
Client Disconnected.