Replies: 1 comment
-
I think I was able to address some of the issues that arise if there is no connectivity on the board. First of all - I see that indeed the connection is kept up and if it isn't connected initially, it will connect when possible. But the connection attempts are adding quite a lot of overhead based on what I have observed, so in my specific case, I have added longer intervals between DHCP retries and the MQTT reconnections. Here's roughly how this looks (declarations and defines missing but should be self explanatory): void setup() {
Ethernet.init(ETH_SCS_PIN);
int rc = Ethernet.begin(mac, ETH_DHCP_TIMEOUT);
if (rc) {
maintainInt = ETH_DHCP_OK_MAINT_INT;
}
else {
maintainInt = ETH_DHCP_NOK_MAINT_INT;
}
haDevice.setName("Arduino");
haMqtt.begin(BROKER_ADDR, BROKER_USER, BROKER_PASS);
// haMqtt initial loop to check for MQTT connection
haMqtt.loop();
}
inline void haMqttLoop() {
if (haMqtt.isConnected()) {
haMqtt.loop();
}
else {
if (currentTime - mqttRetryLast > BROKER_RETRY_INT) {
mqttRetryLast = currentTime;
haMqtt.loop();
}
}
}
inline void ethernetMaintain() {
if (currentTime - maintainLast > maintainInt) {
maintainLast = currentTime;
int rc = Ethernet.maintain();
IPAddress ip = Ethernet.localIP();
if (dhcpMaintainFail(rc) || allZerosIp(ip)) {
maintainInt = ETH_DHCP_NOK_MAINT_INT;
}
else {
maintainInt = ETH_DHCP_OK_MAINT_INT;
}
}
}
inline bool allZerosIp(const IPAddress &ip) {
return (ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0);
}
inline bool dhcpMaintainFail(int rc) {
return (rc == 1 || rc == 3);
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am wondering how robust is ArduinoHA in terms of Ethernet outages? My device is a button+relay board and it should be able to operate without issues when the Ethernet is disconnected and should be able to reconnect with the MQTT once the connection is restored. I still need to check if the Ethernet library will behave as expected but I wonder if such cases are handled by ArduinoHA?
What would happen if during boot-up there is no Ethernet link/MQTT server available? Would it work later when the connection is re-established?
Many thanks for this great piece of software BTW - saved me a great amount of work ❤️ !
Beta Was this translation helpful? Give feedback.
All reactions