khoih-prog / WiFiManager_Generic_Lite

"Library to configure MultiWiFi/Credentials at runtime for Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52, RP2040-based (Nano RP2040 Connect, RASPBERRY_PI_PICO), AmebaD RTL8720DN, etc. boards, using Generic WiFi (WiFiNINA, WiFi101, ESP8266-AT, ESP32-AT, etc.) modules/shields. You can also specify DHCP HostName, static AP and STA IP. Use much less memory compared to full-fledge WiFiManager. Config Portal will be auto-adjusted to match the number of dynamic custom parameters. Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Credentials are saved in LittleFS/InternalFS, (emulated-)EEPROM, FlashStorage_SAMD, FlashStorage_STM32, FlashStorage_RTL8720 or DueFlashStorage. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. DoubleDetectDetector as well as Virtual Switches feature permits entering Config Portal as requested. Now using WiFiMulti_Generic library
MIT License
9 stars 3 forks source link

MKR1000 Example : Config portal will not come up. #3

Closed pgeremia closed 2 years ago

pgeremia commented 2 years ago

Describe the bug

Using example code for MKR1000 the config portal will not come up.

Steps to Reproduce

Load example MKR1000_WiFi101 sketch and run. Connect to Wifi AP Run curl with -v and point to 192.168.4.1 to see web portal. There is a connection but it is immediately closed before config portal shows up.

Expected behavior

Config portal is displayed allowing you to set up wifi access.

Actual behavior

Config portal is never displayed.

Screenshots

** This is run when it failed with debugging level 4 enabled

Connect to serial port /dev/cu.usbmodem1444101 at 115200

Start MKR1000_WiFi101 on Unknown SAMD21 board with WINC1500 using WiFi101 Library
WiFiManager_Generic_Lite v1.6.0
[WG] Set CustomsStyle to : <style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>
[WG] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[WG] Set CORS Header to : Your Access-Control-Allow-Origin
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xffffffff
No doubleResetDetected
SetFlag write = 0xd0d01234
[WG] CCSum=0xe11e,RCSum=0xffffffff
[WG] ChkCrR:pdata=����������������������������������,len=34
[WG] ChkCrR:pdata=����������������������������������,len=34
[WG] ChkCrR:pdata=����������������������������������,len=34
[WG] ChkCrR:pdata=����������������������������������,len=34
[WG] ChkCrR:pdata=������,len=6
[WG] ChkCrR:pdata=����������������������������������,len=34
[WG] ChkCrR:CrCCsum=0xaf50,CrRCsum=0xffffffff
[WG] InitCfgFile,sz=236
[WG] g:myMenuItems[0]=blank
[WG] g:myMenuItems[1]=blank
[WG] g:myMenuItems[2]=blank
[WG] g:myMenuItems[3]=blank
[WG] g:myMenuItems[4]=blank
[WG] g:myMenuItems[5]=blank
[WG] SaveEEPROM,Sz=1024,DataSz=0,WCSum=0xdb3
[WG] pdata=blank,len=34
[WG] pdata=blank,len=34
[WG] pdata=blank,len=34
[WG] pdata=blank,len=34
[WG] pdata=blank,len=6
[WG] pdata=blank,len=34
[WG] CrCCSum=0xc30
[WG] bg: isForcedConfigPortal = false
[WG] bg:Stay forever in CP:No ConfigDat
[WG] SSID=NIXIESHIELDFORARDUINO,PW=(**removed password**)
[WG] IP=192.168.4.1,CH=11
[WG] s:configTimeout = 0
C
Your stored Credentials :
Blynk Server1 = blank
Token1 = blank
Blynk Server2 = blank
Token2 = blank
Port = blank
MQTT Server = blank
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321
[WG] serverSendHeaders:WM_HTTP_CACHE_CONTROL:Cache-Control=no-cache, no-store, must-revalidate
[WG] serverSendHeaders:WM_HTTP_CORS:Access-Control-Allow-Origin : Your Access-Control-Allow-Origin
[WG] serverSendHeaders:WM_HTTP_PRAGMA:Pragma : no-cache
[WG] serverSendHeaders:WM_HTTP_EXPIRES:Expires : -1
[WG] h:HTML page size:2101
[WG] h:HTML=<!DOCTYPE html><html><head><title>SAMD_WM_Lite</title><style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style><style>html{filter: invert(10%);}</style></head><div style='text-align:left;display:inline-block;min-width:260px;'><fieldset><div><label>*WiFi SSID</label><div><input value='' id='id'></div></div><div><label>*PWD (8+ chars)</label><input value='' id='pw'><div></div></div><div><label>*WiFi SSID1</label><div><input value='' id='id1'></div></div><div><label>*PWD1 (8+ chars)</label><input value='' id='pw1'><div></div></div></fieldset><fieldset><div><label>Board Name</label><input value='' id='nm'><div></div></div></fieldset><fieldset><div><label>Blynk Server1</label><input value='blank'id='sv1'><div></div></div><div><label>Token1</label><input value='blank'id='tk1'><div></div></div><div><label>Blynk Server2</label><input value='blank'id='sv2'><div></div></div><div><label>Token2</label><input value='blank'id='tk2'><div></div></div><div><label>Port</label><input value='blank'id='prt'><div></div></div><div><label>MQTT Server</label><input value='blank'id='mqt'><div></div></div></fieldset><button onclick="sv()">Save</button></div><script id="jsbin-javascript">function udVal(key,val){var request=new XMLHttpRequest();var url='/?key='+key+'&value='+encodeURIComponent(val);request.open('GET',url,false);request.send(null);}function sv(){udVal('id',document.getElementById('id').value);udVal('pw',document.getElementById('pw').value);udVal('id1',document.getElementById('id1').value);udVal('pw1',document.getElementById('pw1').value);udVal('nm',document.getElementById('nm').value);udVal('sv1',document.getElementById('sv1').value);udVal('tk1',document.getElementById('tk1').value);udVal('sv2',document.getElementById('sv2').value);udVal('tk2',document.getElementById('tk2').value);udVal('prt',document.getElementById('prt').value);udVal('mqt',document.getElementById('mqt').value);alert('Updated');}</script></html>

Information

Arduino IDE version: 1.8.13 MKR1000 Hardware (just purchased) updated to latest WIFI firmware (19.6.1) Using Eclipse IDE with Sloeber Arduino Env Running on MacOS

Additional context

I turned on debugging and played around with the different parameters. I have found that when I turn off

USE_DYNAMIC_PARAMETERS and SCAN_WIFI_NETWORKS

The config portal then works.

I will do more debugging after work and see if I can isolate it any further.

The test I did took the stock example with almost no changes running on a MKR 1000 with the LATEST wifi firmware.

khoih-prog commented 2 years ago

HI @pgeremia

Thanks for your interest in the library and investigation.

I'm sorry I don't have the too-old MKR1000 to test and help you, so you're on your own.

Some suggestions

  1. Try using my forked copy of WiFi101. As you know, WiFi101 library is very old and buggy.
  2. Test to know if FlashStorage_SAMD is working on your board
  3. Verify if the board is defective
  4. If still early in the project, try to use better and more powerful board, such as ESP32, ESP8266, Nano_RP2040_Connect, Nano_33_IoT, etc.
  5. Use Arduino IDE v1.8.19 with native Arduino editor

I have to close the issue now, and only reopen when you prove this is a bug of this library

Good Luck,

pgeremia commented 2 years ago

Thank you for the help. I really appreciate the guidance. I use the Nano 33 IoT in many other projects. Unfortunately for this project I have to use a Uno form factor. So I need to use MKR1000 with MKR2UNO adapter. I will get it working and let you know the solution. Again thank you for your help!!

khoih-prog commented 2 years ago

Can you try using ESPDuino-32 or similar ESP32 with same UNO form factor.

image

instead of

image

pgeremia commented 2 years ago

Yes!! That is a great idea. Ordering now and will give it a go! Thanks!!!

pgeremia commented 2 years ago

So while I am waiting for the new board to come in I did a little more digging and I think I found something. If the length of the web page is greater than around 1400 bytes it hangs and the web page is never displayed. So I went into the wifiwebserver code and instead of sending the entire web page, I decided to call the wifi client write method that takes a single byte. It is a little slower but it now works! But as expected other network functions in my program are not working and hanging. So like you said it probably is the buggy wifi101 library. I will just wait for the new board!

/////////////////////////////////////////////////////////////////////////
//PG
void WiFiWebServer::sendContent(const String& content, size_t size)
{
  const char * footer = RETURN_NEWLINE;

  if (_chunked) 
  {
    char * chunkSize = (char *) malloc(11);

    if (chunkSize) 
    {
      WS_LOGDEBUG(F("sendContent: _chunked"));

      sprintf(chunkSize, "%x%s", size, footer);
      _currentClient.write(chunkSize, strlen(chunkSize));
      free(chunkSize);
    }
  }

  WS_LOGDEBUG1(F("sendContent: Client.write content: "), content);
  ///////////////////////////////
  //Write data a byte at a time
  //////////////////////////////
  for (int i = 0 ; i < size ; i++ )
  {
      _currentClient.write(content[i]);
  }
  //_currentClient.write(content.c_str(), size);

  if (_chunked) {
    _currentClient.write(footer, 2);
  }
}
khoih-prog commented 2 years ago

The limit 1400 is defined by

socket.h#L88

as

#define SOCKET_BUFFER_MAX_LENGTH       1400

You can try to send by chunk by modify the code somewhere to enable it. I don't have time now to look at it.

pgeremia commented 2 years ago

I think I will wait for the other board and go from there. I did try to increase the max length but I then had other odd things happen like the web page was not rendered correctly. Maybe some kind of corruption? Anyway the espduino-32 boards have been shipped and are on their way. Thank you!

pgeremia commented 2 years ago

I got the new ESPDUINO-32 board. I am using ESP_WiFiManager_Lite. It works much better and WiFi seems to work. The only thing I cannot figure out is an issue accessing the onboard file system. I get this error:

When I start up: (26) SPIFFS: mount failed, -10025

Then a little while later:

LittleFS_esp32/1.0.6/src/lfs.c:1076:error: Corrupted dir pair at {0x1, 0x0} E (36025) esp_littlefs: mount failed, (-84) E (36073) esp_littlefs: Failed to initialize LittleFS

If I use ESP_WiFiManager everything works great. So I may just rewrite my application to use that instead unless you know what may be the issue. I have spent a lot of time trying to figure it out with not a lot of luck.

Thank You.

khoih-prog commented 2 years ago

I'm glad you're doing much better now with the new ESPDUINO-32 board.

I don't have any issue using ESP_WiFiManager_Lite with that same ESPDUINO-32 board.

Be sure to start with the ESP_WiFi example to have a good feeling before moving on.

Check if you

  1. select LittleFS, not SPIFFS
  2. use latest ESP32 code v2.0.2 as specified in Prerequisites
  3. Install either ESP_DoubleResetDetector or ESP_MultiResetDetector library.

Good Luck,


Debug Terminal

Starting ESP_WiFi using LittleFS on ESP32_DEV
ESP_WiFiManager_Lite v1.8.2
ESP_MultiResetDetector v1.3.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
lowerBytes = 0x0001, upperBytes = 0x0001
No multiResetDetected, number of times = 1
LittleFS Flag read = 0xFFFE0001
Saving config file...
Saving config file OK
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=password
[WML] SSID1=HueNet2,PW1=password
[WML] BName=ESP32_WMLite_v105
[WML] WiFi networks found:
[WML] 1: HueNet1, -40dB
[WML] 2: HueNetTek, -42dB
[WML] 3: HueNet2, -56dB
[WML] 4: El khoury, -80dB
[WML] 5: ESP151CD5, -81dB
[WML] 6: DECO-5655, -88dB
[WML] 7: rogers786, -89dB
[WML] 8: Guest5655, -89dB
[WML] 9: house, -90dB
[WML] 10: Jessie, -91dB
[WML] 11: Rogers 786, -91dB
[WML] 12: Jasmine, -93dB
[WML] 13: Access, -94dB
[WML] 
stConf:SSID=your_customized_ssid,PW=your_customized_pwd
[WML] IP=192.168.4.1,ch=8
C
Your stored Credentials :
Blynk Server1 = blank
Token1 = blank
Blynk Server2 = blank
Token2 = blank
Port = blank
MQTT Server = blank
Stop multiResetDetecting
Saving config file...
Saving config file OK
CC
pgeremia commented 2 years ago

All I had to do is grab the defines in the example you provided and everything worked perfectly! Turns out my defines (from another example) did not have the circled section so it was using SPIFFS. Thanks again for all of your help!! I really appreciate it!!!

littlefs