khoih-prog / WiFiWebServer

This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD, STM32, RP2040-based, etc. boards running WiFi modules/shields (WiFiNINA, CYW43439, U-Blox W101, W102, etc.). The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Now using WiFiMulti_Generic library
MIT License
104 stars 21 forks source link

ERR_EMPTY_RESPONSE when serial monitor is not active. #13

Closed mariolukas closed 2 years ago

mariolukas commented 2 years ago

Describe the bug

Same or similar behaviour as described in #9 I am using this lib for my Co2 Ampel (see #10) Firmware now Everything works as expected until the serial monitor of the Arduino IDE is open. After closing the monitor, i am getting "ERR_EMPTY_RESPONSE" in the Browser.

Steps to Reproduce

Code: https://github.com/mariolukas/Watterott-CO2-Ampel-Plus-Firmware/blob/main/CO2-Ampel_Plus/NetworkManager.cpp

  1. Connecting the board
  2. Open serial monitor in IDE
  3. Using a browser with the IP
  4. Everything is working like expected.
  5. Closing the serial monitor,
  6. Refreshing the browser
  7. ERR_EMPTY_RESPONSE in browser

Even this does not work:

  1. Resetting the device
  2. Not using serial monitor
  3. Opening the web Interface by IP
  4. ERR_EMPTY_RESPONSE in browser

Same behaviour in AP mode and when connected to WPA network.

Information

Additional context

Already tried some delays like described in #9 but this does not change anything. ( by the way the character limit to 1400 chars might be solved by sending the content in chunks).

khoih-prog commented 2 years ago

I'm sorry I don't have the special Co2 Ampel + WiFi101 to test, duplicate. So you're on your own.

Post your issue somewhere else, such as Arduino Forum, Wii101 library or Co2 Ampel-related forum, and ask for help.

Possibly some issue with WiFi101 library or that special Co2 Ampel board (core, library, bootloader, etc.)

Help yourself by using the more popular, yet much cheaper boards such as Nano-33-IoT, Nano-RP2040-Connect, ESP32/ESP8266, etc.

I'm closing the issue now, and won't reopen until you prove this is caused by a bug of this library, not the underlying library and/or boards.

Good Luck,

khoih-prog commented 2 years ago

Just have a quick 5-min look at your code at Watterott-CO2-Ampel-Plus-Firmware, I have some notes for you to improve / check

  1. CO2-Ampel_Plus/NetworkManager.cpp#L510
delay(100);

seems to long, what for and why ?

  1. You don't take full advantage of the WiFiWebServer, and use too many server.sendContent repeatedly. For example NetworkManager.cpp#L168-L256

and certainly more to improve. Certainly these have nothing to do with the ERR_EMPTY_RESPONSE issue, which depends on how the core / your code handle the USB-Serial port communication.

mariolukas commented 2 years ago

First of all i have to thank you for all the work on this lib and of course for the fast response.

  1. CO2-Ampel_Plus/NetworkManager.cpp#L510

You are right. I just removed this line. I think this was a left over from my testings.

  1. You don't take full advantage of the WiFiWebServer, and use too many server.sendContent repeatedly. For example NetworkManager.cpp#L168-L256

I also know that this is ugly. I used this as a workaround. It seems that MKR1000 is not able to handle more than 1400 bytes at once. Is there an other way to send content in chunks?

Certainly these have nothing to do with the ERR_EMPTY_RESPONSE issue, which depends on how the core / your code handle the USB-Serial port communication.

I am even not really sure if my issue only behaves on the serial monitor. But this was the way on how i was able to reproduce it. I realised that the behaviour didn't occur when i was investigating the debug logs.

Anyway finally i got it working (reliable) after checking #9 and #3 again. I tried to add a delay like described in these two issues. I also tried to use yield instead of a delay, but like the others already mentioned it doesn't work for me too. https://github.com/khoih-prog/WiFiWebServer/blob/23215024c85eb0410a3cfd7aa790156f28a0a201/src/WiFiWebServer-impl.h#L198

Is there a chance to add this fix permanently to the lib?