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

MKR1000 - HelloServer issue when _WIFI_LOGLEVEL_ < 4 #3

Closed williamsulzer closed 3 years ago

williamsulzer commented 3 years ago

Hi, really great library! I am experiencing a strange issue where the handleClient doesn't seem to function when the _WIFILOGLEVEL identifier is set to 0 through 3. When the identifier is set to 4, everything works as expected.

With the identifier set to 0-3, I get the following output to serial:

Starting HelloServer on SAMD MKR1000 with WiFi101 using WiFi101 Library Connecting to WPA SSID: HTTP server started @

I can ping the device and it seems to be executing loop(). When using a browser to navigate to the server, the browser returns ERR_EMPTY_RESPONSE. No info is logged to Serial, and I can confirm that handleRoot or any other handler never gets called.

Very strange! Any ideas?

khoih-prog commented 3 years ago

Thanks for your encouraging words.

Can you try using the WebServer examples such as

  1. AdvancedWebServer
  2. WebServer

to see if the problem disappears. If so, check your code. It's possible you need to add some delay() somewhere or your code prevent some parts of the library from running.

You can also post a reproducible sketch to verify and debug.

Check How to create a Minimal, Reproducible Example

I actually don't have MKR1000 to test, only the similar Nano-33-IoT.

Good Luck,

williamsulzer commented 3 years ago

Thanks for the input! After some testing, I am able to make the original version of HelloServer work by adding a 1ms delay in the implementation of clientHandle after this line. I'm not sure why this fixes it or if delays need to be introduced in other parts of the library, but I'll keep playing with it.

I'm excited to start using the library in my project! Thanks again!

khoih-prog commented 3 years ago

Good to know.

It might be better to use yield() than delay(1) to be more efficient and avoid wasting time doing nothing.

Try to see if the MKR1000 core supports it.

Philwzen commented 3 years ago

insert this at https://github.com/khoih-prog/WiFiWebServer/blob/23215024c85eb0410a3cfd7aa790156f28a0a201/src/WiFiWebServer-impl.h#L198 before switch statement NOTE:Yield() doesnt work, so its a bit of a bodge!!

if defined(ARDUINO_SAMD_MKR1000)

  #if defined TimeAlarms_h
    Alarm.delay(1);
  #else 
    delay(1);
  #endif
#endif