Hi,
I changed my code to this and it works. The only thing is that it takes about 2 seconds to retry and the carry on excicuting my code.
if (Ethernet.linkStatus() == LinkOFF) {
systemMessages = "Cable not connected or damaged";
ethClient.stop();
} else {
if (!modbusTCPClient.connected()) {
systemMessages = "Attempting to reconnect Modbus...";
Ethernet.begin(mac, ip);
modbusTCPClient.begin(server, 502);
} else {
doModbus();
systemMessages = "Modbus Connected";
}
}
I had a look at the Ethenet Class of the ethernet library. So I tried these functions to set my retries and time out. But I get errors when I compile.
- Ethernet.setRetransmissionCount()
- Ethernet.setRetransmissionTimeout()
In my setup loop. This is what I did.
Ethernet.begin(mac, ip);
Ethernet.setRetransmissionTimeout(10);
Ethernet.setRetransmissionCount(3);
modbusTCPClient.begin(server, 502);
So it compile with errors. This is the error.
/var/run/arduino/user-cache/sketches/096EF522CA3E27EE7D8409719A2E2D3E/sketch/objs.a(24EI44111_2_H25.50_ShopRite_PE_Wells_Estate_may05a.ino.cpp.o): In function `setup':
/run/arduino/sketches/24EI44111_2_H25.50_ShopRite_PE_Wells_Estate_may05a/24EI44111_2_H25.50_ShopRite_PE_Wells_Estate_may05a.ino:194: undefined reference to `arduino::EthernetClass::setRetransmissionTimeout(unsigned short)'
/run/arduino/sketches/24EI44111_2_H25.50_ShopRite_PE_Wells_Estate_may05a/24EI44111_2_H25.50_ShopRite_PE_Wells_Estate_may05a.ino:195: undefined reference to `arduino::EthernetClass::setRetransmissionCount(unsigned char)'
collect2: error: ld returned 1 exit status
Seems like its not part of the Library for the Portenta H7. But I'm not sure. I do not have extensive experience with Ethernet yet to understand if its included or not.
What is your take on the two functions that compile with errors?