Fix static IP for ETH connections #268

This commit is contained in:
Robert Strouse 2024-02-12 17:36:57 -08:00
parent bf8da394d5
commit bbefe7fe6d
5 changed files with 19 additions and 17 deletions

View file

@ -54,7 +54,7 @@ body:
- type: textarea - type: textarea
id: reprod id: reprod
attributes: attributes:
label: "How to reproduce it (setp by step)" label: "How to reproduce it (step by step)"
description: Please enter an explicit description of your issue description: Please enter an explicit description of your issue
value: | value: |
1. Go to... 1. Go to...

View file

@ -236,7 +236,6 @@ bool Network::connectWired() {
Serial.print("Set hostname to:"); Serial.print("Set hostname to:");
Serial.println(ETH.getHostname()); Serial.println(ETH.getHostname());
if(!ETH.begin(settings.Ethernet.phyAddress, settings.Ethernet.PWRPin, settings.Ethernet.MDCPin, settings.Ethernet.MDIOPin, settings.Ethernet.phyType, settings.Ethernet.CLKMode)) { if(!ETH.begin(settings.Ethernet.phyAddress, settings.Ethernet.PWRPin, settings.Ethernet.MDCPin, settings.Ethernet.MDIOPin, settings.Ethernet.phyType, settings.Ethernet.CLKMode)) {
Serial.println("Ethernet Begin failed"); Serial.println("Ethernet Begin failed");
if(settings.connType == conn_types::ethernetpref) { if(settings.connType == conn_types::ethernetpref) {
this->wifiFallback = true; this->wifiFallback = true;
@ -246,9 +245,10 @@ bool Network::connectWired() {
} }
else { else {
if(!settings.IP.dhcp) { if(!settings.IP.dhcp) {
if(!ETH.config(settings.IP.ip, settings.IP.gateway, settings.IP.subnet, settings.IP.dns1, settings.IP.dns2)) if(!ETH.config(settings.IP.ip, settings.IP.gateway, settings.IP.subnet, settings.IP.dns1, settings.IP.dns2)) {
Serial.println("Unable to configure static IP address...."); Serial.println("Unable to configure static IP address....");
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
}
} }
else else
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
@ -467,7 +467,9 @@ bool Network::openSoftAP() {
// If no clients have connected in 3 minutes from starting this server reboot this pig. This will // If no clients have connected in 3 minutes from starting this server reboot this pig. This will
// force a reboot cycle until we have some response. That is unless the SSID has been cleared. // force a reboot cycle until we have some response. That is unless the SSID has been cleared.
if(clients == 0 && strlen(settings.WIFI.ssid) > 0 && millis() - startTime > 3 * 60000) { if(clients == 0 &&
(strlen(settings.WIFI.ssid) > 0 || settings.connType == conn_types::ethernet || settings.connType == conn_types::ethernetpref) &&
millis() - startTime > 3 * 60000) {
Serial.println(); Serial.println();
Serial.println("Stopping AP Mode"); Serial.println("Stopping AP Mode");
WiFi.softAPdisconnect(true); WiFi.softAPdisconnect(true);

View file

@ -3193,19 +3193,16 @@ void SomfyShadeController::emitState(uint8_t num) {
} }
void SomfyShadeController::publish() { void SomfyShadeController::publish() {
this->updateGroupFlags(); this->updateGroupFlags();
StaticJsonDocument<128> docShades; char arrIds[128] = "[";
StaticJsonDocument<128> docGroups;
JsonArray arrShades = docShades.to<JsonArray>();
JsonArray arrGroups = docGroups.to<JsonArray>();
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) { for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) {
SomfyShade *shade = &this->shades[i]; SomfyShade *shade = &this->shades[i];
if(shade->getShadeId() == 255) { if(shade->getShadeId() == 255) continue;
continue; if(strlen(arrIds) > 1) strcat(arrIds, ",");
} itoa(shade->getShadeId(), &arrIds[strlen(arrIds)], 10);
arrShades.add(shade->getShadeId());
shade->publish(); shade->publish();
} }
mqtt.publish("shades", arrShades, true); strcat(arrIds, "]");
mqtt.publish("shades", arrIds, true);
for(uint8_t i = 1; i <= SOMFY_MAX_SHADES; i++) { for(uint8_t i = 1; i <= SOMFY_MAX_SHADES; i++) {
SomfyShade *shade = this->getShadeById(i); SomfyShade *shade = this->getShadeById(i);
if(shade) continue; if(shade) continue;
@ -3213,18 +3210,21 @@ void SomfyShadeController::publish() {
SomfyShade::unpublish(i); SomfyShade::unpublish(i);
} }
} }
strcpy(arrIds, "[");
for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) { for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) {
SomfyGroup *group = &this->groups[i]; SomfyGroup *group = &this->groups[i];
if(group->getGroupId() == 255) continue; if(group->getGroupId() == 255) continue;
arrGroups.add(group->getGroupId()); if(strlen(arrIds) > 1) strcat(arrIds, ",");
itoa(group->getGroupId(), &arrIds[strlen(arrIds)], 10);
group->publish(); group->publish();
} }
strcat(arrIds, "]");
mqtt.publish("groups", arrIds, true);
for(uint8_t i = 1; i <= SOMFY_MAX_GROUPS; i++) { for(uint8_t i = 1; i <= SOMFY_MAX_GROUPS; i++) {
SomfyGroup *group = this->getGroupById(i); SomfyGroup *group = this->getGroupById(i);
if(group) continue; if(group) continue;
else SomfyGroup::unpublish(i); else SomfyGroup::unpublish(i);
} }
mqtt.publish("groups", arrGroups, true);
} }
uint8_t SomfyShadeController::getNextShadeId() { uint8_t SomfyShadeController::getNextShadeId() {
// There is no shortcut for this since the deletion of // There is no shortcut for this since the deletion of

Binary file not shown.

Binary file not shown.