Communication between 2 ESP8266 WiFi modules without router using AT commands - tcp

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:
AT+CWMODE=3
AT+CIPMUX=1
AT+CIPSERVER=1,222
AT+CIFSR
/*the server response to CIFSR is:
+CIFSR:APIP,"192.168.7.7"
+CIFSR:APMAC,"a2:20:a6:10:50:2c"
+CIFSR:STAIP,"0.0.0.0"
+CIFSR:STAMAC,"a0:20:a6:10:50:2c"*/
The Client commands:
AT+CWMODE=3
AT+CWJAP="SERVER_SSID","SERVER_PASS"
AT+CIPMUX=1
AT+CIPSTART=2,"TCP","192.168.7.7",222
AT+CIPSEND=2,7
HELLO

Related

how to know what port is used to make http Get request from Postman

how to know what port is used to make http Get request from Postman?
I made this http Get request for example:
http://127.0.0.1:3000/
This request got through to the destination and the client could get response.
You can goto console >network >remote address to know the IP and port of the destination
if you goto localaddress , it shows the network through which it will connect to the destination (Meaning the subnet network ) like wireless network , vlan network etc.
You can goto cmd and type ifconfig or ipconfig and verify this

How can i run UDP client and server on two seperate computers?

I have a command line program using UDP socket and a UDP hub server running fine on my local host with seperate command prompts. Each the server and the client are bidirectional, so they both need to be able to send and recieve from each other.
I think that all i need to do to make them run on two seperate computers is to change the IP addresses and port numbers respectively. I think i will need to use the private IPV4 address because my socket is UDP IPV4. But i can't confirm because I do not have two different computers. Can someone please reassure me?
For instance, let's say I have basic UDP client and UDP server:
UDP Client is running on a computer with IPV4 162.16.156.1
UDP server is running on a computer with IPV4 162.18.200.1
UDP server should:
- bind to 162.18.200.1
- send to 162.16.156.1
- recieve would happen at 162.18.200.1
UDP client should:
- connect to 162.18.200.1
- send to 162.18.200.1
- recieve would happen at 162.16.156.1

"OSError: [Errno 99] Cannot assign requested address" for communication between Jetson TX2 Board and PC host

I think the IP address and port number are correct checked by using ifconfig at server side, and the port is not bind by others at server side. So, I guess the problem is at client side. I have attached the running results at client side and netstat result on server side (PC). They are all under the same wifi. Server IP is 10.42.0.197 and port # is 14450, the client ip is 10.42.0.1. The client side (TX2 board) still cannot bind the ip and port.
.
Try to check the interface associated with the IP you wanted to bind on client side. If you did not find any related IP then there is no associated connection with this IP. Resolve the connection issue and retry. Use netstat or ifconfig or ipconfig to check interfaces. This command vary per OS, check for the one that supports.

How do I use UdpSocket to send using a specific network interface?

I have machine with two Ethernet network interfaces. eno0 and eno1. eno0 is where the internet is plugged in and eno1 has a connected Ethernet device. I got its IP through Link-Local Address method and it's 168.254.80.23. I would like to send a packet to port 5000.
I would like to use Rust's UdpSocket to connect to this address and given port and send some packet. One such packet is already correctly described in the variable buf_with_message:
let sock = UdpSocket::bind("0.0.0.0:0"); //Let system assign me an ip and port
sock.connect(("168.254.80.23",5000)); // Connect to device ip and pre-designated port 5000
sock.send(&buf_with_message).unwrap(); //Send the packet
That connection occurs as it should, but the packet is send over eno0 instead of eno1. I have no idea how to specify the interface it should use. I have found some answers that in C SO_BINDTODEVICE could be used to do this.
I have also tried assigning an IP to the interface through
sudo ifconfig eno1 192.0.2.10
and then changing the 0.0.0.0 address in UdpSocket::bind to this new address with no positive result.
I see a potential solution to go straight to raw sockets using the pnet crate but I think that would be overkill.
I am aware that RFC 3927 warns against hosts with multiple interfaces, but I didn't find any options for an alternative without ditching LLA and implementing a DHCP server.
I have started a DHCP server and I am communication over the IP that is given through DHCP. I have no idea why LLA assigned IP doesn't work when DHCP does, but it works for now.

Sim900 GSM module keeps disconnecting when it's used as a TCP Client

I’m trying to interface a Sim900 GSM module (This one: http://www.elecfreaks.com/store/gprsgsm-moduleefcom-pro-efcompro-p-450.html) with a Tiva C microcontroller to initiate a TCP connection using a sim card.
The problem is that once the GSM module is connected to the server the internet of the GSM module auto disconnects and I have to reset it, but also sometimes it connects successfully to the server then auto disconnects after receiving any reply from the server, Although it's the same AT commands. why does that keep happening?
Edit:
These are the commands I'm using and the corresponding responses in order:
ATE0
\r\nOK\r\n
AT+CREG?
\r\n+CREG: 0,1\r\n\r\n
AT+CGATT?
\r\n+CGATT: 1\r\n\r\n
AT+CIPMUX=0
\r\nOK\r\n
AT+CGATT=1
\r\nOK\r\n
AT+CSTT
\r\nOK\r\n
AT+CIICR
\r\nOK\r\n
AT+CIFSR
the IP address of the GSM module
AT+CIPSTART="TCP",Server_IP,Server_Port
\r\nOK\r\n\r\nCONNECT
Sometimes the GSM disconnects right after the previous response
Sometimes it keeps working normally and sends the request to the server, but disconnects during the reply from the server after receiving few bytes.
The send command and its reply:
AT+CIPSEND
\r\n>
"The message"
\r\nSEND OK\r\n
I'm sure that the problem isn't with the IP address and Port number because I tested them using telnet.
Also sometimes the request reaches the server, but the GSM auto disconnects during the server reply.

Resources