Files

138 lines
12 KiB
Plaintext
Raw Permalink Normal View History

Episode: 2353
Title: HPR2353: RoboThermometer
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2353/hpr2353.mp3
Transcribed: 2025-10-19 01:36:29
---
This in HBR episode 2,353 entitled Robo Thermometer, it is hosted by Epicanis and is about 13 minutes long and Karimaklin flag.
The summer is a surprisingly short geeky episode about connecting a temperature sensor to the Raspberry Pi.
This episode of HBR is brought to you by AnanasThost.com.
Get 15% discount on all shared hosting with the offer code HBR15, that's HBR15.
Better web hosting that's honest and fair at AnanasThost.com.
This episode includes a shell command that is relatively simple but sounds insanely complicated when recited aloud.
Would you believe that this command is the entire reason I decided to record today's episode?
Here is your caffeinated beverage, Master.
Thank you robot friend. Your microphone is live and you have begun recording, Master.
Oh, right. Hello hacker public radio. You may recall that I was having some trouble with robot vampires during my previous episode.
The robot vampire problem has taken care of now, but I did have to re-engineer the cultures in their microbial fuel cells
to metabolize something other than the blood of the innocent, or, you know, the blood of me, either.
And I had to bring in a witch doctor to sacrifice three bunnies and a sketch of Isaac Asimov to drive out the evil spirits.
And I had to replace the muffler bearings and refill the headlamp fluid.
You know, all routine stuff, but it took a while to get it all sorted out.
Now they are no longer powered by human blood. They are powered by caffeine, just like a normal human IT person.
Now that we have so much in common, the robots are my friends.
In fact, today's episode is about one of my little robot friends who is built around a Raspberry Pi and sits around monitoring room temperature for me.
That seems like a ridiculously contrived introduction for an episode about connecting a temperature sensor to a Raspberry Pi.
Shh. Fine. What's really going on here is...
Name of employer.
Has had a couple of incidents with server room air conditioning failing,
and now they're looking into getting some temperature monitoring equipment put in.
By default, this probably means some proprietary module for our proprietary security system
that won't do much more than send emails if the temperature gets too high,
doesn't talk to any other systems, and costs far more than such a simple thing should,
like $250 USD each.
Or so the one online price that I was able to find for our security system's brand name sensor seems to indicate.
My media player design from the last episode has worked out pretty well,
so I decided I wanted to see if I could come up with a temperature monitor design
that would be extensible, customizable, would talk to the existing computer and network
monitoring system I set up around Xabix, and wouldn't cost much.
I'm running Xabix to monitor my home network too, so I figured I would try to get one working at
home and tie it in. Not to spoil the ending, but it works. If you want your own temperature
monitoring robot like mine, here's all you have to do, presented in properly nerdy detail.
Don't worry if your eyes glaze over and you fall into a hypnotic trance while listening to
me recite commands, the important parts will be included in text form in the show notes for you
to read later when you snap out of it. First, get a Raspberry Pi. Install the operating system
and edit the slash boot slash config.txt file to add the line dt overlay equals w1-gpi0
so that the OS knows to create a device node for the sensor to be associated with.
Power off the Raspberry Pi. Get a pre-assembled DS18B20 module or the bare part and a 4.7 kilo
ohm resistor. I'm using the pre-assembled board with the sensor, the resistor, and a couple of LEDs
to indicate power on and data activity, which is sold by SunFounder, thanks to a generous Christmas
time grant from the mom and dad foundation. Hi, dad and mom! If you're using the bare parts,
which retail for about $4 US dollars, connect to the resistor between the positive voltage and
data pins yourself. If using the $8 SunFounder board or other pre-assembled module, you can skip that.
Then, just plug things in as follows. Connect pin 1 of the DS18B20. That's the ground wire
to pin 3, also the ground wire on the Raspberry Pi. Connect pin 3 of the DS18B20. That's the
VCC or positive voltage pin to pin 2 on the Raspberry Pi, which is plus 5 volts.
Pin 1 on the Raspberry Pi, which is 3.3 volts, might also work. The DS18B20 itself will work
with anything from 3 volts to 5.5 volts. The SunFounder board has those LEDs on it though,
so I'm assuming it needs the extra volt and a half or so to light those up. Finally,
connect pin 2 of the DS18B20. That's the data wire to pin 7 on the Raspberry Pi, which is GPIO
number 4. Power on the Raspberry Pi. Log in and type these commands.
Sudo, ModProbe, W1-GPIO, and then Sudo, ModProbe, W1-Thurm. Now look in, slash cis,
slash bus, slash W1, slash devices, to figure out which one is your temperature sensor.
It should be 28- and a big long hexadecimal number. If you just have the temperature sensor
and nothing else, there'll be two things in there, and the one you want is the one that's not
labeled W1 busmaster. Now try this. Cat, space, slash cis, slash bus, slash W1, slash devices,
slash whatever your device's number is, slash W1 underscore slave. That command should spit out
a couple of lines with T equals and your temperature in milicellseus at the very end. In a typical
indoor place, this is probably around 22,000, which would mean a room temperature of 22.000 Celsius.
If you don't care that you have to explicitly ask the temperature bot what the temperature is,
and you're okay with just mentally inserting the decimal point, and using the temperature
in celsius scale, you can be done here if you want. But if you want to make the output more useful,
try this. Install the BC package by typing Pacman-CapitalSBC. Or if you're just not cool enough
for arch Linux, you can apt-get install BC, like some sort of techno-commoner if you must.
Now then, if you're among the mighty nations of the Bahamas, the United States, or Belize,
who use Fahrenheit freedom units for temperature, you can fetch the reading from your temperature
sensor and convert it to a plain number and Fahrenheit, with the following single command.
Echo, space, double quote, scale equals three semicolon space, left parentheses,
backtick, grip, space, dash o, space, double quote, left square bracket, left square bracket,
colon, digit, colon, right square bracket, right square bracket, backslash, left curly brace,
five, backslash, right curly brace, double quote, space, slash cis, slash bus, slash w1, slash
devices, slash your device's number, slash w1 underscore slave, backtick, forward slash,
left parentheses, five thousand, forward slash nine, right parentheses, right parentheses,
plus 32, double quote, space, pipe, space, BC. That was easy enough, wasn't it? Don't panic,
that command I just read off, I'll put that in the show notes so you can just read it too.
Oh, if you're wondering about backtick, that's, we'll see, when backslash and single quote get
really drunk and they get together one night and, well, anyway, that's the other thing that's
on the tilde key at the upper left of most U.S. keyboards. The output of that command should just
be the temperature in United States temperature freedom units to three decimal places.
Replace the five thousand divided by nine plus 32 part with just one thousand if you're
living in one of the few isolated handful of places that make up the entire rest of the world
outside of the U.S., or maybe come up with a non-BC-based decimal insertion trick of some sort instead,
maybe involving Bach or said or something. A proper full length discussion of the
extremely flexible Zabix monitoring system is well beyond the scope of today's short episode,
but in summary, to connect the Robothermometer to Zabix, just install the Zabix agent package on it,
and adjust the Zabix agent configuration appropriately to set the address of the Zabix server
and the hostname, and then define that one line command I just mentioned as a user parameter.
In my case, I named it room temp, and then, when you define the entry for the Robothermometer
on the Zabix server, you just create a monitoring item for it, and just like that,
you've got an ongoing historical record of the temperature, and you can easily set up triggers
in Zabix to alert you by email, posting to a channel on your rocket chat instance,
making loud noises, and various other things if the temperature gets too high, or too low,
or is changing too fast. One thing that looks handy about the DS18B20 temperature sensor
is that it seems to be available for well under $10 US dollars in a few different forms,
including encased in a stainless steel tube that you can use to monitor temperatures with
the sensor submerged. It'll operate in environments where it's about as cold as it ever gets
naturally outside of Antarctica, and comfortably above boiling water temperatures.
So, although you can't use it as a candy thermometer, or for tracking your oven temperature,
or for monitoring your stock of dry ice or liquid nitrogen, it ought to be suitable for your
refrigerator, freezer, fish tank, water heater, natural hot springs, and whether in most places
where sane human beings might live long term. Another nice thing is that each one has a unique
serial number, so you could monitor several different ones separately from a single Raspberry Pi.
As an aside, my original idea was to use a different sensor, the DHT22 combination
temperature and humidity sensor, which only costs a few dollars more than the DS18B20,
or its minimally exceptional cousin the DHT11, which is pretty much the same thing,
only half as accurate and a little cheaper. I decided against it in this case, because apparently
the method for reading the data off of them is extremely fussy, and especially if you're on a
single core board, and anything else tries to do anything while you're trying to read data off
the sensor, it can easily throw the timing off and cause the read to fail. We aren't really
concerned about humidity for our purpose, so switching to the DS18B20 seems to be a smarter and
much simpler option for this project. You can build a reasonably complete networked
robo thermometer like this, with a Raspberry Pi Zero W kit, temperature sensor parts,
and a suitable enclosure for a total of about $50 US or less at regularamazon.com retail prices.
You can also add additional sensors, of course, but that's a topic for another episode,
and that's it for today. No, seriously, not everything I record has to be an hour-long epic.
You've been listening to Hecker Public Radio at Hecker Public Radio.org. We are a community
podcast network that releases shows every weekday Monday through Friday. Today's show,
like all our shows, was contributed by an HBR listener like yourself. If you ever thought of
recording a podcast, then click on our contributing to find out how easy it really is.
Hecker Public Radio was founded by the Digital Dove Pound and the Infonomicon Computer Club,
and is part of the binary revolution at binrev.com. If you have comments on today's show,
please email the host directly, leave a comment on the website or record a follow-up episode yourself,
unless otherwise status. Today's show is released on the Creative Commons,
Attribution, ShareLite, 3.0 license.
Well, that was nice and short. Maybe too short. It feels like something is missing.
Don't you usually add some sort of allegedly humorous comment after the end music, master?
Oh, Dagnabbit, I knew I was forgetting something.