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
105 stars 21 forks source link

MKR1000 #1

Closed sid4084 closed 4 years ago

sid4084 commented 4 years ago

This does not work on MKR1000. Serial monitor shows: Starting HelloServer on SAMD MKR1000

But then hangs up on WiFi.begin

khoih-prog commented 4 years ago

Hi @sid4084 The WiFiWebServer library is written specifically for WiFiNINA and other WiFi libraries using the standard #include . Unfortunately , MKR1000 uses WiFi101 library and we need to use #include

The WiFiWebServer v1.0.3 currently does not support MKR1000 running WiFi101.

This is the quick fix to enable MKR1000 to use this library (will be included in new v1.0.4)

  1. Modify WiFiWebServer.h from
// Modify to use new WiFiNINA_Generic library to support boards besides Nano-33 IoT, MKRWiFi1010, Adafruit MetroM4, etc.
#if USE_WIFI_NINA
#include <WiFiNINA_Generic.h>
#else
#include <WiFi.h>
#endif

to

// Modify to use new WiFiNINA_Generic library to support boards besides Nano-33 IoT, MKRWiFi1010, Adafruit MetroM4, etc.
#if USE_WIFI_NINA
#include <WiFiNINA_Generic.h>
#elif USE_WIFI101
#include <WiFi101.h>
#else
#include <WiFi.h>
#endif
  1. Modify any example similarly to the following example HeloServer.ino
    
    #define DEBUG_WIFI_WEBSERVER_PORT Serial

define USE_WIFI_NINA true

if defined(ARDUINO_SAMD_MKR1000)

if defined(USE_WIFI_NINA)

#undef USE_WIFI_NINA

endif

define USE_WIFI_NINA false

define USE_WIFI101 true

endif

if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) )

if defined(WIFI_USE_NRF528XX)

#undef WIFI_USE_NRF528XX

endif

define WIFI_USE_NRF528XX true

endif

.....

void setup(void) { // Open serial communications and wait for port to open: Serial.begin(115200); while (!Serial);

Serial.println("\nStarting HelloServer on " + String(BOARD_TYPE));

// check for the presence of the shield

if USE_WIFI_NINA

if (WiFi.status() == WL_NO_MODULE)

else

if (WiFi.status() == WL_NO_SHIELD)

endif

{ Serial.println(F("WiFi shield not present")); // don't continue while (true); }

if USE_WIFI_NINA

String fv = WiFi.firmwareVersion(); if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("Please upgrade the firmware"); }

endif

....



Please try the modified code and let me know so that I can update the release.
I also post the updated code on Master.
sid4084 commented 4 years ago

The above fix did work, WiFi now connects and the HTTP server is working on MKR1000. Excellent! Thank you!

khoih-prog commented 4 years ago

Good news. I'll post new release v1.0.4 to provide support to MKR1000. Your contribution will be noted. Regards,

khoih-prog commented 4 years ago

Hi @sid4084

Please test the new v1.0.4 library and inform it's all OK now for you.

Thanks,

sid4084 commented 4 years ago

I have tested with library v1.0.4 and this issue is fixed.

I currently am unable to use Transfer-Encoding: chunked, which is needed for HTTP responses larger than 1400 chars. In my handleRoot() function I have: server.setContentLength(CONTENT_LENGTH_UNKNOWN); server.send(200, "text/html", temp); and the response header includes 'Transfer-Encoding: chunked', but the connection never completes. There may be some problem with the format of the last chunk. But I think this will be a topic for a new Issue.

khoih-prog commented 4 years ago

I think that is the issue of the W101 library the MKR1000 is using. If so, you can post the issue there to ask for help.

The WiFiWebServer library is based on many other libraries (ESP8266-AT, WiFiNINA, W101, etc.), and the performance / behaviors depend on those underlying libs. The find out exactly what happening, you can

  1. Use the W101 library examples to see if the problem still exists, especially with large data. Many WiFi, even Ethernet libraries have the 2K buffer limit issues unless fixed.
  2. Put many more debugging msgs to see what actually happening.
  3. Check to see if MKR1000 RAM is enough to run your application.
  4. If OK with all W101 examples, move gradually to WiFiWebServer library, step by step.

You can also post the total test code here so that somebody or I can have a look. I'm sorry I don't have any MKR1000 to know what's happening. Hope someone can help testing.