Issue with wifimgr.py

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Issue with wifimgr.py

Post by ebolisa » Tue Apr 07, 2020 12:20 pm

Hi,

I cannot get to connect using the connection manager wifimgr.py.

I noticed that the '@' in my router's password is not recognized. How do I fix it?

TIA

Code: Select all

Request is: b'POST /configure HTTP/1.1\r\nHost: 192.168.4.1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3\r\nAccept-Encoding: gzip, deflate\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 43\r\nOrigin: http://192.168.4.1\r\nConnection: keep-alive\r\nReferer: http://192.168.4.1/\r\nUpgrade-Insecure-Requests: 1\r\n\r\nssid=PHONE_HOME&password=Jarandilla%4028232'
URL is configure
PHONE_HOME&password=Jarandilla%4028232 should be PHONE_HOME&password=Jarandilla@28232

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Issue with wifimgr.py

Post by jimmo » Tue Apr 07, 2020 1:55 pm

What is wifimgr.py? Can you provide a link?

%40 is the escaped form of @ (the ASCII value of @ is 0x40).

The http spec requires escaping special character (especially space, percent, ampersand and equals which would otherwise be interpreted as delimiting parameters).

My guess is is that wifimgr has it's own custom http server that doesn't know how to do the corresponding unescaping. (Replace "%xx" with chr(int("xx", 16)) ).

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Issue with wifimgr.py

Post by ebolisa » Tue Apr 07, 2020 2:34 pm

Hi, wifimgr.py can be found here https://github.com/tayfunulu/WiFiManage ... wifimgr.py

I fixed the problem by adding 'replace("%40", "@")' on lines 189, 190, 192 and 193.
I also had to adjust line 288 from 'request += client.recv(512)' to 'request += client.recv(560)' to accept more characters.

Not sure if it's the best way to go but it works now.

Thank you.

sspaman
Posts: 16
Joined: Fri Nov 02, 2018 5:03 pm

Re: Issue with wifimgr.py

Post by sspaman » Sun Apr 12, 2020 8:06 pm

Hi ebolisa, jimmo

Jimmo to answer your question wifimgr.py is a wifi manager for esp8266 and esp32 that was developed by Tayfunulu and can be seen here:

https://github.com/tayfunulu/WiFiManager

It's is a useful piece of code and is really convenient for connecting to wifi without having to hard code ssid and pw's. It seems to work good with a few bugs especially with android.

However I have found a bug using iOS on iPhone. Whenever connecting to wifi AP using iPhone after selecting the SSID and entering the PW I get an error displayed in the browser, "Parameters not found". The browser doesn't seem to make a difference. I tried safari, chrome and duckduckgo all with the same results. There is an active issue at the github repository but doesn't seen to be much activity there.

I was hoping someone could load up this code and try it out using iPhone and possibly help me resolve this. I am currently using esp32-wroom and micropython distro esp8266-20180511-v1.9.4.bin.

Thanks in advance.

Regards,
Chris

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Issue with wifimgr.py

Post by jimmo » Tue Apr 14, 2020 2:02 am

sspaman wrote:
Sun Apr 12, 2020 8:06 pm
I get an error displayed in the browser, "Parameters not found".
This sounds a lot like the issue the OP is describing. I took a quick look at the code, it's full of all sorts of issues with HTTP handling (i.e. parsing querystrings with regexp, etc).

It would be really good if someone could rewrite this on top of a "real" HTTP server library.

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Issue with wifimgr.py

Post by ebolisa » Tue Apr 14, 2020 5:24 pm

sspaman wrote:
Sun Apr 12, 2020 8:06 pm
However I have found a bug using iOS on iPhone. Whenever connecting to wifi AP using iPhone after selecting the SSID and entering the PW I get an error displayed in the browser, "Parameters not found". The browser doesn't seem to make a difference. I tried safari, chrome and duckduckgo all with the same results. There is an active issue at the github repository but doesn't seen to be much activity there.
Hi,

Please read my first post above. The issue is not Smartphone/browser related but ssid/password name related.

As I mentioned in my last post, my password had an @ in it and was causing the problem. Also, the sum of characters received (request) was above the limitation shown on line 288 which I had to change from "client.recv(512)" to "client.recv(555)".

EDIT: Also had to remove "decode("utf-8")" from lines 189, 190, 192 and 193
EDIT2: You can also change the above lines to

Code: Select all

from urllib.parse import unquote 
ssid = unquote(match.group(1))
password= unquote(match.group(2))
here you can find the libs : https://github.com/micropython/micropython-lib

Having said that, capture the received request and that will give you a clue.

sspaman
Posts: 16
Joined: Fri Nov 02, 2018 5:03 pm

Re: Issue with wifimgr.py

Post by sspaman » Sat Apr 18, 2020 2:44 pm

Hi,

Thanks for the reply. I didn't think your post was precisely related since I didn't have any special characters in my password. I'll give it a try.

So you are referring to these lines of code:

Code: Select all


    try:
        ssid = match.group(1).decode("utf-8").replace("%3F", "?").replace("%21", "!")
        password = match.group(2).decode("utf-8").replace("%3F", "?").replace("%21", "!")
    except Exception:
        ssid = match.group(1).replace("%3F", "?").replace("%21", "!")
        password = match.group(2).replace("%3F", "?").replace("%21", "!")

How would I replace this with your code? It seems to make sense to replace the try: portion but what about the exception? Or would I just replace the entire section? Also, any tips on capturing the received request?

Thanks,
Chris

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Issue with wifimgr.py

Post by ebolisa » Sat Apr 18, 2020 3:34 pm

@sspaman: request comes in on line 181
def handle_configure(client, request):
so just print it. You can see mine in my first post in this topic. I suggest you to take at look at your request first before changing any codes.

sspaman
Posts: 16
Joined: Fri Nov 02, 2018 5:03 pm

Re: Issue with wifimgr.py

Post by sspaman » Sat Apr 18, 2020 8:41 pm

Hi ebolisa,

It is clear I am now over my head and probably need training in network protocol. In any event here is the request response: (no idea what it means)

Code: Select all


 b'POST /configure HTTP/1.1\r\nHost: 192.168.4.1\r\nOrigin: http://192.168.4.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nUpgrade-Insecure-Requests: 1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nUser-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1\r\nReferer: http://192.168.4.1/\r\nContent-Length: 39\r\nAccept-Language: en-us\r\n\r\n'

None of this looks like an error to me. Any help you can provide is appreciated.

Regards,
Chris

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Issue with wifimgr.py

Post by ebolisa » Sun Apr 19, 2020 7:33 am

It's not an error, it's just a valuable information. If you take a look at my response text shown on my first post, you will notice that it ends with
ssid=PHONE_HOME&password=Jarandilla%4028232
That's my router's credentials. In that, I noticed what was happening. The system was converting the character @ to %40 which helped me solve my problem.

Your response text doesn't show your router's credentials so you need to investigate why is that's happening. Start by using a different browser.

Post Reply