I'm trying to make a TCP based communication to send a simple message "Hello" from one ESP8266 module to another using this document. I'm using 2 USB to TTL as hardware and Realterm as serial terminal. I could do it when ESP8266 modules are connected to a router, sending AT commands as below,
Set the Server:
AT+CWJAP="AccessPointName","Password"//Join to your WiFi network
AT+CIPMUX=1//0 for single connection 1 for multiple connection.
AT+CIPSERVER=1,1336//Set as Server. 1 to open Server mode(0 to close). 1336 is port.
AT+CIFSR//Get IP address (STAIP 192.168.43.151)
Set the Client:
AT+CWJAP="AccessPointName","Password"
AT+CIPMUX=1
AT+CIPSTART=1,"TCP","192.168.43.151",1336//Set up TCP or UDP connection, the 4 parameters are id, type, adress and port.
AT+CIPSEND=1,7// Channel and number of bytes to send
//After issuing all previous command you will receive "OK". But afterAT+CIPSENDyou will receive a ">" as response.
Hello//send your Data
I want to connect both ESP8266 to each other without a router. So I used these AT commands:
Server commands:
AT+CIPMUX=1
AT+CWMODE=3//set the module as a client and also an access point.
AT+CIPSERVER=1,1336
AT+CIFSR //Getting 2 ip address (APIP 192.168.4.1 and STAIP 0.0.0.0).
Client commands:
AT+CIPMUX=1
AT+CWMODE=3
AT+CWJAP="ESP1 SSID", "ESP1 PWD" //Connect to server
AT+CIPSTART=1,"TCP","0.0.0.0",1336 // I also tried APIP 192.168.4.1.
But when I send CIPSTART
command I get ERROR
message.
What's going wrong? What should I do?
In the context of a route entry, the 0.0.0.0 means the default route. In the context of servers, 0.0.0.0 means all IPv4 addresses on the local machine. If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs. This type of communication is also known as WiFi P2P or Wifi direct. It should work properly with your commands! If problem persists try with different modules.
I changed modules and it's working now.
The Server Commands:
The Client commands: