[ad_1]
I hope to search out some assist right here.
Thanks prematurely already for some assist.
I’ve a esp32 board as a Shopper with a static ip-address.
The Shopper with the static ip-address connects to a second esp32 that’s performing as a Entry Level. The connection is established and the Entry Level acknowledge the brand new related system. The issue is, with the Shopper having the static ip-address the Entry Level shows the Shopper ip as 0.0.0.0. If the Shopper because the ip-address not set as static, the Entry Level shows the proper ip-address.
Follows the code for the Shopper:
#embody <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.start(115200);
WiFi.mode(WIFI_STA);
// Configure the static IP handle
WiFi.config(ip, gateway, subnet);
WiFi.start(ssid, password);
whereas (WiFi.standing() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Related to WiFi community");
Serial.println("IP handle: ");
Serial.println(WiFi.localIP());
}
void loop() {
static lengthy general_t1 = 0;
if (millis() - general_t1 > 2000)
{
Serial.println("IP handle: ");
Serial.println(WiFi.localIP());
general_t1 = millis();
}
}
Follows the code for the Entry Level:
#embody <Arduino.h>
#embody <WiFi.h>
#embody "esp_wifi.h"
#embody <SPI.h>
#embody <Wire.h>
#embody <Adafruit_GFX.h>
#embody <Adafruit_SSD1306.h>
#outline SCREEN_WIDTH 128
#outline SCREEN_HEIGHT 64
#outline OLED_RESET -1
Adafruit_SSD1306 show(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char *ssid = "ESP32-AP"; // SSID Identify
const char *password = "123456789"; // SSID Password - Set to NULL to have an open AP
const int channel = 10; // WiFi Channel quantity between 1 and 13
const bool hide_SSID = false; // To disable SSID broadcast -> SSID won't seem in a fundamental WiFi scan
const int max_connection = 5; // Most simultaneous related purchasers 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 Machine related";
}
else
{
for (int i = 0; i < adapter_sta_list.num; i++)
{
tcpip_adapter_sta_info_t station = adapter_sta_list.sta[i];
deviceInfo += "Machine " + String(i) + " = ";
deviceInfo += IPAddress((&station.ip)->addr).toString();
deviceInfo += "n";
}
}
// Show collected system data
show.clearDisplay();
show.setTextSize(1);
show.setTextColor(WHITE);
show.setCursor(0, 0);
show.println("AP IP: " + WiFi.softAPIP().toString());
show.setCursor(0, 20);
show.println(deviceInfo);
show.show();
show.clearDisplay();
}
//***********************************************************************************************
//** void setup()
//***********************************************************************************************
void setup()
{
Serial.start(115200);
if (!show.start(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
show.clearDisplay();
show.setTextSize(2);
show.setTextColor(SSD1306_WHITE);
show.setCursor(25, 10);
show.println(F("ESP-32"));
show.setCursor(25, 30);
show.println(F("Router"));
show.show();
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);
}
[ad_2]