Sunday, August 2, 2020

Temperature Collection for Rasp PI / Linux USB Attached probes

It all starts with Cron. I use it pretty heavily :)

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/digitemp/bs.s0 1> /dev/null
1,6,11,16,21,26,31,36,41,46,51,56 * * * * /home/digitemp/bs.s1 1> /dev/null

Gotta have a remote drive mounted with Samba…

/cp1/digitemp  /home/digitemp  cifs      user=timc,pass=[password],vers=3.0        0   0

Gotta call a shell script that calls the reader and the conf file

root@bs:~# cat /home/digitemp/bs.s0
#  1/19/19 TimC - rm digitemp file to put clean number in
#  updated via cron every 5 minutes
#  use /etc/digitemp directory for conf files & exec of this
#  use /tmp for current temp reading
/usr/bin/rm /home/digitemp/bs.s0.temp
/usr/bin/digitemp -c /home/digitemp/bs.s0.conf -a -l /home/digitemp/bs.s0.temp

conf file

root@bs:~# cat /home/digitemp/bs.s0.conf
TTY /dev/ttyUSB0
CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
ROM 0 0x28 0xFF 0x64 0x1E 0x1D 0xC6 0x77 0x54

which results in a single value (temperature)

root@bs:~# cat /home/digitemp/bs.s0.temp

Then of course it’s on a remote drive cp1:/home/digitemp
which is also using cron :)

4,9,14,19,34,29,34,39,44,49,54,59 * * * * /home/mrtg/temp/ &> /dev/null

which calls mrtg

root@cp1:/home/digitemp# cat /home/mrtg/temp/
/bin/mrtg /home/mrtg/temp/temp.cfg

mrtg config :)

root@cp1:/home/digitemp# cat /home/mrtg/temp/temp.cfg
# 10/12/18 added /bin/cfgmaker public@lo  10/12/18
### Global Config Options

WorkDir: /home/mrtg/temp/
Options[_]: gauge pngdate expscale fixunit nomax nototal nopercent unknaszero noo
MaxBytes[_]: 125
ABSMax[_]: 125
YLegend[_]: Fahrenheit
ShortLegend[_]: Fahrenheit
LegendI[_]: Temperature
Legend1[_]: Temperature
Options[_]: integer, gauge, nopercent
Colours[_]: RED#FF0000, WHATEVER#123456, DARKRED#800000, WHATEVER2#654321
Background[_]: #0a0a0a0
TimeStrPos[_]: RU
#Unscaled[_]: ymwd
#   ................
#       bs 1 - Attic
#          USB RS485 serial port ttyUSB0
Target[bs-s1]:  `/home/mrtg/temp/`
Title[bs-s1]: Behind Freezer Temp sensor
PageTop[bs-s1]: <H1>Behind Freezer Sensor</H1>
PNGTitle[bs-s1]: Behind Commercial Freezer Temperature

which calls another script to gett it into the proper oid and 4 values for MRTG…

root@cp1:/home/digitemp# cat /home/mrtg/temp/
#  4 The external command must return 4 lines of output:
#    Line 1
#    current state of the first variable, normally 'incoming bytes count'
#    Line 2
#    current state of the second variable, normally 'outgoing bytes count'
#    Line 3
#    string (in any human readable format), telling the uptime of the target.
#    Line 4
#    string, telling the name of the target.
DATE=`/usr/bin/date +%m%d%g`
SNMPGET="/usr/bin/snmpget -v 1 -c public"
AWK="/usr/bin/awk -F"
#AWK1="/usr/bin/awk -F '=' '{print $2}' "
#AWK2="/usr/bin/awk -F ')' '{print $2}' "
TEMP=`/usr/bin/cat /home/digitemp/$HOST"."$SEN".temp"`

#echo $AWK1
#echo $AWK2
UPTIME=`$SNMPGET $HOST $OID | $AWK '=' '{print $2}' | $AWK ')' '{print $2}'`




Which results in the following data set that mrtg can read

root@cp1:/home/mrtg/temp# ./

Simple really :) A lot of moving parts perhaps. Yeah, I like scripting I guess. It has some pretty cool graphs. I have about 15 of the probes measuring different parts of the house and then I have a web page running on cp1 that displays all of the temperatures. Most are running on pi zero’s but I have had a lot of problems with USB reliability on the Zero’s. Well I’m not actually sure if it’s a problem with the zero or a problem with the cheap ass USB probes. - Prolific Technology, Inc. PL2303 Serial Port which is essentially a single wire RS-485. I’ve tried unsuccessfully to get a multi-point RS-485 working, and finally just gave up over the abundantly prolific probes. for $10 a PI (zero w/header and wireless) and $3 for a probe. I can turn a new one up for under $15.00 with tax / shipping et all and it’s completely self contained. I’ve put a bunch into a 2 gang electrical outlet, that I hang off of a room outlet. It give me room to put in a cheap 2amp power supply with a couple cables and the probe and the zero.

I’ve also played around with Relays…. More on that later. I’m controlling my irrigation system and outside light timer using Zero’s…

If the above logic is confusing… The relays are even worse. A lot of it’s the same. But much of it’s different. I also have a few motion sensors and light meters and GPSs using the same zero’s But that’s all stuff for another post.

Questions? It’s not a how to, just a what ive done. If you want a how to go somewhere else.

Add comment

Fill out the form below to add your own comments