Socket server only works on Mobile phone

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Zaszigre
Posts: 1
Joined: Fri Jun 01, 2018 6:30 am

Socket server only works on Mobile phone

Post by Zaszigre » Fri Jun 01, 2018 7:08 am

Hello every one !

Using the esp Luncher, I have a little issue. while developping, I as using my phone to test what happens on the client side. My cellular felt out of battery so I used, instead, my laptop whereas I didn't change anything.

Here's my code :

[code]
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
skt = socket.socket()
skt.bind(addr)
skt.listen(5)
htm = open('AskNWID.htm')
f_htm = htm.read()
while True:
cl, addr = skt.accept()
print('client connect from address ', addr)
query = cl.makefile('rwb', 0)
query = query.read(128)

query = query.decode('utf-8')[5:query.find(b'HTTP')]
print(query)

if query == 'data':
data = ""
data += ("<p>mode : %s" % (Mode.hardmode)) + "</p>\n"
data += ("<p>switch is %savailable") % "" if Mode._isAvailableDateReached() else "un"
elif 'RespNWID?' in query:
data, trash = query.split(b'?', 2)
SSID, PSWD = query.split(b'&', 2)
SSID = SSID[5:]
PSWD = PSWD[5:]
cl.send('OK')
print('analyzing data')
print(ussid, upswd)
elif len(query) == 1:
cl.send(f_htm)
time.sleep_ms(1000)
cl.close()
[/code] (sorry for BBCode, I can't turn it on. it is checked 'yes' on my profile preferences but anyway)

when trying to reach http://<IP>/ on my browser, it prints me 'connection reset' (translation from French 'connection réinitialisé').
when doing wget http://<IP>/ , it after 'HTTP request sent, waiting for response …"
But this is only from my laptop computer.

from my cellphone, my browser is able to print me the html page
however, using the 'terminal' termux on Android, a wget hangs after 'connecting to <IP> (<IP>:<PORT>)

So I assume my cellphone browser is able to deal with shaky socket communications But can you tell me what am I doing wrong.
You'll surely find many massive errors since I'm pretty new on python and even more with micropython.

thank's for your help !

Post Reply