Hello everyone.
Due to my limited knowledge of networks and Wi-Fi, I am unable to identify and resolve
a problem I am having with a project.
Since the project code is very large, I have made a summary that reproduces the problem.
The project uses an ESP8266.
There is no need to post a schematic, since I am only using the ESP8266 without connecting
anything to it, other than the USB cable.
In addition to other libraries, I am using "ESPAsyncWiFiManager.h" in the code.
The link to it and the others I use are in the code.
I will also post the printout, since it makes it easier to visualize the problem.
To provide the IP/GW/SN data, I use a file loaded into SPIFFS, named "config.json"
as used in examples of the "ESPAsyncWiFiManager.h" library.
The problem is the ESP8266 IP that appears and I don't know where it comes from and
how to change or delete it.
In the printout I will mark it with <<<<<------
I appreciate any help and teaching.
The printout:
Static_gateway 192.168.1.254
Static_ip 192.168.1.52 <<<<<<--------------------Correct
Ping 0
Local_IP 192.168.1.37 <<<<<<-------------------- ?????????
Router_gateway192.168.1.254
*WM:
*WM: AutoConnect Try No.:
*WM: 0
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet/DNS
*WM: 192.168.1.52 <<<<<<--------------------Correct
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.1.52 <<<<<<--------------------Correct
Servidor iniciado com o IP "192.168.1.52" <<<<<<--------------------Correct
The code:
// Arduino IDE // Ver 1.8.9
#include <ESP8266WiFi.h> // Ver 2.7.4
#include <ESP8266Ping.h> // Ver 1.1.0 https://github.com/dancol90/ESP8266Ping
#include <ESPAsyncWiFiManager.h> // Ver 0.23 https://github.com/tzapu/WiFiManager
#include <ESPAsyncWebServer.h> // Ver 1.2.3 https://github.com/me-no-dev/ESPAsyncWebServer
#include <FS.h> // Ver 2.7.4 This needs to be first, or it all crashes and burns...
#include <ArduinoJson.h> // Ver 5.13.5 https://github.com/bblanchon/ArduinoJson
AsyncWebServer server(80);
DNSServer dns;
char static_ip[16] = "10.0.0.1"; // Default basic static IP
char static_gw[16] = "10.0.0.254";
char static_sn[16] = "255.255.255.000";
//------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
Serial.println(" ");
SPIFFS.begin();
if (SPIFFS.begin()) {
//SPIFFS.format(); // Format SPIFFS clear files
if (SPIFFS.exists("/config.json")) { // If file exists, reading and loading
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
size_t size = configFile.size();
std::unique_ptr<char[]> buf(new char[size]); // Allocate a buffer to store contents of the file.
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
if (json.success()) {
strcpy(static_ip, json["ip"]);
strcpy(static_gw, json["gateway"]);
strcpy(static_sn, json["subnet"]);
Serial.print("Static_gateway "); Serial.println(static_gw);
Serial.print("Static_ip "); Serial.println(static_ip);
Serial.print("Ping ");
Serial.println(Ping.ping("192.168.1.25")); // Any IP, only for test of fuction
}
else {
Serial.println("failed to load json config");
}
}
}
}
else {
Serial.println("failed to mount FS");
}
Serial.print("Local_IP ");
Serial.println(WiFi.localIP());
Serial.print("Router_gateway");
Serial.println(WiFi.gatewayIP());
AsyncWiFiManager wifiManager(&server, &dns);
IPAddress _ip, _gw, _sn; // Set static ip
_ip.fromString(static_ip);
_gw.fromString(static_gw);
_sn.fromString(static_sn);
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn );
wifiManager.setMinimumSignalQuality(); // Set minimu quality of signal so it ignores AP's under that quality //defaults to 8%
if (!wifiManager.autoConnect("AP_Configure", "password")) {
Serial.println("failed to connect and hit timeout");
}
Serial.print("Servidor iniciado com o IP \"");
Serial.print(WiFi.localIP());
Serial.println("\"");
}
//------------------------------------------------------------------------------------
void loop() {
}
The config.json file.
{"ip":"192.168.1.52","gateway":"192.168.1.254","subnet":"255.255.255.0"}