Forth Estuary Experimental Data Network

Network Map
Status 2 day
Status 30 day
Technical Info
Contact Information
Feednet Services


Downloadable PI Image


Most of what can be achieved via FEEDNET is courtesy of open source software. The sheer hard work, altruism and inventiveness of all open source authors is gratefully acknowledged here.




Safely Shutdown the Raspberry PI with a switch.


We use Raspberry PI single board Linux computers for all kinds of purposes relating to FEEDNET. They are cheap, powerful and flexible.  But we need to remember that they are ordinary Linux computers and that they should never be switched off without shutting down the operating system first.   Our experience is that this often does not happen. Perhaps there is no handy terminal at hand just at the moment when the power is to be removed. Perhaps not everyone knows how important it is to get this right.  Disconnecting power from a PI server without performing a safe shutdown can damage irreparably the file system and lead very quickly to an inoperable system.


We install an LED and push button switch on every PI. The LED flashes when the PI is up and running.  Power should never be removed when the LED is flashing. Pressing the switch will trigger a proper controlled shutdown of the system, and a few seconds after the LED stops flashing it is safe to power off.

Reproduced here are the details of what we have done. Use them at your own risk. You can destroy your PI very easily by adding hardware to it or making modifications. The components we use may not be the same as those that you source.    We accept no responsibility for damage to your equipment no matter how that damage is caused. If you do not agree then do not read any further or use these instructions in any way.


Connect Pin 11  of the GPIO expansion board to a 570ohm resistor in series with an LED  as shown below.  Note that Pin 11 of the header pertains to GPIO Pin 17, otherwise known as GPIO_GEN0.

Connect a 1K resistor from pin 12 of the GPIO expansion board to one side of a normally open switch. Note that Pin 12 of the header pertains to GPIO Pin 18, otherwise known as GPIO_GEN1. Connect the other side to ground.




Create the following files in a suitable subdirectory.


include <stdio.h>    // Used for printf() statements
include <wiringPi.h> // Include WiringPi library!
// Pin number declarations. We're using the Broadcom chip pin numbers.
const int ledPin = 17; // Regular LED

int main(void)
    // Setup
    wiringPiSetupGpio(); // Initialize wiringPi -- using Broadcom pin numbers
    pinMode(ledPin, OUTPUT);     // Set regular LED as output
            // Do some blinking on the ledPin:
            digitalWrite(ledPin, HIGH); // Turn LED ON
            digitalWrite(ledPin, LOW); // Turn LED OFF
    return 0;






#include <stdio.h>    // Used for printf() statements
#include <stdlib.h>  // Used for system command
#include <wiringPi.h> // Include WiringPi library!
// Pin number declarations. We're using the Broadcom chip pin numbers.
const int butPin = 18; // Active-low button

int main(void)
    // Setup
    wiringPiSetupGpio(); // Initialize wiringPi -- using Broadcom pin numbers
    pinMode(butPin, INPUT);      // Set button as INPUT
    pullUpDnControl(butPin, PUD_UP); // Enable pull-up resistor on button
        if (!digitalRead(butPin)) // Button is released if this returns 1
            system("shutdown -h now");
            delay(10000)  // No debounce. We want to avoid issuing zillions of shutdown commands.;

Now you need to compile the programs. Do so with

gcc -o ledblink ledblink.c -lwiringPi
gcc -o switchoff switchoff.c -lwiringPi

You must have the compiler gcc and the wiringPi library installed. See here https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

Edit the /etc/rc.local file and add the following lines. These will be executed at boot up time.  Note that these lines should contain the full path to your compiled code. In my case it was /home/myc/filename. In your case it depends which directory you used at the beginning.

/home/myc/ledblink  &
/home/myc/switchoff  &

Reboot and both programs should run in the background. The LED will be flashing. To switch off the PI safely, press the button for a second or so. You will see the LED stop flashing (either steady on, or steady off). After 10 seconds more, you can safely remove power.






Home | Network Map | Status 2 day | Status 30 day | Emcomm | Technical Info | Contact Information | Streaming | Feednet Services | Gallery

Last updated: 02/26/16.