ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By Ovaltineo
#13971 Thanks guys! I finally solved my problem by testing the ESP in the same room as my wireless router. I was testing it two rooms away. This short distance is no problem for my laptop and phone but I guess the tcp/ip stack in the ESP firmware is not that robust.
User avatar
By Ovaltineo
#14219 I've spent more time trying to make it work with the ESP a reasonable distance away rom the router. I think there is a problem in the code -- it doesn't know what to do with Reconnect Callback being invoked. Here's what the code does. Actually, it doesn't do anything, and I think this causes the ESP to reset the station connection.

static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
HttpdConnData *conn=httpdFindConnData(arg);
os_printf("ReconCb\n");
if (conn==NULL) return;
//Yeah... No idea what to do here. ToDo: figure something out.
}

Here's the output from the console:

connected with roberts, channel 7
dhcp client start...
ip:192.168.1.110,mask:255.255.255.0,gw:192.168.1.254
Con req, conn=0x3fff53e8, pool slot 0
URL = /
Is url index 0
Conn 0x3fff53e8 is done. Closing.
Con req, conn=0x3fff54a8, pool slot 0
URL = /index.tpl
Is url index 3
Heatshrink compressed file; decode parms = b4
Conn 0x3fff54a8 is done. Closing.
Con req, conn=0x3fff5728, pool slot 0
URL = /style.css
Is url index 12
Heatshrink compressed file; decode parms = b4
Con req, conn=0x3fff5520, pool slot 1
URL = /cats/chris.jpg
Is url index 12
Heatshrink compressed file; decode parms = b4
Conn 0x3fff5728 is done. Closing.
Con req, conn=0x3fff5eb0, pool slot 0
URL = /cats/kids.jpg
Is url index 12
rm match
pm close 7 0 0/57614899
FindConnData: Huh? Couldn't find connection for 0x3ffe9d4c
ReconCb
FindConnData: Huh? Couldn't find connection for 0x3ffe9d4c
ReconCb
reconnect
scandone
add 0
aid 2
pm open phy_2,type:2 0 0
cnt

connected with roberts, channel 7
dhcp client start...
ip:192.168.1.110,mask:255.255.255.0,gw:192.168.1.254
User avatar
By Ovaltineo
#14240 Good news! I can now get it working at any place in my house. I added "Connection: close" header in all responses and I don't get reconnect errors anymore, especially in the home page where multiple resources (css and jpgs) are present in the page.

I examined the esphttpd code and noticed that the socket is being closed after a http response is sent. This works via AP mode because there is minimal propagation delay and the the browser client sees the socket has been closed before it has a chance to make another request on the same socket. In STATION mode, there is more propagation delay and the client has already made another request on the socket before it sees the close on the socket. This causes the ESP to reconnect the socket (doesn't really work) and causes havoc. By adding "Connection: close" to the response header, the client browser is forced to close the socket and open a new one for each request.

So, I was right in my original post, esphttpd is closing the socket too early.
User avatar
By Sprite_tm
#14259
Ovaltineo wrote:I've spent more time trying to make it work with the ESP a reasonable distance away rom the router. I think there is a problem in the code -- it doesn't know what to do with Reconnect Callback being invoked. Here's what the code does. Actually, it doesn't do anything, and I think this causes the ESP to reset the station connection.


To what I read in the documentation, this call is called to inform the user code that the connection has been 'reconnected', and you're not really supposed to do anything in that case. The comments unfortunately don't yet reflect that knowledge.