D. M.
D. M.

Reputation: 11

ESP8266 Wifi P2P with Arduino

I am fairly new to using the ESP8266 and trying to get two of them to connect directly via the wifi generated by the server. For now, I am using two Arduino Unos, one for each wifi module. I am sending the ESP8266 AT commands from the Serial Monitor. I have one ESP8266 dedicated to being a server and the other as a client. My goal is to send a simple message from the client to the server without connecting to any external wifi. Here is the series of AT commands I am using in the Arduino Serial Monitor.

Server code:

INPUT:  AT+CWSAP="ESP SSID","ESP PASSWORD",2,3
OUTPUT: OK
INPUT:  AT+CWMODE=3
OUTPUT: OK
INPUT:  AT+CIPMUX=1
OUTPUT: OK
INPUT:  AT+CIPSERVER=1,80
OUTPUT: no change 
        OK
INPUT:  AT+CIFSR
OUTPUT: +CIFSR:APIP,"192.168.4.1"
        +CIFSR:APMAC,"2e:3a:e8:20:f9:96"
        +CIFSR:STAIP,"0.0.0.0"
        +CIFSR:STAMAC,"2c:3a:e8:20:f9:96"

Client Code:

INPUT:  AT+CWMODE=3
OUTPUT: OK
INPUT:  AT+CJAP="ESP SSID","ESP PASSWORD"
OUTPUT: WIFI CONNECTED
        WIFI GOT IP
INPUT:  AT+CIPMUX=1
OUTPUT: OK
INPUT:  AT+CIPSTART=2,"TCP","192.168.4.1",80
OUTPUT: ERROR
        2,CLOSED

I cannot figure out why I am getting this error when trying to start a connection with the server. I am aware of the thread Communication between 2 ESP8266 WiFi modules without router using AT commands but none of these solutions have fixed this error.

I have also swapped the original ESP8266s with 2 new ones, which did not solve the problem. In addition, I have been able to communicate with these wifi modules using a smartphone with a TCP client app, so I don't think any of my hardware is broken. Thank you for any suggestions and help.

Upvotes: 0

Views: 2299

Answers (1)

D. M.
D. M.

Reputation: 11

After some extreme trial and error, I got the connection to work. After manually setting the IP address of the client using

AT+CIPSTA="192.168.4.2"

the connection could be made using the AT commands above. I guess the client needs to contain the same first three parts of the IP address as the server. I'm not sure if I'm just a noob that should know about this IP address nomenclature, but here is an official answer to help others with the same problem. Good luck!

Upvotes: 1

Related Questions