I hope to find some help here. Thanks in advance already for some help.
I have a esp32an ESP32 board as a Clientclient with a static ip-addressIP address. The Client The client with the static ip-addressIP address connects to a second esp32ESP32 that is acting as a Access Pointan access point. The connection is established and the Access Point recognizeaccess point recognizes the new connected device.
The problem is, with the Clientclient having thea static ip-addressIP address the Access Pointaccess point displays the Client ipclient IP as 0.0.0.0. If the Client as the ip-addressclient does not have the IP address set as static, the Access Pointaccess point displays the correct ip-addressIP address.
Follows theThe code for the Clientclient:
#include <WiFi.h>
const char* ssid = "ESP32-AP";
const char* password = "123456789";
IPAddress ip(192, 168, 0, 101);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// Configure the static IP address
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi network");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
static long general_t1 = 0;
if (millis() - general_t1 > 2000)
{
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
general_t1 = millis();
}
}
#include <WiFi.h>
const char* ssid = "ESP32-AP";
const char* password = "123456789";
IPAddress ip(192, 168, 0, 101);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// Configure the static IP address
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi network");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
static long general_t1 = 0;
if (millis() - general_t1 > 2000) {
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
general_t1 = millis();
}
}
Follows theThe code for the Access Pointaccess point:
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char *ssid = "ESP32-AP"; // SSID Name
const char *password = "123456789"; // SSID Password - Set to NULL to have an open AP
const int channel = 10; // WiFi Channel number between 1 and 13
const bool hide_SSID = false; // To disable SSID broadcast -> SSID will not appear in a basic WiFi scan
const int max_connection = 5; // Maximum simultaneous connected clients on the AP
IPAddress local_ip(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
//*** void display_connected_devices() **************************************************************
void display_connected_devices()
{
wifi_sta_list_t wifi_sta_list;
tcpip_adapter_sta_list_t adapter_sta_list;
esp_wifi_ap_get_sta_list(&wifi_sta_list);
tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list);
String deviceInfo = "";
if (adapter_sta_list.num == 0)
{
deviceInfo = "No Device connected";
}
else
{
for (int i = 0; i < adapter_sta_list.num; i++)
{
tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i];
deviceInfo += "Device " + String(i) + " = ";
deviceInfo += IPAddress((&station.ip)->addr).toString();
deviceInfo += "\n";
}
}
// Display accumulated device information
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("AP IP: " + WiFi.softAPIP().toString());
display.setCursor(0, 20);
display.println(deviceInfo);
display.display();
display.clearDisplay();
}
//***********************************************************************************************
//** void setup()
//***********************************************************************************************
void setup()
{
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(25, 10);
display.println(F("ESP-32"));
display.setCursor(25, 30);
display.println(F("Router"));
display.display();
delay(2000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(local_ip, gateway, subnet);
WiFi.softAP(ssid, password, channel, hide_SSID, max_connection);
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP());
}
//***********************************************************************************************
//** void loop()
//***********************************************************************************************
void loop()
{
display_connected_devices();
delay(5000);
}
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char *ssid = "ESP32-AP"; // SSID Name
const char *password = "123456789"; // SSID Password - Set to NULL to have an open AP
const int channel = 10; // WiFi Channel number between 1 and 13
const bool hide_SSID = false; // To disable SSID broadcast -> SSID will not appear in a basic WiFi scan
const int max_connection = 5; // Maximum simultaneous connected clients on the AP
IPAddress local_ip(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
//*** void display_connected_devices() **************************************************************
void display_connected_devices() {
wifi_sta_list_t wifi_sta_list;
tcpip_adapter_sta_list_t adapter_sta_list;
esp_wifi_ap_get_sta_list(&wifi_sta_list);
tcpip_adapter_get_sta_list(&wifi_sta_list, &adapter_sta_list);
String deviceInfo = "";
if (adapter_sta_list.num == 0) {
deviceInfo = "No Device connected";
}
else {
for (int i = 0; i < adapter_sta_list.num; i++) {
tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i];
deviceInfo += "Device " + String(i) + " = ";
deviceInfo += IPAddress((&station.ip)->addr).toString();
deviceInfo += "\n";
}
}
// Display accumulated device information
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("AP IP: " + WiFi.softAPIP().toString());
display.setCursor(0, 20);
display.println(deviceInfo);
display.display();
display.clearDisplay();
}
//***********************************************************************************************
//** void setup()
//***********************************************************************************************
void setup() {
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(25, 10);
display.println(F("ESP-32"));
display.setCursor(25, 30);
display.println(F("Router"));
display.display();
delay(2000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(local_ip, gateway, subnet);
WiFi.softAP(ssid, password, channel, hide_SSID, max_connection);
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP());
}
//***********************************************************************************************
//** void loop()
//***********************************************************************************************
void loop() {
display_connected_devices();
delay(5000);
}