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

Access Point connected but Browser unable to show HTML page - why ? #2

Closed iKK001 closed 3 years ago

iKK001 commented 3 years ago

Not sure what I am sitll doing wrong:

I try to get the Access Point working with the WiFiManager_Generic_Lite libarary.

I am using the Adafruit Feather M0 Board.

First I set the pins correctly for this particular board (i.e. in setup() { WiFi.setPins(8, 7, 4, 2); //...}

Second, I set USE_DYNAMIC_PARAMETERS = false (since I do not need dynamic parameters, or do I ?)

Then, after compiling, downloading and starting-up the SAMD_WIFI code, I can see Access Point "WIFI_GENERIC_XXXXXX". Moreover, on my mobile phone, I can connect to the Access Point by entering the Password "MyWIFI_GENERIC_XXXXXX". So far so good.

But then going to my browser on the mobile phone and entering http://192.168.4.1 does not do anything

Two questions:

  1. Why does http://192.168.4.1 not bring up the HTML Mask where I can finally enter the SSID and PW of my Home Network ??

  2. Where exactly in the Code can I change the Access Point Password (from "MyWIFI_GENERIC_XXXXXX" to something else) ??

khoih-prog commented 3 years ago

Just back home and see you got into this issue

  1. Did you modify defines.h #L155-L157 from

#define USE_WIFI_NINA             true
#define USE_WIFI101               false
#define USE_WIFI_CUSTOM           false

to

#define USE_WIFI_NINA             false
#define USE_WIFI101               true
#define USE_WIFI_CUSTOM           false

to use WiFi101 library?

Check if you have the informational warning when you compile the code.

In file included from /home/abcd/Arduino/arduino_working/WiFiManager_Generic_Lite_GitHub/examples/SAMD_WiFi/SAMD_WiFi.ino:27:
/home/abcd/Arduino/arduino_working/WiFiManager_Generic_Lite_GitHub/examples/SAMD_WiFi/defines.h:175:4: warning: #warning Using WiFi101 Library [-Wcpp]
  175 |   #warning Using WiFi101 Library

Also post the compiler output here so that I can spot if there is something not correct.

  1. Post the terminal display after modifying defines.h #L20 to
#define _WIFI_GENERIC_LOGLEVEL_       4

So far, I have no idea what's happening without info from you.

  1. You can change the SSID and PWD by using the function
void setConfigPortal(String ssid = "", String pass = "");

For example,

WiFiManager_Generic = new WiFiManager_Generic_Lite();

WiFiManager_Generic->setConfigPortal("your_ssid", "your_pwd");
  1. Did you check and verify the WebServer or WiFiWebServer example is working on your Adafruit Feather M0 Board ?

As I don't have the same board, only you can verify and make it working now.

Good Luck,

iKK001 commented 3 years ago

Thank you for all the hints.

Before I answer your points, I have to state that there is another change needed in your code - otherwise you cannot run on a physical device wihtout Serial Monitor:

Your code sais in SAMD_WiFi.ino, line 76: while (!Serial);

I changed it to : while (!Serial && (millis() < 3000));

Otherwise it waits in an endless loop until Serial Monitor is started. And this way, at least after 3 sec the Access Point gets built even if Serial Monitor is OFF...

(And by the way, commenting out DEBUG_WIFI_WEBSERVER_PORT and WIFI_GENERIC_DEBUG_OUTPUT inside defines.h does not help with this problem.)

Also, of course, the pinouts I change with the cmd WiFi.setPins(8, 7, 4, 2); (right as the first line of code inside setup() { ...} method. As we found out, the Adafruit Feather M0 needs this to work.

And last but not least: I have the following libraries installed via the Arduino Library Manager:

WiFiManager_Generic_Lite Functional-Vlpp DoubleResetDetector_Generic FlashStorage_SAMD WiFi101 WiFiWebServer

The following libraries I did NOT install:

WiFiNINA_Generic ESP_AT_Lib WiFiEspAT ESP8266_AT_WebServer FlashStorage_STM32

As you can see, compared to your original Arduino-Library-complete List - I figured that everything with ESP or Nina does not make sence for my board.

Do you know if I am missing a library still ?

Now that I can run the Code with or without Serial Monitor, I can get to your points:

Here my answers:

1a. Yes, I did change to WiFi101 (instead of NINA) 1b. No, I do not get this particular warning during compile

  1. Here is my Serial Monitor Terminal Display (after modification of _WIFI_GENERIC_LOGLEVEL_ to 4): (as you can see at the very beginning, the BOARD_NAME is SAMD_ZERO even tough in reality is is a SAMD21-type from Adafruit - hope that is not the issue....)
Start SAMD_WiFi on SAMD_ZERO with WINC1500 using WiFi101 Library
WiFiManager_Generic_Lite v1.4.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-WIFIGENERIC-51F485
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] Scanning Network
[WG] scanWifiNetworks: Done, Scanned Networks n = 2
[WG] Sorting
[WG] Removing Dup
[WG] WiFi networks found:
[WG] 1: MY_HOME_SSID, -41dB
[WG] 2: DIRECT-B9-HP OfficeJet Pro 6970, -76dB
[WG] SSID=NEW_SSID_DEFINED,PW=12345678
[WG] IP=192.168.4.1,CH=10
[WG] s:configTimeout = 0
F
Your stored Credentials :
Blynk Server1 = blank
Token1 = blank
Blynk Server2 = blank
Token2 = blank
Port = blank
MQTT Server = blank
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321
FFFFFFF
  1. Thanks, it works in a sence that I can connect to the Access Point with my mobile phone. However, going to the browser http://192.168.4.1 afterwards still does not show me any settings page.

One question: If I now use WiFiManager_Generic->setConfigPortal("your_ssid", "your_pwd"); - do I still need to call WiFiManager_Generic->setConfigPortalChannel(0); as well or not ?

  1. I understand that I should check : a) Arduino IDE --> Examples --> WiFiWebServer --> WebServer b) Arduino IDE --> Examples --> WiFi101 --> WiFiWebServer

Both do not work without the following two changes (i.e. basically the two identical changes that I had to implement in the WiFiManager_Generic_Lite SAMD_WiFi.ino in the first place...)

  1. make a timeout in the Serial Monitor, i.e. inside setup() { ... } method, replace while (!Serial); by while (!Serial && (millis() < 3000));

  2. change pinout (for Adafruit Feather M0 as compared to the WiFi101 library): i.e. add WiFi.setPins(8, 7, 4, 2); (right as the first line of code inside setup() { ...} method.

  3. And of course, for both, I had to enter an SSID and PW. (but that will not be necessary once in play with WiFiManager_Generic_Lite of course - but only if the WebServer and WiFiWebServer are run standalone).

But now, I cannot use the two libraries as standard since they need these two changes to work. The standard installed is read-only.

I try to reference my new versions of WebServer and WiFiWebServer - but I don't know how or where and I don't know whether this is even needed. Or does WiFiManager_Generic_Lite automatically does that ????

Are there other libraries referenced by WiFiManager_Generic_Lite that need to be adapted to the special Feather M0 pinout ?? If yes, which ones ?

Since I don't know what exactly your code is exactly doing, can you please help me with these library-references that seem to need custom libraries ?? And how I reference such a custom library in the first place ??

Also, with the two extra workarrounds needed (i.e. pinout and eventually serial monitor timeout), can you think of anything that would make the Access Point fail ?

Or is it something that I need to set on my iPhone, Android or Mac Browsers in order to get the settings page with http://192.168.4.1 ?

(I get ERR_EMPTY_RESPONSE when trying to connect)

And my very last point: Might be related: With my old Android phone I cannot even connect the Access Point. I am not sure if this is due to the fact that it is an older phone. With my iPhone or Mac I can connect the Access Point (but the http://192.168.4.1 does not work).

khoih-prog commented 3 years ago

That's good you're moving forward, yet still some more things to tackle.

  1. while (!Serial);

The example is just an example to demonstrate the basic feature of the library. The Serial debug port is intentional and mandatory to debug and understand what's wrong and going on. Please don't expect to be able to use the example as-is in your real use-case, and you have to modify the Serial code such as you did if you don't need it.

Anyway, I'll add some comment line to inform other un-experienced users about this.


  1. Do you know if I am missing a library still ?

That's all you need. Even adding many more libraries to the to-be-installed list seems to be excessive, it's better that way to help other users, as some don't know which one in necessary, even don't bother to scan thru README to figure out.

This certainly happens because the library has to support too many different kind of boards, wifi modules, platforms, etc.


  1. Start SAMD_WiFi on SAMD_ZERO with WINC1500 using WiFi101 Library

With this, I know you're setting and OK for WiFi101

BOARD_NAME is SAMD_ZERO

Adafruit Feather M0 is actually using same SAMD21 MCU and configurations such as SAMD_ZERO (with minor mods in analog pins).


  1. I still don't see the debug terminal output after you connect to Config Portal 192.168.4.1 It must be something similar to this
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
WiFiManager_Generic_Lite v1.4.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] SSID=WIFI_GENERIC_51F485,PW=MyWIFI_GENERIC_51F485
[WG] IP=192.168.4.1,CH=5
[WG] s:configTimeout = 0
F
Your stored Credentials :
Blynk Server1 = blank
Token1 = blank
Blynk Server2 = blank
Token2 = blank
Port = blank
MQTT Server = blank
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321

======== Displayed only after you've connected successfully to Config Portal ========

[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] 10 SSIDs found, generating HTML now
[WG] <option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home
[WG] pitem:</head><div style='text-align:left;display:inline-block;min-width:260px;'><fieldset><div><label>*WiFi SSID</label><div><input id='id' list='SSIDs'><datalist id='SSIDs'><option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home</datalist></div></div><div><label>*PWD (8+ chars)</label><input value='[[pw]]' id='pw'><div></div></div><div><label>*WiFi SSID1</label><div>[[input_id1]]</div></div><div><label>*PWD1 (8+ chars)</label><input value='[[pw1]]' id='pw1'><div></div></div></fieldset><fieldset><div><label>Board Name</label><input value='[[nm]]' id='nm'><div></div></div></fieldset>
[WG] pitem:</head><div style='text-align:left;display:inline-block;min-width:260px;'><fieldset><div><label>*WiFi SSID</label><div><input id='id' list='SSIDs'><datalist id='SSIDs'><option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home</datalist></div></div><div><label>*PWD (8+ chars)</label><input value='[[pw]]' id='pw'><div></div></div><div><label>*WiFi SSID1</label><div><input id='id1' list='SSIDs'><datalist id='SSIDs'><option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home</datalist></div></div><div><label>*PWD1 (8+ chars)</label><input value='[[pw1]]' id='pw1'><div></div></div></fieldset><fieldset><div><label>Board Name</label><input value='[[nm]]' id='nm'><div></div></div></fieldset>
[WG] h:HTML page size:2413
[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 id='id' list='SSIDs'><datalist id='SSIDs'><option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home</datalist></div></div><div><label>*PWD (8+ chars)</label><input value='' id='pw'><div></div></div><div><label>*WiFi SSID1</label><div><input id='id1' list='SSIDs'><datalist id='SSIDs'><option>HueNetTek<option>HueNet1<option>HueNet2<option>bacau<option>guest_24<option>rogers786<option>Jasmine<option>Home</datalist></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>
F

It's better that you use a PC to connect to the Config Portal (CP) because the browsers of Phone are sometimes not designed to work with complex HTMLs.

Also note the IP address of your phone / PC after you connect to the Config Portal SSID and verify that it must be something such as 192.168.4.abc.


  1. You can also use a different Config Portal IP to avoid IP conflict to so popular 192.168.4.1 IP by using
  // Optional to change default AP IP(192.168.4.1) and channel(10)
  WiFiManager_Generic->setConfigPortalIP(IPAddress(192, 168, 120, 1));

The CP IP now is 192.168.120.1

The following command is also important to avoid channel conflict by using random WiFi channel every time the board is reset

WiFiManager_Generic->setConfigPortalChannel(0);

Good Luck,

iKK001 commented 3 years ago

Thank you for your detailed answer, I highly appreciate it.

Here my answers:

1) / 2) / 3) --> OK - makes total sense

4-) The reason why you didn't get the debug terminal AFTER I enter 192.168.4.1 in a Windows-PC Browser is that THERE IS ABSOLUTELY NOTHING PRINTED TO THE TERMINAL

5-) Here is my implementation:

  WiFiManager_Generic = new WiFiManager_Generic_Lite();

  WiFiManager_Generic->setConfigPortal("NEW_SSID_DEFINED", "12345678");
  WiFiManager_Generic->setConfigPortalIP(IPAddress(192, 168, 120, 1));
  WiFiManager_Generic->setConfigPortalChannel(0);

After connecting with my Windows PC to NEW_SSID_DEFINED Access Point, and go to a Browser entering 192.168.120.1 THERE IS ABSOLUTELY NOTHING PRINTED TO THE TERMINAL - and also the Browser does not show anything. I only get the Error ERR_EMPTY_RESPONSE inside the Browser.

Something still does not work but I have no idea what it is.

It is as if the Access Point does not send the correct HTML-page content.... Do you have any more idea what to do ?

khoih-prog commented 3 years ago

Sorry you have the issue. I'm afraid there is some incompatibility of the old Adafruit Feather M0 Board with the library.

Without the physical board, there is no way I can find out what's wrong.

It's possible the board hangs up whenever you access the Config Portal => no more Serial printout.

I'm not going to spend any more time on this special rare board. You have to figure out yourself. I'm closing the issue now.

Good Luck,

iKK001 commented 3 years ago

oh no :(

Can you please recommend a better board that is newer ?

khoih-prog commented 3 years ago

I suggest that you use RP_2040_Connect as they're new and using better-supported WiFiNINA_Generic Library and this library.

The Nano_33_IoT is using the same W102 WiFiNINA, but much older and slower.

I don't know why you go to the not popular and less powerful board? Why not using ESP32-based boards (either from Adafruit or cheaper source)?

iKK001 commented 3 years ago

thank you - I need to look into the newer boards.

I want to thank you for all the effort in helping out here.

khoih-prog commented 3 years ago

You're very welcome. Hope not anytime in the near future you need help. ;-)