Skip to content

Commit

Permalink
Merge branch 'xyzroe:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
leroyloren authored May 28, 2024
2 parents a19574f + 70fddbd commit 410a722
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 12 deletions.
62 changes: 60 additions & 2 deletions src/etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,67 @@ void nmDeactivate()
setLedsDisable();
}

IPAddress savedWifiDNS;
IPAddress savedEthDNS;

void checkDNS(bool setup = false)
{
const char *wifiKey = "WiFi";
const char *ethKey = "ETH";

if (networkCfg.wifiEnable)
{
IPAddress currentWifiDNS = WiFi.dnsIP();
if (setup)
{
savedWifiDNS = currentWifiDNS;
LOGI("Saved %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str());
}
else
{
if (currentWifiDNS != savedWifiDNS)
{
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), savedWifiDNS);
LOGI("Updated %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str());
}
else
{
//LOGD("No update on %s DNS", wifiKey);
}
}
}

if (networkCfg.ethEnable)
{
IPAddress currentEthDNS = ETH.dnsIP();
if (setup)
{
savedEthDNS = currentEthDNS;
LOGI("Saved %s DNS - %s", ethKey, savedEthDNS.toString().c_str());
}
else
{
if (currentEthDNS != savedEthDNS)
{
ETH.config(ETH.localIP(), ETH.gatewayIP(), ETH.subnetMask(), savedEthDNS);
LOGI("Updated %s DNS - %s", ethKey, savedEthDNS.toString().c_str());
}
else
{
//LOGD("No update on %s DNS", ethKey);
}
}
}
}

void reCheckDNS()
{
checkDNS();
}

void setupCron()
{
// Cron.create(const_cast<char *>("0 */1 * * * *"), cronTest, false);
Cron.create(const_cast<char *>("0 */1 * * * *"), reCheckDNS, false);

Cron.create(const_cast<char *>("0 0 */1 * * *"), checkEspUpdateAvail, false);

Expand Down Expand Up @@ -482,7 +540,7 @@ char *convertTimeToCron(const String &time)
static char formattedTime[16];
int hours, minutes;

char timeArray[6];
char timeArray[6];
time.toCharArray(timeArray, sizeof(timeArray));

sscanf(timeArray, "%d:%d", &hours, &minutes);
Expand Down
1 change: 1 addition & 0 deletions src/etc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void factoryReset();
void setLedsDisable(bool all = false);
void cronTest();
void nmActivate();
void checkDNS(bool setup);
void setupCron();

void setClock(void *pvParameters);
Expand Down
12 changes: 8 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,16 @@ void NetworkEvent(WiFiEvent_t event)
break;
case ARDUINO_EVENT_ETH_GOT_IP: // 22: // SYSTEM_EVENT_ETH_GOT_IP:
startServers();
LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, %dMbps", ethKey,
LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, DNS: %s, %dMbps", ethKey,
ETH.macAddress().c_str(),
ETH.localIP().toString().c_str(),
ETH.subnetMask().toString().c_str(),
ETH.gatewayIP().toString().c_str(),
ETH.dnsIP().toString().c_str(),
ETH.linkSpeed());

vars.connectedEther = true;
checkDNS(true);
// ConfigSettings.disconnectEthTime = 0;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED: // 21: //SYSTEM_EVENT_ETH_DISCONNECTED:
Expand All @@ -268,11 +270,13 @@ void NetworkEvent(WiFiEvent_t event)
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP: // SYSTEM_EVENT_STA_GOT_IP:
startServers();
LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s", wifiKey,
LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, DNS: %s", wifiKey,
WiFi.macAddress().c_str(),
WiFi.localIP().toString().c_str(),
WiFi.subnetMask().toString().c_str(),
WiFi.gatewayIP().toString().c_str());
WiFi.gatewayIP().toString().c_str(),
WiFi.dnsIP().toString().c_str());
checkDNS(true);
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: // SYSTEM_EVENT_STA_DISCONNECTED:
LOGD("%s STA DISCONNECTED", wifiKey);
Expand Down Expand Up @@ -316,7 +320,7 @@ void startAP(const bool start)
WiFi.disconnect();
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(vars.deviceId); //, WIFIPASS);

// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
Expand Down
26 changes: 20 additions & 6 deletions src/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,17 @@ void handleEspUpdateUpload()
}
}

void handleEvents() {
if (is_authenticated()) {
if (eventsClient) {
void handleEvents()
{
if (is_authenticated())
{
if (eventsClient)
{
eventsClient.stop();
}
eventsClient = serverWeb.client();
if (eventsClient) {
if (eventsClient)
{
eventsClient.println("HTTP/1.1 200 OK");
eventsClient.println("Content-Type: text/event-stream;");
eventsClient.println("Connection: close");
Expand All @@ -369,8 +373,10 @@ void handleEvents() {
}
}

void sendEvent(const char *event, const uint8_t evsz, const String data) {
if (eventsClient) {
void sendEvent(const char *event, const uint8_t evsz, const String data)
{
if (eventsClient)
{
char evnmArr[10 + evsz];
snprintf(evnmArr, sizeof(evnmArr), "event: %s\n", event);
eventsClient.print(evnmArr);
Expand Down Expand Up @@ -1156,6 +1162,14 @@ void handleSerial()
{
doc["115200"] = checked;
}
else if (systemCfg.serialSpeed == 230400)
{
doc["230400"] = checked;
}
else if (systemCfg.serialSpeed == 460800)
{
doc["460800"] = checked;
}
else
{
doc["115200"] = checked;
Expand Down
2 changes: 2 additions & 0 deletions src/websrc/html/PAGE_ZIGBEE.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<option data-r2v="38400" value='38400'>38400 bauds</option>
<option data-r2v="57600" value='57600'>57600 bauds</option>
<option data-r2v="115200" value='115200'>115200 bauds</option>
<option data-r2v="230400" value='230400'>230400 bauds</option>
<option data-r2v="460800" value='460800'>460800 bauds</option>
</select>
</div>
</div>
Expand Down

0 comments on commit 410a722

Please sign in to comment.