Hello everyone!
I am looking for an example/guide how to use TCP/IP protocol to set up connection between few ESP modules.
So far i prepared UDP communication between 3 esp modules and it works, now i am looking for TCP/IP example. I would be grateful if u could help me and show me the example/code of TCP/IP implementation!
Regards!
EPS - ESP communication via TCP/IP
Re: EPS - ESP communication via TCP/IP
Hallo,
I'm interested in the UDP-example. Can you write the program (the UDP parts) here in the forum.
thank you
Thomas
I'm interested in the UDP-example. Can you write the program (the UDP parts) here in the forum.
thank you
Thomas
Re: EPS - ESP communication via TCP/IP
Sure: here you have the code:
Server :
and the client:
Server :
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- WiFiUDP Udp;
- unsigned int localUdpPort = 4210; // local port to listen on
- char incomingPacket[255];
- IPAddress ip(192, 168, 4, 1);
- void setup()
- {
- Serial.begin(115200);
- Serial.println();
- WiFi.begin("ESP32", "123456789");
- Serial.print("Connecting");
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println();
- Serial.print("Connected, IP address: ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- while (WiFi.status() != WL_CONNECTED)
- {
- WiFi.reconnect();
- delay(10000);
- Serial.print(".Reconnected");
- Serial.println(WiFi.localIP());
- }
- Udp.beginPacket(ip, localUdpPort);
- Udp.write("45"); // wysyłamy jeden bajt
- Udp.endPacket();
- Serial.print("Wyslalem cos\n");
- delay(5000);
- }
- }
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <WiFiAP.h>
- #include <WiFiUdp.h>
- #include <stdlib.h>
- WiFiUDP Udp;
- unsigned int localUdpPort = 4210; // local port to listen on
- char incomingPacket[255]; // buffer for incoming packets
- void setup()
- {
- Serial.begin(115200);
- Serial.println();
- Serial.print("Setting soft-AP ... ");
- Serial.println(WiFi.softAP("ESP32", "123456789") ? "Ready" : "Failed!");
- IPAddress myIP = WiFi.softAPIP();
- Serial.print("AP IP address: ");
- Serial.println(myIP);
- Udp.begin(localUdpPort);
- Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
- }
- void loop()
- {
- int packetSize = Udp.parsePacket();
- if (packetSize)
- {
- // receive incoming UDP packets
- Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
- int len = Udp.read(incomingPacket, 255);
- if (len > 0)
- {
- incomingPacket[len] = 0;
- }
- Serial.printf("UDP packet contents: %s\n", incomingPacket);
- }
- }
Re: EPS - ESP communication via TCP/IP
Hallo,
thank you for your post.
I have never worked before with UDP directly. I see your code so: The server sends and the client receives one Byte.
This is a communication in one direction. For two-way communication I have to mix client and server without the long delay() at the end of the server-loop...
I will try it and talk about my results here.
bye
Thomas
thank you for your post.
I have never worked before with UDP directly. I see your code so: The server sends and the client receives one Byte.
This is a communication in one direction. For two-way communication I have to mix client and server without the long delay() at the end of the server-loop...
I will try it and talk about my results here.
bye
Thomas
Who is online
Users browsing this forum: No registered users and 86 guests