TCP SYN blocks incoming ARP requests
Posted: Wed May 06, 2015 3:35 pm
Hi,
I've built a simple project with a PIR sensor. When an event is detected, the ESP8266 just does a GET on an HTTP server. The code works most of the time, except when the server (on the LAN) makes an ARP request. It goes as follows:
- ESP8266 sends a TCP SYN packet
- Server broadcasts an ARP request ("who has this IP?")
- ESP8266 keeps sending TCP SYN packets every 500ms
- Server keeps sending ARP requests
- After trying 4 times to create the connection (i.e. after 2 seconds), the ESP8266 gives up
- The ESP8266 now listens and replies to the next incoming ARP request
- The server is happy and sends a TCP SYN ACK
- This was probably too late for the ESP8266 and it responds with a TCP RST ACK
So, as long as the server doesn't have to make an ARP request, all is good. If an ARP request is sent by the server, the ESP8266 is deaf to it while it's waiting for a SYN ACK.
I'm using NodeMCU 0.9.5 build 20150318. Here is my code:
If this can help, I have a PCAP that shows the issue. I don't know if the problem comes from NodeMCU or from the TCP stack of the ESP8266.
I've built a simple project with a PIR sensor. When an event is detected, the ESP8266 just does a GET on an HTTP server. The code works most of the time, except when the server (on the LAN) makes an ARP request. It goes as follows:
- ESP8266 sends a TCP SYN packet
- Server broadcasts an ARP request ("who has this IP?")
- ESP8266 keeps sending TCP SYN packets every 500ms
- Server keeps sending ARP requests
- After trying 4 times to create the connection (i.e. after 2 seconds), the ESP8266 gives up
- The ESP8266 now listens and replies to the next incoming ARP request
- The server is happy and sends a TCP SYN ACK
- This was probably too late for the ESP8266 and it responds with a TCP RST ACK
So, as long as the server doesn't have to make an ARP request, all is good. If an ARP request is sent by the server, the ESP8266 is deaf to it while it's waiting for a SYN ACK.
I'm using NodeMCU 0.9.5 build 20150318. Here is my code:
Code: Select all
PIRDataPin = 2 -- GPIO4
serverIP = "192.168.1.1"
serverPort = 80
serverURL = "/"
function onPIREvent(level)
print("Event detected:")
connect()
end
function connect()
local conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
print("-> Received: "..payload:sub(1, payload:find("\r\n")))
conn:close()
conn=nil
end)
conn:connect(serverPort, serverIP)
conn:send("GET "..serverURL.." HTTP/1.1\r\nHost: "..serverIP.."\r\n\r\n")
end
print("Setting up GPIO interrupt for PIR sensor on pin "..PIRDataPin..".")
gpio.mode(PIRDataPin, gpio.INT)
gpio.trig(PIRDataPin, "up", onPIREvent)
print("Waiting for PIR sensor event...")
If this can help, I have a PCAP that shows the issue. I don't know if the problem comes from NodeMCU or from the TCP stack of the ESP8266.