[GH-ISSUE #1003] wifiManager.setAPStaticIPConfig (question,set IP fixed address without gateway) #853

Open
opened 2026-02-28 01:27:21 +03:00 by kerem · 15 comments
Owner

Originally created by @gauix4 on GitHub (Feb 6, 2020).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1003

Hello everybody
first sorry if my english is not correct :)
I have a question I block on a problem
I would like my IP to be fixed, knowing that I do not know the gateway address, it changes depending on the box where we are connected, it can go from 192.168.1.1 and 192.168.1.254

I use the function wifiManager.setAPStaticIPConfig(int, int , int);
this indicates that I already know my gateway address which is not my case since we connect to several different gateways

my question is the following how to fix the IP without knowing the gateway knowing that it changes according to the box where we are connected

Thank you in advance for your answers ! :)
sorry for my english it is not correct
PS thanks to Google Translate lol

Originally created by @gauix4 on GitHub (Feb 6, 2020). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1003 Hello everybody first sorry if my english is not correct :) I have a question I block on a problem I would like my IP to be fixed, knowing that I do not know the gateway address, it changes depending on the box where we are connected, it can go from 192.168.1.1 and 192.168.1.254 I use the function wifiManager.setAPStaticIPConfig(int, int , int); this indicates that I already know my gateway address which is not my case since we connect to several different gateways my question is the following how to fix the IP without knowing the gateway knowing that it changes according to the box where we are connected Thank you in advance for your answers ! :) sorry for my english it is not correct PS thanks to Google Translate lol
Author
Owner

@gauix4 commented on GitHub (Feb 7, 2020):

Hello @flavio-fernandes
thank you very much for your answer but i didn't understand it
I already instaler ESP32 v1.0.4
esp8266 V2.6.3
not against i'm on an esp8266

`#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266httpUpdate.h>

const String Firmware_Version={"1.3"};

void FirmwareUpdate()//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
{
Serial.println("recherche de mise à jour");
HTTPClient http;
Serial.println("version du firmwer interne v"+Firmware_Version);
#define URL_firmware_Version "https://raw.git...... "
#define URL_firmware_Bin "https://raw.git......"

http.begin(URL_firmware_Version,"CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33");
delay(200);
int httpCode = http.GET();
delay(200);
String http_version;

if (httpCode == HTTP_CODE_OK)
{
http_version = http.getString();
Serial.println("version disponible v"+(http_version));
}
else
{
Serial.println("Erreur verification firmware:");
}
http.end();

if (httpCode == HTTP_CODE_OK)
{

if(http_version<(Firmware_Version))
{
 Serial.println("Version du firmware déjà à jour ok");
}

if(http_version.equals(Firmware_Version) )
{
 Serial.println("Version du firmware indentique");
}

if(http_version>(Firmware_Version))
{
 Serial.println("Nouvel mise à jour du firmware disponible");
 WiFiClient client;
 delay(1000);
 Serial.println("mise à jour du firmware");
 ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);


 t_httpUpdate_return ret = ESPhttpUpdate.update(URL_firmware_Bin,"","CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33");

  switch (ret)
  {
   case HTTP_UPDATE_FAILED:
    Serial.printf("Mise à jour échouer ! (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
    break;

   case HTTP_UPDATE_NO_UPDATES:
    Serial.println("Mise à jour non effectuée");
    break;

   case HTTP_UPDATE_OK:
    Serial.println("Mise à jour réussi !!!");
    break;
  }
}

}
}

unsigned long previousMillis=0 ;
unsigned long interval = 60000;
//int ok=0;

WiFiServer server(80);

const byte LED_PIN = 2;
const int RELAY = 0;

void led_off(){
//ok=0;
Serial.println("off");
digitalWrite(LED_PIN,HIGH);
digitalWrite(RELAY, HIGH);
}

void led_on(){
//ok=1;
//previousMillis = millis();
Serial.println("on");
digitalWrite(LED_PIN, LOW);
digitalWrite(RELAY, LOW);
}

String homepage() {
String s;

s = "HTTP/1.1 200 OK\r\n";
s +="Content-Type: text/html\r\n\r\n";
s +="\r\n";

s +="<html>\r\n";
s +="\r\n";

s += "\r\n";

s +="<button onclick='myFunction2()''>Off\r\n";
s +="

\r\n";

s +="<button onclick='myFunction()''>On\r\n";
s +="

\r\n";

s +="\r\n";

s +="\r\n";
s += "

\r\n";

s +="\r\n";
s += "\r\n";

s +="\r\n";

s +=" \r\n";
s +="

<font size=""50"">version du firmware interne v"+Firmware_Version+"

\r\n";
s +=" \r\n";

return s;
}

boolean matchcommand(String req,String command){
if (req.indexOf(command) != -1){
return true;
} else {
return false;
}
}

void setup() {

Serial.begin(115200);

pinMode(LED_PIN, OUTPUT);
pinMode(RELAY, OUTPUT);
digitalWrite(LED_PIN,HIGH);
digitalWrite(RELAY, HIGH);

WiFiManager wifiManager;
wifiManager.autoConnect("je suis la chaudière ");
//wifiManager.setAPStaticIPConfig(IPAddress(192,168,1,33));
//Serial.println(WiFi.localIP());
//FirmwareUpdate();

server.begin();
Serial.println("HTTP server started");

}

void loop() {

//if( ok==1 && millis() - previousMillis >= interval) {
if(millis() - previousMillis >= interval) {

//led_off();
FirmwareUpdate();
previousMillis = millis();
}

// Vérifie si client se connecte
WiFiClient client = server.available();
if (!client) {
return;
}
// Attends que le client envoie des données
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Affiche la page d'accueil 192.168.4.1
client.print(homepage());
//Serial.print(homepage());

// Lit la premiere ligne de la requete
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
if (matchcommand(req,"off")){
// requête 192.168.4.1/off --> éteins led
led_off();
}
else if (matchcommand(req,"on")){
// requête 192.168.4.1/on --> allume led
led_on();
}

  else {

Serial.println("invalid request");
client.stop();
return;
}
client.flush();

}

}`

<!-- gh-comment-id:583388504 --> @gauix4 commented on GitHub (Feb 7, 2020): Hello @flavio-fernandes thank you very much for your answer but i didn't understand it I already instaler ESP32 v1.0.4 esp8266 V2.6.3 not against i'm on an esp8266 `#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> #include <ESP8266httpUpdate.h> const String Firmware_Version={"1.3"}; void FirmwareUpdate()//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO { Serial.println("recherche de mise à jour"); HTTPClient http; Serial.println("version du firmwer interne v"+Firmware_Version); #define URL_firmware_Version "https://raw.git...... " #define URL_firmware_Bin "https://raw.git......" http.begin(URL_firmware_Version,"CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33"); delay(200); int httpCode = http.GET(); delay(200); String http_version; if (httpCode == HTTP_CODE_OK) { http_version = http.getString(); Serial.println("version disponible v"+(http_version)); } else { Serial.println("Erreur verification firmware:"); } http.end(); if (httpCode == HTTP_CODE_OK) { if(http_version<(Firmware_Version)) { Serial.println("Version du firmware déjà à jour ok"); } if(http_version.equals(Firmware_Version) ) { Serial.println("Version du firmware indentique"); } if(http_version>(Firmware_Version)) { Serial.println("Nouvel mise à jour du firmware disponible"); WiFiClient client; delay(1000); Serial.println("mise à jour du firmware"); ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW); t_httpUpdate_return ret = ESPhttpUpdate.update(URL_firmware_Bin,"","CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33"); switch (ret) { case HTTP_UPDATE_FAILED: Serial.printf("Mise à jour échouer ! (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: Serial.println("Mise à jour non effectuée"); break; case HTTP_UPDATE_OK: Serial.println("Mise à jour réussi !!!"); break; } } } } unsigned long previousMillis=0 ; unsigned long interval = 60000; //int ok=0; WiFiServer server(80); const byte LED_PIN = 2; const int RELAY = 0; void led_off(){ //ok=0; Serial.println("off"); digitalWrite(LED_PIN,HIGH); digitalWrite(RELAY, HIGH); } void led_on(){ //ok=1; //previousMillis = millis(); Serial.println("on"); digitalWrite(LED_PIN, LOW); digitalWrite(RELAY, LOW); } String homepage() { String s; s = "HTTP/1.1 200 OK\r\n"; s +="Content-Type: text/html\r\n\r\n"; s +="<!DOCTYPE HTML>\r\n"; s +="<html><body>\r\n"; s +="<table align='center' style='cursor: pointer;'><tr>\r\n"; s += "<style>\r\n"; s += "button {margin:auto;display:block;padding: 100px 200px;font-size: 100px;}\r\n"; s += "</style>\r\n"; s +="<button onclick='myFunction2()''>Off</button>\r\n"; s +="<h1 id='demo'></h1>\r\n"; s +="<button onclick='myFunction()''>On</button>\r\n"; s +="<h1 id='demo'></h1>\r\n"; s +="<style>\r\n"; s +="body {text-align: center;color: black;}\r\n"; s +="</style>\r\n"; s +="<script>\r\n"; s +="function myFunction(){document.getElementById('demo').innerHTML = '<font size=""100"">ok On !</font>'\r\n"; s +="on();}\r\n"; s +="</script>\r\n"; s += "</tr></table>\r\n"; s +="<script>\r\n"; s +="function myFunction2(){document.getElementById('demo').innerHTML = '<font size=""100"">ok Off !</font>'\r\n"; s +="off();}\r\n"; s +="</script>\r\n"; s += "</tr></table>\r\n"; s +="<script language='javascript' type='text/javascript'>\r\n"; s +="<!--\r\n"; s +="function on() { var xhr = new XMLHttpRequest(); xhr.open('GET', '/on', true); xhr.send();}\r\n"; s +="function off() { var xhr = new XMLHttpRequest(); xhr.open('GET', '/off', true); xhr.send();}\r\n"; s +="//-->\r\n"; s +="</script>\r\n"; s +="<body> \r\n"; s +="<p><font size=""50"">version du firmware interne v"+Firmware_Version+"</font></p> \r\n"; s +="</body> \r\n"; return s; } boolean matchcommand(String req,String command){ if (req.indexOf(command) != -1){ return true; } else { return false; } } void setup() { Serial.begin(115200); pinMode(LED_PIN, OUTPUT); pinMode(RELAY, OUTPUT); digitalWrite(LED_PIN,HIGH); digitalWrite(RELAY, HIGH); WiFiManager wifiManager; wifiManager.autoConnect("je suis la chaudière "); //wifiManager.setAPStaticIPConfig(IPAddress(192,168,1,33)); //Serial.println(WiFi.localIP()); //FirmwareUpdate(); server.begin(); Serial.println("HTTP server started"); } void loop() { //if( ok==1 && millis() - previousMillis >= interval) { if(millis() - previousMillis >= interval) { //led_off(); FirmwareUpdate(); previousMillis = millis(); } // Vérifie si client se connecte WiFiClient client = server.available(); if (!client) { return; } // Attends que le client envoie des données Serial.println("new client"); while(!client.available()){ delay(1); } // Affiche la page d'accueil 192.168.4.1 client.print(homepage()); //Serial.print(homepage()); // Lit la premiere ligne de la requete String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); if (matchcommand(req,"off")){ // requête 192.168.4.1/off --> éteins led led_off(); } else if (matchcommand(req,"on")){ // requête 192.168.4.1/on --> allume led led_on(); } else { Serial.println("invalid request"); client.stop(); return; } client.flush(); } }`
Author
Owner

@flavio-fernandes commented on GitHub (Feb 7, 2020):

Hello @flavio-fernandes
thank you very much for your answer but i didn't understand it
I already instaler ESP32 v1.0.4
esp8266 V2.6.3
not against i'm on an esp8266

Hello @gauix4 . Sorry for the confusion. My post was not much of a response, but rather
a confirmation that I too am hitting the issue you are describing here. So I thought of posting my findings here instead of opening a duplicate.

I have an ESP32, not an ESP8266 when hitting this. It is very possible that it does not matter which one is used. The code I'm using to reproduce this issue uses Preferences which I think does not exist in ESP8266. But, that is irrelevant to the issue here.

Hope this makes it a little clearer.

Best,

-- flaviof

`#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266httpUpdate.h>

const String Firmware_Version={"1.3"};

void FirmwareUpdate()//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
{
Serial.println("recherche de mise à jour");
HTTPClient http;
Serial.println("version du firmwer interne v"+Firmware_Version);
#define URL_firmware_Version "https://raw.git...... "
#define URL_firmware_Bin "https://raw.git......"

http.begin(URL_firmware_Version,"CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33");
delay(200);
int httpCode = http.GET();
delay(200);
String http_version;

if (httpCode == HTTP_CODE_OK)
{
http_version = http.getString();
Serial.println("version disponible v"+(http_version));
}
else
{
Serial.println("Erreur verification firmware:");
}
http.end();

if (httpCode == HTTP_CODE_OK)
{

if(http_version<(Firmware_Version))
{
 Serial.println("Version du firmware déjà à jour ok");
}

if(http_version.equals(Firmware_Version) )
{
 Serial.println("Version du firmware indentique");
}

if(http_version>(Firmware_Version))
{
 Serial.println("Nouvel mise à jour du firmware disponible");
 WiFiClient client;
 delay(1000);
 Serial.println("mise à jour du firmware");
 ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);


 t_httpUpdate_return ret = ESPhttpUpdate.update(URL_firmware_Bin,"","CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33");

  switch (ret)
  {
   case HTTP_UPDATE_FAILED:
    Serial.printf("Mise à jour échouer ! (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
    break;

   case HTTP_UPDATE_NO_UPDATES:
    Serial.println("Mise à jour non effectuée");
    break;

   case HTTP_UPDATE_OK:
    Serial.println("Mise à jour réussi !!!");
    break;
  }
}

}
}

unsigned long previousMillis=0 ;
unsigned long interval = 60000;
//int ok=0;

WiFiServer server(80);

const byte LED_PIN = 2;
const int RELAY = 0;

void led_off(){
//ok=0;
Serial.println("off");
digitalWrite(LED_PIN,HIGH);
digitalWrite(RELAY, HIGH);
}

void led_on(){
//ok=1;
//previousMillis = millis();
Serial.println("on");
digitalWrite(LED_PIN, LOW);
digitalWrite(RELAY, LOW);
}

String homepage() {
String s;

s = "HTTP/1.1 200 OK\r\n";
s +="Content-Type: text/html\r\n\r\n";
s +="\r\n";

s +="\r\n";
s +="
\r\n";

s += "\r\n";

s +="<button onclick='myFunction2()''>Off\r\n";
s +="
\r\n";

s +="<button onclick='myFunction()''>On\r\n";
s +="
\r\n";

s +="\r\n";

s +="\r\n";
s += "
\r\n";

s +="\r\n";
s += "\r\n";

s +="\r\n";

s +=" \r\n";
s +="

<font size=""50"">version du firmware interne v"+Firmware_Version+"
\r\n";
s +=" \r\n";

return s;
}

boolean matchcommand(String req,String command){
if (req.indexOf(command) != -1){
return true;
} else {
return false;
}
}

void setup() {

Serial.begin(115200);

pinMode(LED_PIN, OUTPUT);
pinMode(RELAY, OUTPUT);
digitalWrite(LED_PIN,HIGH);
digitalWrite(RELAY, HIGH);

WiFiManager wifiManager;
wifiManager.autoConnect("je suis la chaudière ");
//wifiManager.setAPStaticIPConfig(IPAddress(192,168,1,33));
//Serial.println(WiFi.localIP());
//FirmwareUpdate();

server.begin();
Serial.println("HTTP server started");

}

void loop() {

//if( ok==1 && millis() - previousMillis >= interval) {
if(millis() - previousMillis >= interval) {

//led_off();
FirmwareUpdate();
previousMillis = millis();
}

// Vérifie si client se connecte
WiFiClient client = server.available();
if (!client) {
return;
}
// Attends que le client envoie des données
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Affiche la page d'accueil 192.168.4.1
client.print(homepage());
//Serial.print(homepage());

// Lit la premiere ligne de la requete
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
if (matchcommand(req,"off")){
// requête 192.168.4.1/off --> éteins led
led_off();
}
else if (matchcommand(req,"on")){
// requête 192.168.4.1/on --> allume led
led_on();
}

  else {

Serial.println("invalid request");
client.stop();
return;
}
client.flush();

}

}`

<!-- gh-comment-id:583403577 --> @flavio-fernandes commented on GitHub (Feb 7, 2020): > Hello @flavio-fernandes > thank you very much for your answer but i didn't understand it > I already instaler ESP32 v1.0.4 > esp8266 V2.6.3 > not against i'm on an esp8266 > Hello @gauix4 . Sorry for the confusion. My post was not much of a response, but rather a confirmation that I too am hitting the issue you are describing here. So I thought of posting my findings here instead of opening a duplicate. I have an ESP32, not an ESP8266 when hitting this. It is very possible that it does not matter which one is used. The [code I'm using](https://github.com/flavio-fernandes/persistWifiSetting) to reproduce this issue uses [Preferences](https://github.com/espressif/arduino-esp32/blob/master/libraries/Preferences/src/Preferences.h) which I think does not exist in ESP8266. But, that is irrelevant to the issue here. Hope this makes it a little clearer. Best, -- flaviof > `#include <ESP8266WiFi.h> > #include <WiFiClient.h> > #include <DNSServer.h> > #include <ESP8266WebServer.h> > #include <WiFiManager.h> > #include <ESP8266httpUpdate.h> > > const String Firmware_Version={"1.3"}; > > void FirmwareUpdate()//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO > { > Serial.println("recherche de mise à jour"); > HTTPClient http; > Serial.println("version du firmwer interne v"+Firmware_Version); > #define URL_firmware_Version "https://raw.git...... " > #define URL_firmware_Bin "https://raw.git......" > > http.begin(URL_firmware_Version,"CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33"); > delay(200); > int httpCode = http.GET(); > delay(200); > String http_version; > > if (httpCode == HTTP_CODE_OK) > { > http_version = http.getString(); > Serial.println("version disponible v"+(http_version)); > } > else > { > Serial.println("Erreur verification firmware:"); > } > http.end(); > > if (httpCode == HTTP_CODE_OK) > { > > ``` > if(http_version<(Firmware_Version)) > { > Serial.println("Version du firmware déjà à jour ok"); > } > > if(http_version.equals(Firmware_Version) ) > { > Serial.println("Version du firmware indentique"); > } > > if(http_version>(Firmware_Version)) > { > Serial.println("Nouvel mise à jour du firmware disponible"); > WiFiClient client; > delay(1000); > Serial.println("mise à jour du firmware"); > ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW); > > > t_httpUpdate_return ret = ESPhttpUpdate.update(URL_firmware_Bin,"","CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33"); > > switch (ret) > { > case HTTP_UPDATE_FAILED: > Serial.printf("Mise à jour échouer ! (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); > break; > > case HTTP_UPDATE_NO_UPDATES: > Serial.println("Mise à jour non effectuée"); > break; > > case HTTP_UPDATE_OK: > Serial.println("Mise à jour réussi !!!"); > break; > } > } > ``` > > } > } > > unsigned long previousMillis=0 ; > unsigned long interval = 60000; > //int ok=0; > > WiFiServer server(80); > > const byte LED_PIN = 2; > const int RELAY = 0; > > void led_off(){ > //ok=0; > Serial.println("off"); > digitalWrite(LED_PIN,HIGH); > digitalWrite(RELAY, HIGH); > } > > void led_on(){ > //ok=1; > //previousMillis = millis(); > Serial.println("on"); > digitalWrite(LED_PIN, LOW); > digitalWrite(RELAY, LOW); > } > > String homepage() { > String s; > > s = "HTTP/1.1 200 OK\r\n"; > s +="Content-Type: text/html\r\n\r\n"; > s +="\r\n"; > > s +="\r\n"; > s +=" > \r\n"; > > s += "<style>\r\n"; > s += "button {margin:auto;display:block;padding: 100px 200px;font-size: 100px;}\r\n"; > s += "</style>\r\n"; > > s +="<button onclick='myFunction2()''>Off\r\n"; > s +=" > \r\n"; > > s +="<button onclick='myFunction()''>On\r\n"; > s +=" > \r\n"; > > s +="<style>\r\n"; > s +="body {text-align: center;color: black;}\r\n"; > s +="</style>\r\n"; > > s +="<script>\r\n"; > s +="function myFunction(){document.getElementById('demo').innerHTML = '<font size=""100"">ok On !'\r\n"; > s +="on();}\r\n"; > s +="</script>\r\n"; > s += " > \r\n"; > > s +="<script>\r\n"; > s +="function myFunction2(){document.getElementById('demo').innerHTML = '<font size=""100"">ok Off !'\r\n"; > s +="off();}\r\n"; > s +="</script>\r\n"; > s += "\r\n"; > > s +="<script language='javascript' type='text/javascript'>\r\n"; > s +="\r\n"; > s +="</script>\r\n"; > > s +=" \r\n"; > s +=" > > <font size=""50"">version du firmware interne v"+Firmware_Version+" > \r\n"; > s +=" \r\n"; > > return s; > } > > boolean matchcommand(String req,String command){ > if (req.indexOf(command) != -1){ > return true; > } else { > return false; > } > } > > void setup() { > > Serial.begin(115200); > > pinMode(LED_PIN, OUTPUT); > pinMode(RELAY, OUTPUT); > digitalWrite(LED_PIN,HIGH); > digitalWrite(RELAY, HIGH); > > WiFiManager wifiManager; > wifiManager.autoConnect("je suis la chaudière "); > //wifiManager.setAPStaticIPConfig(IPAddress(192,168,1,33)); > //Serial.println(WiFi.localIP()); > //FirmwareUpdate(); > > server.begin(); > Serial.println("HTTP server started"); > > } > > void loop() { > > //if( ok==1 && millis() - previousMillis >= interval) { > if(millis() - previousMillis >= interval) { > > ``` > //led_off(); > FirmwareUpdate(); > previousMillis = millis(); > } > ``` > > // Vérifie si client se connecte > WiFiClient client = server.available(); > if (!client) { > return; > } > // Attends que le client envoie des données > Serial.println("new client"); > while(!client.available()){ > delay(1); > } > > // Affiche la page d'accueil 192.168.4.1 > client.print(homepage()); > //Serial.print(homepage()); > > // Lit la premiere ligne de la requete > String req = client.readStringUntil('\r'); > Serial.println(req); > client.flush(); > if (matchcommand(req,"off")){ > // requête 192.168.4.1/off --> éteins led > led_off(); > } > else if (matchcommand(req,"on")){ > // requête 192.168.4.1/on --> allume led > led_on(); > } > > ``` > else { > ``` > > Serial.println("invalid request"); > client.stop(); > return; > } > client.flush(); > > } > > }`
Author
Owner

@tablatronix commented on GitHub (Feb 7, 2020):

@flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question.

<!-- gh-comment-id:583493016 --> @tablatronix commented on GitHub (Feb 7, 2020): @flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question.
Author
Owner

@flavio-fernandes commented on GitHub (Feb 7, 2020):

@flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question.

Oh boy, looks like I'm the one who does not know English. :( Very sorry for mixing the wires here. Going to open a new issue and try to clean this mess.

<!-- gh-comment-id:583507084 --> @flavio-fernandes commented on GitHub (Feb 7, 2020): > @flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question. Oh boy, looks like I'm the one who does not know English. :( Very sorry for mixing the wires here. Going to open a new issue and try to clean this mess.
Author
Owner

@flavio-fernandes commented on GitHub (Feb 7, 2020):

@flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question.

Oh boy, looks like I'm the one who does not know English. :( Very sorry for mixing the wires here. Going to open a new issue and try to clean this mess.

Moved it to https://github.com/tzapu/WiFiManager/issues/1006 Sorry folks!

<!-- gh-comment-id:583519335 --> @flavio-fernandes commented on GitHub (Feb 7, 2020): > > @flavio-fernandes create a new issue, you are posting an exception, this is not the same as this simple question. > > Oh boy, looks like I'm the one who does not know English. :( Very sorry for mixing the wires here. Going to open a new issue and try to clean this mess. Moved it to https://github.com/tzapu/WiFiManager/issues/1006 Sorry folks!
Author
Owner

@gauix4 commented on GitHub (Feb 8, 2020):

@tablatronix
no one has an idea ??

<!-- gh-comment-id:583718775 --> @gauix4 commented on GitHub (Feb 8, 2020): @tablatronix no one has an idea ??
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2020):

I mean what you are asking makes no sense. How can you connect to something you dont know.. do you want to connect via dhcp the first time then change to static afterwards? Then you can jusy use esp function to get gateway.

<!-- gh-comment-id:583751366 --> @tablatronix commented on GitHub (Feb 8, 2020): I mean what you are asking makes no sense. How can you connect to something you dont know.. do you want to connect via dhcp the first time then change to static afterwards? Then you can jusy use esp function to get gateway.
Author
Owner

@gauix4 commented on GitHub (Feb 8, 2020):

@tablatronix
if that is useful because i don't know this ip address
my little box is made to go to several houses so the address will not be the same
in my house I know it's 192.168.1.254 but in the other houses I don't know it's not necessarily the same
and my little box communicates with another one so if the IP address is not identical they cannot communicate

<!-- gh-comment-id:583754686 --> @gauix4 commented on GitHub (Feb 8, 2020): @tablatronix if that is useful because i don't know this ip address my little box is made to go to several houses so the address will not be the same in my house I know it's 192.168.1.254 but in the other houses I don't know it's not necessarily the same and my little box communicates with another one so if the IP address is not identical they cannot communicate
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2020):

I mean if you are connecting to different networks you cannot just use any ip address, it has to be on the same subnet as the gateway. You have to use dhcp.

Maybe I misunderstood, you want the AP to be static ?
Then the gateway is whatever you want it to be, its your network and only exists on the esp

you keep saying connect to , but in ap mode you connect to the esp .. in sta mode the esp connects to a network. So I am confused as to what you are doing.

<!-- gh-comment-id:583755021 --> @tablatronix commented on GitHub (Feb 8, 2020): I mean if you are connecting to different networks you cannot just use any ip address, it has to be on the same subnet as the gateway. You have to use dhcp. Maybe I misunderstood, you want the AP to be static ? Then the gateway is whatever you want it to be, its your network and only exists on the esp you keep saying connect to , but in ap mode you connect to the esp .. in sta mode the esp connects to a network. So I am confused as to what you are doing.
Author
Owner

@gauix4 commented on GitHub (Feb 8, 2020):

@tablatronix
no actually when i use wifimanager i can't assign a fixed IP address for my server
let me explain
I use wifimanager to create an access point so that the person goes on it and connects to this internet box
until then everything is OK
I also do the same manipulation with the second box
now they are both connected to the same internet box
the problem is that boxing assign an IP address and in my code I can not know in advance so impossible to communicate with the two boxes
so I have to fix their IP address so that it can communicate

IPAddress server(192,168,1,80);
serveur.begin();

i tried putting this in a code it works fine but when i call wifi manager it doesn't work anymore

<!-- gh-comment-id:583757766 --> @gauix4 commented on GitHub (Feb 8, 2020): @tablatronix no actually when i use wifimanager i can't assign a fixed IP address for my server let me explain I use wifimanager to create an access point so that the person goes on it and connects to this internet box until then everything is OK I also do the same manipulation with the second box now they are both connected to the same internet box the problem is that boxing assign an IP address and in my code I can not know in advance so impossible to communicate with the two boxes so I have to fix their IP address so that it can communicate IPAddress server(192,168,1,80); serveur.begin(); i tried putting this in a code it works fine but when i call wifi manager it doesn't work anymore
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2020):

They should be able to communicate on the same network as dhcp will give them the gateway, thats how it works.

When you say box you mean 2 esp and 1 router?

<!-- gh-comment-id:583760737 --> @tablatronix commented on GitHub (Feb 8, 2020): They should be able to communicate on the same network as dhcp will give them the gateway, thats how it works. When you say box you mean 2 esp and 1 router?
Author
Owner

@gauix4 commented on GitHub (Feb 8, 2020):

@tablatronix
yes I understood correctly but you must know the IP address of each ESP connect
and when i use wifimanager i can't fix the ip after connecting to the paserel
therefore the gateway assigns an IP address to each ESP which does not correspond to this indicate in the program so it does not communicate together

<!-- gh-comment-id:583760810 --> @gauix4 commented on GitHub (Feb 8, 2020): @tablatronix yes I understood correctly but you must know the IP address of each ESP connect and when i use wifimanager i can't fix the ip after connecting to the paserel therefore the gateway assigns an IP address to each ESP which does not correspond to this indicate in the program so it does not communicate together
Author
Owner

@gauix4 commented on GitHub (Feb 8, 2020):

to fix IP address I would need to know the gateway address
except that I don't know her

<!-- gh-comment-id:583764012 --> @gauix4 commented on GitHub (Feb 8, 2020): to fix IP address I would need to know the gateway address except that I don't know her
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2020):

You could use mdns and host names also

I would after connecting, get the gateway and then set the static ip after connected

WiFi.gatewayIP().toString()

Of course other networks might not be 192 subnet there are others

<!-- gh-comment-id:583784698 --> @tablatronix commented on GitHub (Feb 8, 2020): You could use mdns and host names also I would after connecting, get the gateway and then set the static ip after connected `WiFi.gatewayIP().toString()` Of course other networks might not be 192 subnet there are others
Author
Owner

@gauix4 commented on GitHub (Feb 9, 2020):

this is exactly what I have to do but suddenly I don't really see how to do it I still have trouble with all the subfolders .h .ccp

<!-- gh-comment-id:583792382 --> @gauix4 commented on GitHub (Feb 9, 2020): this is exactly what I have to do but suddenly I don't really see how to do it I still have trouble with all the subfolders .h .ccp
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#853
No description provided.