mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1003] wifiManager.setAPStaticIPConfig (question,set IP fixed address without gateway) #853
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#853
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
@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)
{
}
}
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";
\r\n";s +="
s +="<button onclick='myFunction()''>On\r\n";
\r\n";s +="
s +="\r\n";
s +="\r\n";
s += "
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) {
// 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();
}
Serial.println("invalid request");
client.stop();
return;
}
client.flush();
}
}`
@flavio-fernandes commented on GitHub (Feb 7, 2020):
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
@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.
@flavio-fernandes commented on GitHub (Feb 7, 2020):
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.
@flavio-fernandes commented on GitHub (Feb 7, 2020):
Moved it to https://github.com/tzapu/WiFiManager/issues/1006 Sorry folks!
@gauix4 commented on GitHub (Feb 8, 2020):
@tablatronix
no one has an idea ??
@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.
@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
@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.
@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
@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?
@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
@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
@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
@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