kurbatov / firmata4j

Firmata client written in Java.
MIT License
87 stars 45 forks source link

Cannot detect if device is still connected #30

Closed centic9 closed 5 years ago

centic9 commented 5 years ago

I have an Arduino connected via USB for some Button/Led interaction.

The device is connected for a long time and should stay connected across all types of system-events, e.g. when the machine resumes from sleep/hibernate or whenever there is a hickup on the USB ports.

But sometimes the device gets disconnected and firmata4j does not detect this, so I cannot build in code which automatically restarts the device.

Is there a way to detect that the device is still working, i.e. some ping/watchdog request/response functionality?

https://github.com/firmata/ConfigurableFirmata/issues/47 is related somehow, but seems to be further out.

Currently I am doing something like the following, but it would be nice to have a "last receive timestamp" or even a "restart after x-seconds device inactivity" built into the library.

            device = new FirmataDevice(comPort) {
            // Firmata4j does not have a Watchdog functionality, so
            // I use the timestamp of the last received event as indication
            // that there was no update any more
            @Override
            protected void handleEvent(Event event) {
                lastReceivedTimestamp = event.getTimestamp();
                super.handleEvent(event);
            }
        };
kurbatov commented 5 years ago

Hi Dominik,

I made an implementation of a watchdog for the next version of firmata4j. Could you please review #31 to see if it works for you. I would appreciate any suggestions on further improvement.

kurbatov commented 5 years ago

Hi Dominik,

This watchdog implementation now available in firmata4j-2.3.7