Random

Snow Temperature Logger with Raspberry Pi

I do some work for ski areas, and one of them has a nordic center. The Nordorks really care about the snow temps, so I built a raspberry pi temperature logger using a waterproof temperature sensor. Skip to the example

Nordic Pi Documentation

The Nordic Pi is a raspberry pi, display, and temperature sensor. The goal of this project is to
collect snow temperature readings. They can be viewed online, and also displayed on a
monitor connected to the same raspberry pi device. Internet connectivity is required.

Accessing the Nordic Pi

The Nordic Pi can be accessed via ssh and vnc.

Reading Temperatures

A simple script was written by Jonathan Damon to read the temperature sensor and submit the
values to a remote database. This file takes a single reading.

/home/pi/TemperatureSensor/record-temps-remote.py
import MySQLdb
import os
import glob
import time
os.system( 'modprobe w1-gpio' )
os.system( 'modprobe w1-therm' )
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*' )[ 0 ]
device_file = device_folder + '/w1_slave'
def read_temp_raw ():
f = open(device_file, 'r' )
lines = f.readlines()
f.close()
return lines
def read_temp ():
lines = read_temp_raw()
while lines[ 0 ].strip()[ -3 :] != 'YES' :
time.sleep( 0.2 )
lines = read_temp_raw()
equals_pos = lines[ 1 ].find( 't=' )
if equals_pos != -1 :
temp_string = lines[ 1 ][equals_pos+ 2 :]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c
Con = MySQLdb.Connect(host= "HOSTNAME" , port= 3306 ,
user= "USERNAME" , passwd= "PASSWORD" , db= "DATABASENAME" )
Cursor = Con.cursor()
Cursor.execute( "INSERT INTO `nordictemps` (`celsius`, `sensor`) VALUES
('" +str(read_temp())+ "', 'NordicTemp1')" )
Con.commit()
Con.close()

Scheduling the temperature readings

For convenience, I have installed a crontab gui. The current schedule is “every 5 minutes”.
You can edit the cron jobs by going to Start > System Tools > Scheduled Tasks
You can also edit the crontab file by opening a command prompt and entering crontab -e
For this project, the cron settings are */5 * * * * and the command is…

python TemperatureSensor/record-temps-remote.py >/dev/null 2>&1 >/dev/null 2>&1>/dev/null 2>&1

Cron jobs are run from the home folder so the relative path to the file is used.

Starting the Display on boot

The autostart file launches the chromium browser in fullscreen kiosk mode. Additional directives
hide the cursor and disable “tab restore notifications” after chromium quits unexpectedly. (ie,
power failure) Although unnecessary, the desktop is loaded to assist supporting this pi.
/home/pi/.config/lxsession/LXDE-pi/autostart

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xset s 0 0
@xset s noblank
@xset s noexpose
@xset dpms 0 0 0
@point-rpi
@chromium-browser --kiosk --incognito YOUR_URL_HERE
@unclutter -idle 0.1 -root

Wiring

We used 3 pins on the GPIO Header for this project, 01, 07, and 09. You can use any of the
3.3vDC and Ground pins, but must use pin #07 ( GPIO04 [GPIO_GCLK] ) for the temperature
sensor.

The following diagram shows a closeup of the section of GPIO pins we are using, and the
connected wires and 4.7k resistor. The red/yellow/black wires were used to match the factory
wires on the temperature sensor so that wiring is consistent.

Web Interface

The Nordic Pi submits temperature readings to a remote web server, which makes it possible to
embed the graph and temperatures on external websites. (ie eldora.com) This remote server
controls how the information is displayed.
While the Pi’s functionality is basic and unlikely to be changed, the web interface will probably
be improved and edited after rounds of feedback. Since it is still a work in progress, the web
interface will be documented in the future, in a separate document.

Troubleshooting

The Pi is quite robust and should recover from power failures and internet connectivity issues.
Because it is running a display, most error reporting and output is suppressed, so that issues
with temperature readings don’t negatively affect the show on the monitor.
After checking all wires and internet connectivity, press Alt+F4 to exit kiosk mode . You can
then run the script manually to view errors. When you’ve completed your testing, reboot the pi
and the autostart should relaunch chromium in kiosk mode.

Example

Here’s the Nordic Pi running live data.  Please note the “last reading” date to see how robust this solution is.  (It may be replaced someday and will be off in the summer months)