mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1644] DHCP Not Working #1398
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#1398
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 @MYTECHREVIEW on GitHub (Aug 8, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1644
Hi everyone, I got the following issue with the DHCP not assigning the correct IP address. The wifi portal opens fine, I select the AP and when it connects is assigning a 192.168.2.3 address instead of grabbing the correct 10.10.0.* address that I use in my network. I'm no expert in this matter and programing skills are a bit beginner. Below is the code that I'm working probably is something that I'm missing. Thanks
// https://github.com/tzapu/WiFiManager
#include <WiFiManager.h>
#include <ESPmDNS.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
bool set_time_flag = false;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
// Set web server port number to 80
WiFiServer server(80);
// Variable to store the HTTP request
String header;
// Auxiliar variables to store the current output state
String init_clock_done = "no";
String output4State = "off";
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
//variabls for blinking an LED with Millis
const int led = 2; // ESP32 Pin to which onboard LED is connected
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 5000; // interval at which to blink (milliseconds)
int ledState = LOW; // ledState used to set the LED
///////////////////////////////////////////////////////////////////////
/////////////// - --- clock code ---------------///////////////////////
///////////////////////////////////////////////////////////////////////
// Please tune the following value if the clock gains or loses.
// Theoretically, standard of this value is 60000.
#define MILLIS_PER_MIN 60000 // milliseconds per a minute
// Motor and clock parameters
// 4096 * 90 / 12 = 30720
#define STEPS_PER_ROTATION 30720 // steps for a full turn of minute rotor
// wait for a single step of stepper
int delaytime = 2;
// ports used to control the stepper motor
// if your motor rotate to the opposite direction,
//int port[4] = {2, 3, 4, 5}; arduino code
int port[4] = { 12, 13, 4, 5 };
///////////////////////////////////////////////////////////////////////
/////////////// - --- clock code ---------------///////////////////////
///////////////////////////////////////////////////////////////////////
// sequence of stepper motor control
int seq[8][4] = {
{ LOW, HIGH, HIGH, LOW },
{ LOW, LOW, HIGH, LOW },
{ LOW, LOW, HIGH, HIGH },
{ LOW, LOW, LOW, HIGH },
{ HIGH, LOW, LOW, HIGH },
{ HIGH, LOW, LOW, LOW },
{ HIGH, HIGH, LOW, LOW },
{ LOW, HIGH, LOW, LOW }
};
void rotate(int step) {
static int phase = 0;
int i, j;
int delta = (step > 0) ? 1 : 7;
int dt = 20;
step = (step > 0) ? step : -step;
for (j = 0; j < step; j++) {
phase = (phase + delta) % 8;
for (i = 0; i < 4; i++) {
digitalWrite(port[i], seq[phase][i]);
}
delay(dt);
if (dt > delaytime) dt--;
}
// power cut
for (i = 0; i < 4; i++) {
digitalWrite(port[i], LOW);
}
}
void setup() {
pinMode(led, OUTPUT);
pinMode(port[0], OUTPUT);
pinMode(port[1], OUTPUT);
pinMode(port[2], OUTPUT);
pinMode(port[3], OUTPUT);
Serial.begin(115200);
Serial.println("Booting");
WiFiManager wifiManager;
wifiManager.autoConnect("Hollow_Clock");
//wifiManager.resetSettings();
ArduinoOTA.onStart( {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
});
ArduinoOTA.onEnd( {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (!MDNS.begin("wifi-clock")) { // Start the mDNS responder for esp8266.local
Serial.println("Error setting up MDNS responder!");
}
// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(-18000);
server.begin();
/////////////// clock code //////////////////////
rotate(-20); // for approach run
rotate(20); // approach run without heavy load
//rotate(STEPS_PER_ROTATION / 60);
/////////////// clock code //////////////////////
}
void increment_time(int val) {
long pos;
pos = (STEPS_PER_ROTATION * val) / 60;
rotate(-20); // for approach run
rotate(20); // approach run without heavy load
rotate(pos);
}
void decrement_time(int val) {
long pos;
pos = (STEPS_PER_ROTATION * val) / 60;
rotate(-20); // for approach run
rotate(20); // approach run without heavy load
rotate(-pos);
}
void update_ntp_time() {
long calc_minutes = 0;
timeClient.update();
int currentHour = timeClient.getHours();
Serial.print("Hour: ");
Serial.println(currentHour);
int currentMinute = timeClient.getMinutes();
//Serial.print("Minutes: ");
//Serial.println(currentMinute);
if (currentHour >= 12) {
currentHour = currentHour - 12;
}
if (currentHour <= 6) {
calc_minutes = (currentHour * 60) + currentMinute;
//calc_minutes = calc_minutes + (calc_minutes/60);
increment_time(calc_minutes);
}
if (currentHour > 6) {
currentHour = currentHour - 6;
calc_minutes = (currentHour * 60) + currentMinute;
calc_minutes = 360 - calc_minutes;
//calc_minutes = calc_minutes - (calc_minutes/60);
decrement_time(calc_minutes);
}
}
void loop() {
ArduinoOTA.handle();
WiFiClient client = server.available(); // Listen for incoming clients
if ((set_time_flag) && (init_clock_done == "no")) {
update_ntp_time();
init_clock_done = "yes";
set_time_flag = false;
}
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
currentTime = millis();
previousTime = currentTime;
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
}
//loop to blink without delay
unsigned long currentMillis = millis();
// if (currentMillis - previousMillis >= interval) {
// digitalWrite(led, ledState);
// }
static long prev_min = 0, prev_pos = 0;
long min;
static long pos;
min = millis() / MILLIS_PER_MIN;
if (prev_min == min) {
return;
}
prev_min = min;
pos = (STEPS_PER_ROTATION * min) / 60;
rotate(-20); // for approach run
rotate(20); // approach run without heavy load
if (pos - prev_pos > 0) {
rotate(pos - prev_pos);
}
prev_pos = pos;
}
@MYTECHREVIEW commented on GitHub (Aug 9, 2023):
Got it resolved.