- Raspberry Pi rev B
- Clear housing
- Tiny Breadboard (for the initial kit - you'll want to solder for final version)
- Breadboard Wires
- Adafruit Cobbler Kit
- DS18B20 temp probe with resistor
- SD card with the newest Raspbian Wheezy build
I got the Wheezy build from here and followed their instructions on how to put it on the SD card in the paragraphs above the download section. Depending on what OS you are using, there are obviously different programs to use.
I hooked the Pi up to a screen, keyboard, mouse and network, stuck the SD card in and, after a little initial setup, i was off and running. I gave it a static by adding these lines to the /etc/network/interfaces file:
iface eth0 inet static
address IP ADDRESS
I commented out the line that said "iface eth0 inet dhcp" because we don't need it for a static. Either one or the other. Now, either restart the Pi or restart the daemon for the network settings to take effect. I've had more luck rebooting....
Following directions from here,
Step One: Updating the Kernel
Next comes wiring the probe and connecting it to the Pi. Using the directions here, I wired it to look similar to this pic:
Obviously, it can be set up any way but it must be connected correctly. I'm talking about using different pins on the breadboard and placement and such.
After that is done and the ribbon cable is connected, I powered the device on. You should feel the probe during this initial power-up. If it gets hot, which it will within seconds, turn it off and check your wiring.
Running these two commands:
Sudo modprobe w1-gpio
sudo modprobe w1-therm
will fire up the probe. These will need to be put in a start-up file upon boot if ever the device is restarted. After those two commands complete, it will be dumping data into a file located at
/sys/bus/w1/devices/SERIAL OF PROBE/
The serial of the probe can be found by doing an "ls" inside the /sys/bus/w1/devices folder. In the pic at the top, I found what that number was and made a yellow label for it since that serial will never change. Easier to label them rather than trying to remember! :)
Running "cat w1_slave" inside that serial folder will produce two lines of output. the very last few digits will be the temperature in Celsius. Its at the thousands place so the python code further down that links page will tell us how to divide by 1k.
The following code is taken from that page with a little tweak at the end to convert it to Fahrenheit:
# Open the file that we viewed earlier so that python can see what is in it. Replace the serial number as before.
tfile = open("/sys/bus/w1/devices/28-00000474e0b1/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperature = temperature / 1000
# Convert Temperature to Fahrenheit
temperature = (temperature * 9) / 5 + 32
# Print Temperature
The 28-00000474e0b1 part in that first line is the serial of MY probe. That will be different for you, of course. Copy and paste that, using your serial number, into a file called temp.py and place it wherever. to run it, type:
and it should return a rounded-like (because of the int() statement) integer that is the Celsius degrees converted to Fahrenheit. The probe works and the temp is being converted. That step is done.
Once we have all that done, we can install SMNPD and get it to respond to queries from a remote machine. This proved to be the most difficult for me because, up until this point, I always piggybacked on an existing SNMP install with the OIDs already there. Building this from scratch was definitely tricky for an SNMP nub like me.
So, taking directions from a lot of places, Ill post links to the most helpful places here.
Following directions from here, I installed SNMPD by running:
sudo apt-get update
sudo apt-get install snmpd
sudo apt-get install snmp
Im not 100% sure if i needed the client portion, but I installed it anyway during troubleshooting steps.
Please be aware that this is for a totally internal setup with no outward facing access therefore its pretty wide open. You'll want to check up on securing your SNMP install if you choose to have it facing the internet.
You'll need to edit your snmpd.conf file by typing:
sudo nano /etc/snmp/snmpd.conf
Here is where it got tricky. I had a line in there that read:
which i commented out and added this line below it:
which I'm assuming from what I read allows for any machine with explicit access to get queries. Then, further down in that config, I found the rocommunity lines. I added these lines:
rocommunity public IP OF REMOTE MACHINE
rocommunity public localhost
not sure if that last one was there or not to begin with. Then commented out:
rocommunity public default -V systemonly
just for good measure! :) it looked like it might have caused a problem. Not sure if it was needed but, again, SNMP newb here. Make sure you restart the daemon to make your changes stick:
sudo /etc/init.d/snmpd restart
once those are done, from the local machine, you should be able to type:
snmpwalk -v 1 -c public localhost
and it will throw a ton of stuff at you from the console. you can also try that same command from a remote machine instead putting in the IP of the Pi rather than localhost and it should do the same thing.
From this moment on it gets a touch more tricky. Getting an OID to match to the temp probe output. remember the temp probe? yeah its been a while....
Continuing to follow the instructions here, you must do a few things which I will list:
- make a script to call the python file we created in the first steps above
- config a new OID inside the snmpd.conf to point to this new script
Easy. Kinda. If you originally knew what you were doing....
I grabbed the executable from that link above and changed it a bit:
if [ "$1" = "-g" ]
copy and paste that above into a file called snmp-temp. Then run this:
sudo chmod 755 snmp-temp
which will make it executable and try running it:
Please notice that I changed the directories where these files are located which you will need to do as well for this to work. If they are all in the same place calling the same files, you should be ok. SNMP likes them to be in that /usr/local/bin directory. i was NOT able to run them out of my home directory where i was originally building these files. i moved both the python scripts and the shell scripts to that location and everything is working fine.
once you run that file, you should get output in three lines:
OUTPUT TEMP FROM PROBE
OUTPUT TEMP FROM PROBE
Now that that is working, we need to add a line to our snmpd.conf file to join that script with that OID. So... Edit the snmpd.conf:
sudo nano /etc/snmp/snmpd.conf
and add this line down where the other "PASS" lines are:
pass .184.108.40.206.220.127.116.11.8.0 /bin/sh /usr/local/bin/snmp-temp -g
Again, please remember that I moved files around to that /usr/local/bin directory.
So.... Now if we run this (either locally or from the remote machine - ill use localhost for this example):
snmpget -v 1 -c public localhost .18.104.22.168.22.214.171.124.8.0
it should return:
iso.126.96.36.199.188.8.131.52.0 = Gauge32: CURRENT TEMP FROM PROBE
So for understanding, this is what happens:
- snmpget goes out via version 1 looking for the public community on localhost for the OID labeled .184.108.40.206.220.127.116.11.8.0
- Once it finds that OID in the snmpd.conf, it runs the associated script called snmp-temp inside /usr/local/bin
- That script calls the python script that actually does all the work; grabbing the output of the probe, parsing all the gibberish and converting it to Fahrenheit.
- snmp-get returns the results of the temp.py into a nicely formatted snmp query that can then be put into any program.
I use nagios to poll a ton of other devices so this was an easy setup inside nagios once the output was generated and the ability to query against it was done.