Jun 082015
 

In the previous post, I got the Raspberry Pi outputting the values from the temperature sensors via SNMP.

In this post, I’ll be configuring Zabbix to monitor and record these values so that I can see how cold it was last night.
You’ll need to note down the OIDs that were configured on the SNMP agent in the last post so you can use them in this post.

Monitoring the Pi

Adding it in

The Raspberry Pi will need to be monitored in some way by Zabbix in order for us to record the temperatures from the SNMP agent that we’ve set up.
You’ll need to add the Raspberry Pi as a host in Zabbix, and give it an IP address under the SNMP interfaces section. I’ve added the SNMP OS Linux template to monitor the rest of the Pi stats, but that’s not required for monitoring temperatures.

Continue reading »

Share
Jun 042015
 

So I got a bit sidetracked from my tear down of the Ritmo CE-3590 NAS, and ended up building a temperature sensor with some DS18B20s and a Raspberry Pi.

Today’s post will detail how I configured the Pi to output the temperature values to the SNMP agent that I’m running on the Pi.

Plugging The Sensors In

Since I used the DS18B20s, they are polled over a single wire with a 4K7 resistor across the VCC and Data wires.
I ended up using a whole bunch of CD Audio cables like this one –
CD Audio Cable
to create the wiring for the sensors. If I had the pins to use between the cables, I could have just joined cables together, but as I didn’t, I cut and soldered multiple cables together. At the end of the wires that will plug into the Pi, I spliced in the 4K7 resistor and heatshrinked it so hopefully it won’t short anything out.
Temp Sensor Wires
It ended up very messy, but it seems to have worked.

I used the Red wire for 3.3V, the white wire as data, and the black as ground.
Red then gets plugged into the Pi header at Pin 1 which is 3.3V power
White gets plugged into Pin 7 which is GPIO 4
Black gets plugged into Pin 6, which is a ground. This could be any of the other grounds, but this is the closest one.

Configuring the Pi

I’m using Raspbian on my Pi, so any instructions are done with a Raspbian flavour. Most distros should have the same setup though.
The Pi needs to be configured to use the w1-gpio device tree overlay (dtoverlay).
This is done by adding the line dtoverlay=w1-gpio to the end of the config.txt file on the /boot partition.
Once this dtoverlay has been activated, you should be able to see your sensors under /sys/devices/w1_bus_master1/. They should appear as 28-0215**. On my Pi, the sensors appear like so –

/sys/devices/w1_bus_master1/28-0215012018ff
/sys/devices/w1_bus_master1/28-021500ce50ff
/sys/devices/w1_bus_master1/28-021500cfceff

Catting one of the w1_slave nodes under the sensor should output something like this –

57 01 55 00 7f ff 0c 10 05 : crc=05 YES
57 01 55 00 7f ff 0c 10 05 t=21437

The YES confirms the sensor is working, and the temperature is displayed after the t=
In this example, the temperature is 21.437 Degrees Celsius. The output needs to be divided by 1000 to get the temperature to the correct amount of decimal places.

Configuring the SNMP agent

With the sensors plugged in, it’s time to extend the SNMP agent to allow us to poll the temperature sensors over SNMP.
I’ve written a script that will output just the temperature to the SNMP agent, I’ve placed this script in /opt/scripts but you’re free to put it wherever you want. You’ll need to keep the location handy for when we extend the SNMP agent.
I’ve named this script gettemp.sh

#!/bin/bash
#
# Usage: gettemp.sh
# e.g. gettemp.sh 28-0215012018ff
SENSOR=$1
SLAVE="/sys/devices/w1_bus_master1/"$SENSOR"/w1_slave"
OUTPUT=$(/bin/cat $SLAVE | /usr/bin/awk -F 't=' ' { printf $2 } ')
echo $OUTPUT

With this script, you should be able to call the script from a command line, and it should output the temperature for that sensor.

# /opt/scripts/gettemp.sh 28-021500ce50ff
21437

With this script operational, we’ll need to setup the SNMP agent to run this script to provide us the output of this script over SNMP.
To do this, we need to modify /etc/snmp/snmpd.conf. At the end of the file, put in this line –
Make sure you replace the sensor id with your own sensor id. If you want to monitor more than one sensor, add more extend lines, and give them differing names, like temp2, temp3, etc.

extend .1.3.6.1.3.1.1 temp1 /bin/bash /opt/scripts/gettemp.sh 28-021500ce50ff

After you modify the snmpd.conf file, make sure you restart SNMP agent with /etc/init.d/snmpd restart or service snmpd restart.

Once the SNMP agent is back up and running, you should be able to poll the OID we specified above (.1.3.6.1.3.1.1) and get the output of the command. I’ve run the snmpwalk on the Pi itself, polling itself.

# snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.3.1.1
iso.3.6.1.3.1.1.1.0 = INTEGER: 1
iso.3.6.1.3.1.1.2.1.2.5.116.101.109.112.49 = STRING: "/bin/bash"
iso.3.6.1.3.1.1.2.1.3.5.116.101.109.112.49 = STRING: "/opt/scripts/gettemp.sh 28-021500ce50ff"
iso.3.6.1.3.1.1.2.1.4.5.116.101.109.112.49 = ""
iso.3.6.1.3.1.1.2.1.5.5.116.101.109.112.49 = INTEGER: 5
iso.3.6.1.3.1.1.2.1.6.5.116.101.109.112.49 = INTEGER: 1
iso.3.6.1.3.1.1.2.1.7.5.116.101.109.112.49 = INTEGER: 1
iso.3.6.1.3.1.1.2.1.20.5.116.101.109.112.49 = INTEGER: 4
iso.3.6.1.3.1.1.2.1.21.5.116.101.109.112.49 = INTEGER: 1
iso.3.6.1.3.1.1.3.1.1.5.116.101.109.112.49 = STRING: "21437"
iso.3.6.1.3.1.1.3.1.2.5.116.101.109.112.49 = STRING: "21437"
iso.3.6.1.3.1.1.3.1.3.5.116.101.109.112.49 = INTEGER: 1
iso.3.6.1.3.1.1.3.1.4.5.116.101.109.112.49 = INTEGER: 0
iso.3.6.1.3.1.1.4.1.2.5.116.101.109.112.49.1 = STRING: "21437"

As you can see from the example, the temperature is output in a couple of different places.
Polling the SNMP agent with one of those locations directly should yield only the temperature.

# snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.3.1.1.4
iso.3.6.1.3.1.1.4.1.2.5.116.101.109.112.49.1 = STRING: "21437"

With that, we now have SNMP set up on the Pi, ready to be polled for the temperature.

Share
May 212013
 

I recently had an email from one of my readers enquiring about making timelapse videos with the Raspberry Pi.

Since I already had a webcam connected to one of my Pis, I set about making it take timelapse shots.
There are a myriad of ways to accomplish this, but I decided to use motion as it took the least configuration to get it to do what I wanted it to do.

Getting motion was as easy as apt-get install motion on my Raspbian powered Pi.
I also needed mencoder to encode the resulting images into a video. Mencoder is also found in the repositories, so a quick apt-get later and I also had mencoder installed.

In order to get timelapse shots, I had to setup motion to take pictures at intervals.
On line 295 in the default motion.conf, there is this following line

snapshot_interval 0

Change that to the number of seconds between each snapshot.

snapshot_interval 5

I’m also allowing remote access to the webcam so that I can check in on it.
On lines 413 and 429, change the webcam_localhost and control_localhost to off.

After changing those, I restarted the motion daemon for the changes to take effect.
Once motion is started, you will start seeing files in /tmp/motion (or wherever you decided to save the files)
The ones ending in -snapshot.jpg are the ones that we will be using for the timelapse movie.
If you have motion detection activated, you will see other files in the directory but we can ignore those.

To create the movie, we are going to use mencoder. This part could also be done with ffmpeg, which I may cover in a later post.
I wrote up a small script to run the mencoder command –

#!/bin/bash
mencoder mf:///tmp/motion/*-snapshot.jpg -mf w=320:h=240:fps=25:type=jpg -ovc copy -oac copy -o output.avi

The resolution (-mf w=320:h=240) should match the resolution setup in motion.
When the script is run, it will take all files in /tmp/motion/ that end in -snapshot.jpg and make a movie out of them. The output file is set by the -o switch, in this case I’ve used output.avi.
Setting this script to run once a minute for example, will keep the timelapse video up-to-date to the last minute.

Once the file has been created, you’ll be able to view the file on another computer very easily.
The only issue with this timelapse movie, is that it will keep getting longer and longer and longer, as there is nothing cleaning up the old files.

So what we’ll do, is add an extra line into the script to remove any files older than a certain time, and that way we can control the length of the timelapse movie.
If we wanted to make the timelapse movie 10 minutes only, we’d add the following line before the mencoder line

find /tmp/motion -name "*.jpg" -type f -mmin +10 -delete

Resulting in this

#!/bin/bash
find /tmp/motion -name "*.jpg" -type f -mmin +10 -delete
mencoder mf:///tmp/motion/*-snapshot.jpg -mf w=320:h=240:fps=25:type=jpg -ovc copy -oac copy -o output.avi

That way, whenever the script is run, we’ll have a 10 minute long timelapse video !

Share
May 162013
 

So lately, I’ve been trying to use one of my Raspberry Pis as a WiFi bridge.
That is connecting the Pi to a WiFi network, and sharing it out via the ethernet port.
I was trying to do that with the RT5370 USB sticks that I was also using to broadcast hotspots.

With the default drivers in Raspbian however, trying to add wlan0 to a bridge results in this message

can't add wlan0 to bridge br0: Operation not supported

According the the drivers, wlan0 can’t do it.
The only way to add the RT5370 NIC to a bridge is to activate 4addr (4 address frame) mode.

iw wlan0 set 4addr on

However, once 4addr mode is on, traffic between the WiFi device and the AP seemed to stop altogether.

The solution to this issue, is to use the RALink drivers. The vendor drivers does not seem to use the Linux WiFi stack however, which means that those drivers can not be used to broadcast a hotspot using hostapd. So if you’re using a Pi as a WiFi repeater, you may have issues there, though that will be something I’m going to experiment with later as well.

Preparation

Before we can actually compile the drivers, we’re going to need to grab the kernel sources.
I’m using Raspbian Server Edition, which uses the 3.6.11+ kernel. We’ll need the matching source from github.
We’ll change to the /usr/src directory first, then wget the sources from github, and then untarball it with these commands.

*Note* I’m doing it as root, so you can either prepend sudo to these commands, or run sudo bash before running these commands.

cd /usr/src
wget https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz
tar -xvzf rpi-3.6.y.tar.gz

Once the source is extracted, we’ll need to copy the current kernel configuration into the source directory.

cd linux-rpi-3.6.y
gzip -dc /proc/config.gz > .config

And then we need to create the files and symlinks neccesary for compiling external modules

make modules_prepare
ln -s /usr/src/rpi-3.6.y /lib/modules/3.6.11+/build

Compiling the Vendor drivers

In order to use the Vendor drivers, first we’ll need to get them.
The drivers can be found here.
Download the ones for the RT5370 and transfer it to the Pi as we’ll need to compile the drivers ourselves.

Once we have the drivers on the Pi, we’ll move them to /usr/src and untar them to keep things nice and neat. Assuming the drivers are in /home/pi
*Note* Again I’m doing everything as root.

mv /home/pi/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2 /usr/src
cd /usr/src
tar -xvjf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2
cd 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0

Once it’s untarred, we’ll need to edit the file ‘os/linux/config.mk’ to enable WPA support and to allow network managers to control the device.
So find these lines, and change the n to y, then save and close the file.

HAS_WPA_SUPPLICANT=n
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n

Now, we should still be in the /usr/src/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0/ directory.
Time to compile the drivers !
To compile them, we just need to run the ‘make’ command in the drivers directory as root.
It took me just shy of 12 minutes to compile the drivers on a Class 4 SD Card on a non-overclocked pi.
Once they are compiled, running ‘sudo make install’ will install the drivers into the right spot

To make sure the drivers are installed properly, we’ll load the module to make sure no errors come up.
*Note* Run this as root again

modprobe rt5370a

If no errors come up, then that’s a good sign. Check that it’s been loaded by running lsmod and checking the output.

root@raspberrypi:/home/pi# lsmod
Module Size Used by

rt5370sta 786186 0

You should see the module rt5370sta in the list there.
Lastly we’ll disable the rt2800 usb module and enable autoloading of the new rt5370sta module.
We’ll need to edit /etc/modprobe.d/raspi-blacklist.conf and add the following line to the end

blacklist rt2800usb

And then we’ll need to edit the /etc/modules file to add the new module we’ve just compiled. Just need to add the module name to the end of the file

rt5370sta

After the file has been modified, reboot the Pi and when it comes back up, run ifconfig -a and you should see something similar to the following –

eth0 Link encap:Ethernet HWaddr b8:27:eb:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:354 errors:0 dropped:0 overruns:0 frame:0
TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30609 (29.8 KiB) TX bytes:25948 (25.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ra0 Link encap:Ethernet HWaddr 00:0f:54:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:854641 (834.6 KiB) TX bytes:44800 (43.7 KiB)

Notice the ra0 rather than wlan0. This shows that the Pi is using the new rt5370sta module rather than the old rt2800usb one. You can still use the ra0 interface to connect to wireless networks like normal.

Share
Apr 242013
 

Another update to PiParted

Fixed up non-appearing SD Cards
Also added a backup option, at the moment it can only backup ~4GB SD Cards as it reads it to ram for now. Your computer will also need at least 4 GB of ram to backup the SD Card.

Grab it here !

SHA1 Hash – 2fa25e4f9e9260a3612129a1b0291fca3e3fd628 PiParted-0.04.iso

Comments / feedback would be very welcome !

Share