3

I'm working with the BeagleBone Black, which runs Debian Linux, and sometimes I will lose wireless connection to it while I am testing my programs. This wouldn't necessarily be an issue on its own, but, since I'm running it on a robot, bad things can happen if I can't stop whatever program is running on it. Is there a way for the BBB (or Linux in general) to detect when I've lost connection to it and either respond in the currently running program or to run a separate script to force everything to a safe state? I did a little reading and tried using SIGHUP, but that didn't actually work (the motors kept running after I force-killed the local SSH process).

dhag
  • 15,736
  • 4
  • 55
  • 65
  • Use screen or tmux – heemayl Apr 12 '15 at 19:28
  • Screen or tmux wont work if he has lost connection to it??? What I would do is write a script on the remote host to ping your computer or attempt some command that if it fails you take measures to re-connect your wifi. Perhaps an ifconfig wlan0 down && ifconfig wlan0 up or perhaps a reboot depending on what fixes the issue. – Dylan Apr 13 '15 at 03:07

3 Answers3

3

You can have some kind of watchdog script running that requires a signal via the remote connection every n (milli)seconds and have it do something when not receiving the signal.

See How to introduce timeout for shell scripting? for an example of an expect-script that prints a message on timeout; you can alter it to create a safe shutdown.

The watchdog echo (localhost) and expect (robot) should go over the same ssh connect e.g. via ssh port forwarding. So that when you loose the ssh connection the watchdog will go down as well and start the safe parking script.

  • I think this is the correct route, to have a script run on the remote host and if it detects the wifi connection to your local host is down then it takes action to correct the issue. + 1 – Dylan Apr 13 '15 at 03:09
  • This sounds like the best solution, but I haven't had a chance to test it yet. If I enable ping replies on my Windows computer, would it be possible to have the expect script start the safe parking script on a ping timeout? Or would it be better to have my computer explicitly sending to the robot and have expect check for a timeout on receiving? – Wes Tarro Apr 15 '15 at 16:34
0

I don't know the BBB but as said heemayl you can use screen (or tmux which I find more user friendly).

Those tools allows you to connect to a remote machine, do what you want (starting a script for example), detach the session and reconnect to it later. The advantage of tmux is that it allows to create easily several sessions on the machine and slice them into different tabs.

Is it what you're looking for?

statox
  • 237
  • I am confused but it sounds like he loses connection to the remote host, how would screen help if he can't connect? Perhaps i misunderstood the issue. – Dylan Apr 13 '15 at 03:08
  • Oh or perhaps I misunderstood (it was late when I wrote my answer I might have read too fast) : actually he wants to send a signal at the disconnection and indeed I'm not sure screen allows that. – statox Apr 13 '15 at 06:13
0

You might want to investigate mosh which is like ssh modified for unreliable connections. From the website:

Mosh (mobile shell) Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes.

Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links.

wurtel
  • 16,115