The following sequence of commands will (1) start a TCP server listening for traffic on port 80 and (2) start a UDP server and listen for incoming UDP packets from all addresses.
AT
OK
AT+CWMODE_CUR=3
OK
AT+CWJAP="AWS","Codehappy123"
OK
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"1a:fe:34:f4:ef:b2"
+CIFSR:STAIP,"192.168.19.30"
+CIFSR:STAMAC,"18:fe:34:f4:ef:b2"
OK
AT+CIPMUX=1
OK
AT+CIPSERVER=1,80
OK
AT+CIPSTART=0,"UDP","0.0.0.0",4445,4445,2
0,CONNECT
OK
+IPD,0,15:turn light 2 on
OK
+IPD,0,16:turn light 1 off
OK
+IPD,0,13:connect servo
OK
AT+CIPCLOSE=0
0,CLOSED
OK
The generic sequence of commands is the following:
AT+CWMODE=3
OK
AT+CWJAP="AP_SSID","AP_PASSWORD"
OK
AT+CIPMUX=1
OK
AT+CIPSTART=0,"UDP","192.168.0.140",4445,4445,2
0,CONNECT
OK
AT+CIPSEND=0,7,"192.168.0.140",4445
OK
> hello\r\n
SEND OK
AT+CIPCLOSE=0
0,CLOSED
OK
Log for Creating Server:
AT+CWMODE=3
OK
AT+CWJAP="AP_SSID","AP_PASSWORD"
OK
AT+CIPMUX=1
OK
AT+CIPSTART=0,"UDP","192.168.0.140",4445,4445,2
0,CONNECT
OK
+IPD,0,13:test from nc
OK
AT+CIPCLOSE=0
0,CLOSED
OK
The AT commands used above are defined as follows:
AT+CIPSTART=<id>,<type>,<remote address>,<remote port>[,(<local port>),(<mode>)]
AT+CIPSEND=[<id>,]<length>[,<ip>,<port>]
AT+CIPCLOSE=<id>
Run the following command (tested on Mac OS X):
echo "test from nc" | nc -4u -w0 192.168.0.140 4445
Note that the -w0
argument can be replaced with -w1
.
- This sequence connects to an access point (AP) with SSID "AP_SSID". This could also be done on the ESP8266 when set up as a "soft AP".
- This sets AT+CWMODE=3. This could be different.
- Likewise, this sets AT+CIPMUX=1. This could be AT+CIPMUX=0, but that case is not covered here.
- Here, the UDP local port is 4445. The remote IP and port are irrespective until sending data.
I used your exemple (Create a UDP Server (Listen to Specific Address)) for work with ESP07 it is work, great!
But if change last parameter of IP adress to 255 in this exemple, it work great for broadcast datagrams listerning in local network.
Thanks your so much!