is there any kind of watchdog timer kind of thing in processing that will restart your code from the beginning? like rerun setup and everything if the serial communication isnt happening?
I am making a kiosk type setup. A bunch of buttons go into a teensy. Teensy goes reads button presses and tell intel NUC whats happenin’
I ran into a problem today where (due to back emf from a relay… which i am going make a snubber circuit so this doesnt happen anymore) the teensy lost connection from the computer for a split second. Processing was already running and when the teensy booted back up, the serial connection was lost because processing is already in the main loop and I guess when the teensy came back online processing didnt want to listen to the serial messages. it only worked if i manually restarted the program. That’s not going to be possible in the final product.
Hi! It depends on how long the downtime can be. I often use pm2 for “production” to auto restart apps when crashed (you can use it not only for node.js but anything that can be launched from a terminal).
But that means the sketch will restart. If that is not “acceptable” I would move the code from setup to somewhere else and trigger that function whenever the connection is lost (within draw).
Nevertheless I highly recommend pm2 even if you implement the second solution. Always assume that crash happens after some time, and pm2 stores all the log output so it’s handy for debugging too.
Hi @zumdar, I assume you are using a Windows PC, as I am. I have Processing sketches that notice the problem with the serial, stop using serial (myPort.stop), wait looking for the port to reappear (serial.list) and reconnect. This works if the loss of the serial device is longer than ? let’s say 0.5 second. This successfully handles manually disconnecting and reconnecting, or repowering the Arduino. If it’s a very short break, and the sketch is still trying to use the port when it reappears, the situation is unrecoverable programmatically. Even stopping the sketch won’t recover that. Another way of saying it is, there must be a time when the port isn’t there, and no program is trying to use it.
For your situation can you ensure the comms break is always long enough for the sketch to notice? Maybe not.
cool thank you for this reference! ive never heard of pm2, but that could be useful for future projects. for this one, i need something a little more speedy to reconnect. The sketch uses quite a bit of memory so it takes a good 60-90 seconds to start up. maybe i will try to implement that as a double backup. I wish this kiosk was connected to the internet so I could check on it from time to time, but it will be mobile. set up for various events around the country.
oh shoooot! that is a good idea! i just looked more into the serial library and i could just wrap the entire program in a while(myPort.available>0) loop… then if its not available, stop the port and then try to reconnect. it seems like an easy solution… but will it work reliability…!? stay tuned!
Hey, I’m hijacking this thread to talk about pm2. @micuat do you have any example of a pm2 config for a project ? When using it to start Exported (.exe) Processing apps, pm2 will have them restart with SIGINT until the max restart is reached.
I tried on multiple machines with multiple sketch builds without success.