Open zhongwujie opened 3 years ago
please enable debug output.
in the arduino IDE its a setting in the menu where you configure your board. https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html
for more advanced IDEs you need to set a compile define options. for example platform IO:
build_flags = -D DEBUG_ESP_PORT=Serial
the debug information is as follows. I still don't know why it failed and why wireShark can't capture it's packets.
the log shows that there is a connection problem on the TCP level. the ESP can not connect to 192.168.1.104 on port 5000.
the ESP is connected to 192.168.43.183/24 which is not the same layer 2 then 192.168.1.104. so most likely a routing or firewall problem in the network.
I don't think so. 192.168.43.183 is the IP of esp8266 given by DHCP
based on the logs the ESP tries to connect 192.168.1.104:5000 which is not the same layer 2 network segment then 192.168.43.183/24.
in this case the gateway (192.168.43.250) needs to have routes to 192.168.1.104 and the firewall needs to allow the connection.
Address: 192.168.43.183 11000000.10101000.00101011 .10110111
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111 .00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000 .11111111
=>
Network: 192.168.43.0/24 11000000.10101000.00101011 .00000000 (Class C)
Broadcast: 192.168.43.255 11000000.10101000.00101011 .11111111
HostMin: 192.168.43.1 11000000.10101000.00101011 .00000001
HostMax: 192.168.43.254 11000000.10101000.00101011 .11111110
Hosts/Net: 254 (Private Internet)
Thank you , I understand. We have also tested under the same subnet but also failed and I'll submit the debug log tomorrow. But I still have a question that why Wireshark can't capture the packets from 192.168.43.183? I think esp8266 will send the packet even if it can't reach the destination.
do you run Wireshark on the gateway (192.168.43.250) ? or on 192.168.1.104?
I make sure that the esp8266 and the server are under the same subnet, but it still failed.
We have changed the code of the server. Now the server can receive the data but the esp8266 log shows that the connection will be disconnected. Can you please help to see what is the problem?
ok the log now shows that the TCP connection is established and the first HTTP header is send from the ESP to the server. but the server kills the TCP connection after getting the header, from the ESP log alone its impossible to say why. only the server log can tell.
the most common problems are:
[WS-Client] connected to 192.168.1.106:5000.
[WS-Client][sendHeader] sending header...
[WS-Client][sendHeader] handshake GET / HTTP/1.1
Host: 192.168.1.106:5000
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: 7g5iBhC5kxXlYQGnjDS93A==
Sec-WebSocket-Protocol: arduino
Origin: file://
User-Agent: arduino-WebSocket-Client
[write] n: 245 t: 1217930
:wr 245 0
:wrc 245 245 0
[WS-Client][sendHeader] sending header... Done (30236us).
:ack 245
:rn 17
:rch 17, 168
:rcl pb=0x3fff1c64 sz=185
[WS-Client] connection lost.
@Links2004 i am also facing this issue [WS-Client] connected to 3.111.108.14:8878. [WS-Client][sendHeader] sending header... [String] 'GET / HTTP ... cket-Key: ': Reallocating large String(128 -> 154 bytes) [String] 'GET / HTTP ... bDN1mA== ': Reallocating large String(154 -> 178 bytes) [String] 'GET / HTTP ... arduino ': Reallocating large String(187 -> 204 bytes) [String] 'GET / HTTP ... file:// ': Reallocating large String(204 -> 242 bytes) [WS-Client][sendHeader] handshake GET / HTTP/1.1 Host: 3.111.108.14:8878 Connection: Upgrade Upgrade: websocket Sec-WebSocket-Version: 13 Sec-WebSocket-Key: 7UbTtB1Prh+C0heMbDN1mA== Sec-WebSocket-Protocol: arduino Origin: file:// User-Agent: arduino-WebSocket-Client
[write] n: 244 t: 134722 :wr 244 0 :wrc 244 244 0 [WS-Client][sendHeader] sending header... Done (58142us). :ack 244 :rn 28 :rcl pb=0x3fff276c sz=28 [WS-Client] connection lost. :ur 1 :dsrcv 28 :close
I tried many times to connect to the websocket server but failed。I used wireShark to capture packets but did not find the corresponding ip data packet。 The source code is as follows:
The information on Serial is as follows:
Connecting.....scandone state: 0 -> 2 (b0) .state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 1 cnt
connected with vivo X21, channel 1 dhcp client start... ....ip:192.168.1.107,mask:255.255.255.0,gw:192.168.1.1 . Connected, IP address: 192.168.1.107 [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected! [WSc] Disconnected!