Static ip bug? esp32 received his own messages...

Posts: 1
Joined: Tue Jul 09, 2019 12:37 pm

Static ip bug? esp32 received his own messages...

Postby martin.ger » Tue Jul 09, 2019 1:00 pm

Hi i hope someone can help me with my problem. if i use static ips for the esp32 this esp received his own messages( ips all the same that the non static) so i don't know how to solve this problem.

I want to build a communication with around 1000 nodes (First and last node have a distance of around 100Meters) in line one of them is the root node and send every messages to the next esp. so i need every node with ap+sta and with a fixed ip i know which one is where. And i know tcp is slow the code here needs around 700ms to send a message to the next esp/ with udp 5ms.. tcp is only for testing.. if someone had a good idea how to solve the send receiving problem it would be great. and im open for all good ideas to make the communication better. And sorry for my english i hope everybody understand what i want so say :-)

Here my code:

#include <Arduino.h>

#include <WiFi.h>
#include <WiFiMulti.h>

WiFiMulti WiFiMulti;
const char* ssidap = "node2";
const char* passwordap = "12345678";
int counter = 2;
WiFiServer server(80);

void setup()

//This part of code will try create static IP address subnet, primaryDNS, secondaryDNS)) {
//if (!WiFi.config(local_IP, gateway , subnet)) {
//Serial.println("STA Failed to configure");
//WiFi.mode(WIFI_AP_STA); wenn du das ausführst wars das ^^
// WiFi.mode(WIFI_MODE_APSTA);wenn du das ausführst wars das ^^

if (counter==2){

IPAddress local_IP(192, 168, 4, 2);
// Set your Gateway IP address
IPAddress gateway(192, 168, 4, 1);

IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(192, 168, 4, 1); //dont work!!!
IPAddress secondaryDNS(4, 4, 4, 4); //??
primaryDNS=IPAddress(192,168, 4, 1); works fine:-)
secondaryDNS=IPAddress(4, 4, 4, 4);
//WiFi.softAPConfig(local_IP,local_IP, IPAddress(255, 255, 255, 0));
if (!WiFi.config(local_IP, gateway , subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");

WiFi.softAP("node2", "12345678");
WiFiMulti.addAP("node1", "12345678");

Serial.print("Waiting for WiFi... ");

while( != WL_CONNECTED) {

Serial.println("WiFi connected");
Serial.println("IP address: ");


int value = 0;

void loop()
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.print("ESP Mac Address: ");
Serial.print("Subnet Mask: ");
Serial.print("Gateway IP: ");
Serial.print("DNS: ");

//server code!
WiFiClient client = server.available(); // listen for incoming clients

if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
String c = client.readStringUntil('\r'); // read a byte, then
Serial.println(c); // print it out the serial monitor
client.printf("hallo vom client");
// client.printf(counter);
Serial.println("Client Disconnected.");

// client code!!
const uint16_t port = 80;
const char * host = ""; // ip or dns

Serial.print("Connecting to ");

// Use WiFiClient class to create TCP connections
// WiFiClient client;

if (!client.connect(host, port)) {
Serial.println("Connection failed.");
Serial.println("Waiting 5 seconds before retrying...");

// This will send a request to the server
client.print("Send this data to the server n");
//read back one line from the server
String line = client.readStringUntil('\r');

Serial.println("Closing connection.");


Who is online

Users browsing this forum: No registered users and 19 guests