Shutting down the headless client along with the host

Firmware/software/electronics/mechanics
Post Reply
essorrac
Beginner
Posts: 6
Joined: Mon Sep 30, 2013 5:40 pm

Shutting down the headless client along with the host

Post by essorrac »

Hello folks,

I am currently tinkering with the headless client on a mobile (battery powered) raspberry pi setup in order to be able to pilot / deploy it a bit away from computers.

Since I'm headless on it, without display, and as I'd prefer not being forced to simlpy power down the pi to shut it, risking SD card corruption, I'm thinking about powering it (simple sudo halt) off using either a gamepad key combination of simply when the radio is plugged out, maybe after a certain timeout.

Did anyone already figure a gracious way of handling that ? I think i'll start trying the radio unplugging and timeout process, but I'd gladly take any other idea.

By the way : I know this could be achieved using the gpio pins and some simple listener, but i'd prefer being able to keep the pi in its case without having a risky emergency shutdown dangling out.

Thanks !
essorrac
Beginner
Posts: 6
Joined: Mon Sep 30, 2013 5:40 pm

Re: Shutting down the headless client along with the host

Post by essorrac »

Ok so far for a quick and dirty bunch of uglyness, i've added something like

import os
retvalue = os.system("sudo halt")
print retvalue

in radiodriver.py juste after self.link_error_callback("Error communicating with crazy radio" ....

Along with a sudoers configuration modification to allow the bitcraze user to sudo halt without any password entry.

It does the job, but I'd still prefer something a bit prettier and robust, as I guess that on the field I might have to unplug / plug the radio to restart the link. Even if the pi does boot quickly, it will waste some time as is.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Shutting down the headless client along with the host

Post by arnaud »

Hi,

Just a random idea: the simplest I can think about is to add a Udev rule that halts the system if a specific USB device is inserted.
For example by adding this in /etc/udev/rules.d/99-usbhalt.rules

Code: Select all

ACTION=="add", ATTR{idVendor}=="0781", ATTR{idProduct}=="5567", ATTR{serial}=="4C532000030416102072", RUN+="/sbin/halt"
It will halts the board when inserting a specific USB flashdrive, this methode can be used with any usb devices that will then become some kind of shutdown key. I could get the ids and serial number by using "sudo lsusb -v". I am not sure this solution qualifies as elegant but at least it is effective :-).


For the idea of halting the board when pressing Gamepad keys it would require making a python program that listen to the gamepad and can halt the system when the key combo is pressed.This script will have to be launched when the Crazyradio is removed and killed when the radio is inserted. This would ensure that it does not conflict with the Crazyflie client.
hsanjuan
Beginner
Posts: 19
Joined: Sat Jul 20, 2013 10:51 am

Re: Shutting down the headless client along with the host

Post by hsanjuan »

In my setup, I have a udev rule that runs a script that shuts the RPi down 1 minute after the crazyradio is removed.

It compliments a second udev rule that cancels all shutdowns and starts the client when the crazyradio is inserted.
Post Reply