I’m using an Arduino OPTA PLC programmed through the Arduino PLC IDE (version 1.0.8.0). It’s connected to a relay/IO extension module, and I mainly use the Arduino PLC runtime with its built-in MODBUS TCP slave interface to communicate with the device I/Os.
The host system polls the PLC inputs once per second via MODBUS over TCP.
However, every few months, the communication to the PLC crashes. When this happens:
The PLC becomes unreachable — I can no longer ping it or establish any MODBUS connection. (I tried from another system on the network)
All relays turn off (normally, at least one relay should always be active), suggesting the PLC has entered some internal fault or reset state.
Power-cycling the PLC restores normal operation immediately. MODBUS communication then works fine again (both from the host and from manual tests on my PC), and the system continues running normally for several months, until the issue reoccurs.
Has anyone experienced similar behavior?
Could this be a firmware or runtime reliability issue?
Any suggestions on how to debug or permanently fix this would be nice.
Can I implement some type of watchdog to reset upon a crash?
I have no experience with the Opta, but the problem sounds like a slow memory leak that eventually consumes all of RAM. Monitor memory usage, free memory or both over time to check for that.
It's currently still in its hang state (didn't yet power cycle it). Can i get its current trace through the USB to get some more debug information? Is there any logging done that may pinpoint the crash?
I'll implement the code and see if it happens again. If its a memory leak, its part of the runtime environment, right?
If you do something like this in your dev setup() you can lock out a large chunk of your heap so that the allocation failure (if that's what it is) would occur much sooner.
char *lockout = new char[350000];
p.s. For completeness, I should mention that crash reporting data can be made available, but it's a lot of work. See section Crash reporting and auto-reboot
I also included the WDT as follows. However, I'm still not capturing issues with the ethernet PHY or TCPIP stack. The OS may keep running but the networking may fail. Can I also monitor that?
#include <mbed.h>
mbed::Watchdog &watchdog = mbed::Watchdog::get_instance();
void setup()
{
watchdog.start(1000);
// Configure static IP address
IPAddress ip(192, 168, 1, 105);
IPAddress dns(8, 8, 8, 8);
IPAddress gateway(192, 168, 1, 104);
IPAddress subnet(255, 255, 255, 0);
// If cable is not connected this will block the start of PLC with about 60s of timeout!
Ethernet.begin(ip, dns, gateway, subnet);
}
void loop()
{
delay(500);
watchdog.kick();
}
MBED_NORETURN void mbed_die () {
NVIC_SystemReset();
}
You could monitor socket stats but that would need a tweak to your mbed config and a rebuild of the mbed core lib.a
One option that may be available to you is a scheduled auto-reboot once a month. Crude workaround but might be acceptable if you can't get to the bottom of this.