Webserver send() + POST data reception

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
trap16
Posts: 1
Joined: Tue Dec 04, 2018 8:23 pm

Webserver send() + POST data reception

Post by trap16 » Tue Dec 04, 2018 8:47 pm

Hello,

I'm currently developping a soft on micropython for ESP8266 board.

I was currently working on a minimalist webserver to access and configure the board and notices 2 behaviors i need expertise.

Current software if a simple http server (I create a socket TCP on port 80 then listen + accept connection), the initial GET request from the client browser is replied with a formular with text input field in POST mode, the subsequent POST request should send my text to the ESP8266

I checked the class on my local computer with python/idle, this works perfectly, I see my formular, can fill it and process the user input. But when uploading it on the ESP and running it I see strange behavior.

The initial problem I faced is with closing the connection my code was somewhat like

while True:
conn ... = self.sock.accept()
query = conn.recv(2048)
...
conn.send(reply)
conn.close()

The client browser was hanging, I then added a time.sleep(1) before the conn.close() and saw it works (means the connection is closed before the reply is sent), is there a better way to handle that (I thought send would be a blocking call) ?

The second issue is very weird : when i print(query) on my local computer I see the POST data, but not on the ESP8266.
The contents of the datas are stricly the same, except the last line (containing the post data) which does not exist when printed on the server running on ESP8266.
I don't know if it is because of my web browser (chrome) or if it is an issue on the ESP8266, anyone by chance had experienced similar issue to give a hint ?

Best regards.

[EDIT] : added the dump of buffer of the POST request in both cases :

Local computer :

b'POST / HTTP/1.1\r\nHost: 172.16.2.1\r\nConnection: keep-alive\r\nContent-Length: 28\r\nCache-Control: max-age=0\r\nOrigin: http://172.16.2.1\r\nUpgrade-Insecure-Requests: 1\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\nReferer: http://172.16.2.1/\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7\r\n\r\nSSID=toto&PASS=&ACTION=Check'

ESP8266 :

b'POST / HTTP/1.1\r\nHost: 172.16.1.30\r\nConnection: keep-alive\r\nContent-Length: 28\r\nCache-Control: max-age=0\r\nOrigin: http://172.16.1.30\r\nUpgrade-Insecure-Requests: 1\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\nReferer: http://172.16.1.30/\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: fr-FR,fr;q=0.9,en-US'

As you can see the local computer environment has a trailing ";q=0.8,en;q=0.7\r\n\r\nSSID=toto&PASS=&ACTION=Check" which is not present when i run the same software on ESP8266

Post Reply