Experiment Status: TESTING | Experiment Start Date: April 8, 2019
Update 4-17-19: Putting this experiment on hold - the Raspberry Pi used for this project died after the first night of testing =(
This project is a fun little experiment with a Raspberry Pi 2. Awhile ago, a Youtube video caught my attention about building a computer system to last decades with minimal downtime. The video didn't really go into the "how" or the technical side of actually building a system. It did, however make some interesting points on what you need to think about when planning for such a system. How to build a System that will run for 30 years
I thought it would be interesting, as an experiment, to see if I can build a system that lasts for years, even a decade! I also wanted this system to actually perform a specific function. How long can I manage to keep it alive without little to no maintenance? To do this experiment, I had absolutely no budget (HAHA), so I settled on using equipment I already had around the house.
A few years ago, approx 2015, I bought a Raspberry Pi 2 & a DS18B20 waterproof temperature sensor and other various components needed from Adafruit (see links below). I got it to function, using a script to record the temperature from the sensor and log it to a database. I even built a small web dashboard to display the temperature. It ran in my laundry room for several months, collecting the temperature. After a house move, it was disconnected and sat in a drawer for 2 years, oops. This will be re-used for my experiment.
Build a temperature gathering system & application to run on a Raspberry Pi. The application will log the current temperature to a flat file two times a day. The goal is to keep the system running as long as possible with minimal maintenance.
- House the Raspberry Pi & other components in an enclosure
- The DS18B20 cable must be run outside of house.
- Indicator light system - use GPIO pins.
- Light system will flash red/green based on results from Restful API endpoint.
- Restful API
- Endpoint to log temperature to flat file ( no database! ).
- Endpoint to test thermometer ( for dashboard & indicator lights ).
- Endpoint to check system uptime.
- Display thermometer status & current temperature.
- Interface to read datafile ( history ).
- Various scripts
- Bash script to CURL temperature endpoint ( CRON job ).
- Bash script to commit data file nightly ( CRON job ).
- Python script to turn on/off led's via gpio pins.
- Bash script to CURL test endpoint.
- Raspberry Pi w/ Raspbian installed.
- DS18B20 Digital Temperature sensor
- 4.7K or 10K ohm resistor
- Breadboard (solderable)
- Jump wires
- Pi Cobbler
- IDE ribbon cable.
Note these may be added down the road
- 2nd Raspberry Pi ( backup Pi ).
- Battery backup - more thoughts on this later.
Temperature sensor setup
I followed the Temperature sensor assembly instructions from Adafruit. It is pretty easy to get up and going with these instructions. I also used a 1 x 2 inch solderable breadboard for a more stable solution and is just big enough to hold the Pi Cobbler, temp sensor, and indicator lights without getting too cramped.
Below is the schematic (taken from Adafruit and used without permission):
My final circuit (without light indicator wiring):
Temperature Sensor Setup
There are a few steps in order to begin collecting temperature, so we need to add OneWire support.
On the Raspberry Pi, add the below line to
dtoverlay=w1-gpio -- then reboot the Pi.
sudo modprobe w1-gpio
sudo modprobe w1-therm
cd 28-xxxx (change xxxx to what shows from above command)
You should see two lines outputted from the above command. The first line ends in either YES or NO. If a YES is displayed, the sensor received a good reading. The 2nd line outputs the temperature, for example
a2 01 4b 46 7f ff 0e 10 d8 t=023345 where
t=023345 is the raw temperature and needs to be converted.
pwd to get the full path of the
w1_slave file, this path is needed for the software installation below and will need to be entered into
Indicator Light Setup
More info on this soon!
Since this project is heavily on the cheap side, I decided to enclose everything in a metal case. The case is from an old exterior timer for a lighting system, and works great for this project as the inside is large enough for everything. I drilled two holes on the front cover door for the 2 indicator LED's and painted the case with a rubbed bronze spray paint.
Case with Pi mounted - no cover:
Case put together - no light indicator assembly:
The main software components are the Dashboard and the Restful API.
The dashboard is self explanatory. Displays current temperature on page load ( Ajax call to API ). Refresh button sends additional call. History directs to separate page which reads datafile.
Screen shot if temperature sensor is unable to get a reading:
Keep in mind you really need to fulfill the existing hardware for this to be useful, although you can replace the
GPIO_TEST setting in
true, and the application will use the provided mock file located at
/data/w1-slave ( allows you to at least tinker with the application without the temperature sensor )
- PHP 7.1 +
- Apache w/ mod_rewrite (see link below)
- Python ( some scripts required )
- Run - composer install in project root.
- Apache - point virtual host document root to
data/is web writable.
http://servername& follow install instructions.
- Run - composer install in project root
- Launch LOCAL PHP Server from folder
php -S localhost:8000 -t public public/index.php
- OPTIONAL: Launch server.bat if on Windows or server.sh for Linux - (alternative)!
http://localhost:8000& follow install instructions.
scripts/record_temperature.shwith username/password created in installation.
- Update URL if needed.
GPIO_PATHwith location of temperature output file (See hardware above) a. e.g. ``
I went on the cheapest route possible for this project and re-used a lot of components I already had lying around. If I were to do a second version of this project, I would definitely make the whole unit smaller using a Raspberry Pi Zero or perhaps something else. I think I would also make the unit weather proof & power it with solar to keep it outside permanently.
Copyright (c) 2018 Drew D. Lenhart
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.