Aquaponics pH to 1-Wire Converter – Part 1

Aquaponics systems need a good water quality, and one of the parameters is pH value, which needs to be within a certain range in order for the fish and plants to thrive. This is of course also true for fish-only aquariums, but since I have an aquaponics system set up already, this is what I’ll focus on. There are a few pictures of the system in this blog post: Debian on NSLU2 With USB Hard Disk and Homeplug Network (I’m using a Debian NSLU2 but it should be possible to use an Unslung NSLU2 too).

The small NSLU2 computer has a USB connector and with a DS9490R 1-Wire to USB adapter it’s easy to collect data from a 1-Wire unit onto a hard disk. Then I just need a pH-to-1-Wire adapter, which is what I want to build and describe in the upcoming blog posts. A 1-Wire bus has a much longer reach than a USB bus and that is very convenient for many purposes.

I’m going to build a circuit with the following specifications that will interface to a common pH probe immersed in the aquaponics water:

Input

  • BNC connector
  • High impedance
  • 0.059 V / pH unit
  • 12 VDC power supply

Output

  • RJ12 connector
  • 1-Wire

The block diagram for the circuit looks like this:

Most of the circuit is originally described at 66pacific.com.

BNC Connector

The pH probe that is supposed to be connected to the voltage amplifier only sends out 0.059 V per pH unit and using a coax cable will keep out noise. Coax cable naturally terminates in a BNC connector.

Voltage Amplifier

The small signal from the pH probe is amplified so that it matches a commonly available A/D converter.

Ground Reference

The voltage signal coming from the pH probe is both positive (pH < 7) and negative (pH > 7). Since the power supply for the circuit is from an ordinary 12 VDC mains adapter and the signal is going to an A/D converter, the ground reference for the voltage amplifier is raised to ensure positive voltages only for the converter, assuming that a normal one is only able to handle positive voltages.

A/D Converter

Converts the amplified analog voltage to a digital value and makes it available on the 1-Wire bus.

RJ12 Connector

A common type of connector for the 1-Wire bus. Only 2 pins are used although 6 are available. The pinout is shown on this page: RJ12 Pinout

Voltage Regulator

This block improves the quality of the supply voltage, which makes it possible to use many different generic mains adapters.

DC Connector

A generic low voltage coaxial power connector commonly used on mains adapters.

The next step is to draw the schematic with all the circuit components. Comments and suggestions are welcome in the comments section below.

Linux Scripts for RainWise 1-Wire Rain Gauge

After the first successful test of my RainWise rain gauge it’s time to automatically generate graphs showing the amount of rainfall versus time.

First I log into my NSLU2 via SSH:

$ ssh 192.168.1.xx

$ uptime
 16:07:28 up 14 days,  3:07,  1 user,  load average: 0.10, 0.06, 0.01

I can’t help checking the uptime when I log in. I’m still amazed by how little maintenance this small NSLU2 computer requires. This is usually the case with Linux servers, but on top of that is has low power consumption and small form factor – I almost forget that it’s there.

Generation of graphs happens automatically so before making any changes to the scripts, I prefer disabling the automatic scripts. This is done via Debian crontab, and I just put a ‘hash’ or number sign (#) in front of the command lines to comment them out:

$ crontab -e

# m h  dom mon dow   command
# */5 * * * * /home/thomas/rrdtool/update_database.sh &> /dev/null
# */5 * * * * /home/thomas/rrdtool/upload_graphs.sh

Once you have done a crontab edit with the -e option, you can view crontab commands as they are at the moment with the -l option for crontab list. You can format crontab listings as explained in the first line with the ‘hash’. I’m using the nano editor when editing crontab.

I want to generate graphs based on the rain data and for that I need a data set in the RRDtool database. The old database is deleted and the rain parameter is added to the database generation script:

$ cd /home/thomas/rrdtool/
$ rm database.rrd
$ nano create_database.sh 

#!/bin/bash
rrdtool create database.rrd --start N --step 300 \
DS:airtemp:GAUGE:600:U:U \
DS:soiltemp:GAUGE:600:U:U \
DS:soilmoist:GAUGE:600:U:U \
DS:rain:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:12 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:12:168 \
RRA:AVERAGE:0.5:12:720 \
RRA:AVERAGE:0.5:288:365

In order to generate the database.rrd file the script is executed:

$ ./create_database.sh

The main script of the measurement logging system is the update_database.sh script (see below).

There’s no formatting of the counter data from the circuit inside the rain gauge. The rainread variable is used directly in calculations. I have created a file called rain_count.txt, which contains the counter value as it was 5 minutes ago. This is the time between each execution of the script, so the old value is in a file, and the new value is read from the 1-Wire counter. When these two values are subtracted you get the amount of rain in the last 5 minutes, but it’s in ticks, or number of buckets. Each tick represents 0.25 mm of rain, and multiplied with the number of ticks, you get the total amount of rain in [mm]. Note that when you’re doing math in a Linux script, you can make up names for your variables, like rainbuckets, but when you want to use the content of a variable you have to use the dollar sign, like $rainbuckets, or else it will be interpreted as the text ‘rainbucket’. It doesn’t make sense to multiply a number with a text (apples and bananas).

After the old value in the text file has been used in the calculations, the old value is replaced by the new value, to be used for the next calculation coming up in 5 minutes.

A few lines have been added to produce the rain graphs.

$ nano update_database.sh 

#!/bin/bash
cd /home/thomas/rrdtool

# Read data from sensors
airtempread=`cat /home/thomas/owfs/10.4F7494010800/temperature`
soiltempread=`cat /home/thomas/owfs/10.06A394010800/temperature`
soilmoistread=`cat /home/thomas/owfs/30.6A1E62120000/current`
rainread=`cat /home/thomas/owfs/1D.50E00D000000/counters.B`

# Format readings
airtemp=`echo $airtempread | cut -c -4`
soiltemp=`echo $soiltempread | cut -c -4`
soilmoist1=`echo $soilmoistread | cut -c -7`

# Calculate soil moisture
drylimit=0.1394
wetlimit=1.338
range=`echo "$wetlimit-$drylimit" | bc`
a=`echo "(-1)*$soilmoist1" | bc`
b=`echo "$a-$drylimit" | bc`
c=`echo "scale=3; $b/$range" | bc`
d=`echo "100*$c" | bc`
soilmoist=`echo $d | cut -c -5`

# Calculate rain
a=`cat /home/thomas/rrdtool/rain_count.txt`
rainbuckets=`echo "$rainread-$a" | bc`
rain=`echo "0.25*$rainbuckets" | bc`
echo $rainread > /home/thomas/rrdtool/rain_count.txt

# Update database
rrdtool update database.rrd N:$airtemp:$soiltemp:$soilmoist:$rain

# Create graphs
#0000FF = blue trace color
#CC6600 = brown trace color

rrdtool graph temp_h.png -y 2:1 --vertical-label "[deg C]" \
--start -1h DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_d.png -y 2:1 --vertical-label "[deg C]" \
--start -1d DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_w.png -y 2:1 --vertical-label "[dec C]" \
--start -1w DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_m.png -y 2:1 --vertical-label "[dec C]" \
--start -1m DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph temp_y.png -y 2:1 --vertical-label "[dec C]" \
--start -1y DEF:airtemp=database.rrd:airtemp:AVERAGE \
DEF:soiltemp=database.rrd:soiltemp:AVERAGE \
LINE1:airtemp#0000FF:"Air temperature [deg C]" \
LINE1:soiltemp#CC6600:"Soil temperature [deg C]"

rrdtool graph soil_moisture_h.png --vertical-label "[%]" \
--start -1h DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_d.png --vertical-label "[%]" \
--start -1d DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_w.png --vertical-label "[%]" \
--start -1w DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_m.png --vertical-label "[%]" \
--start -1m DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph soil_moisture_y.png --vertical-label "[%]" \
--start -1y DEF:soilmoist=database.rrd:soilmoist:AVERAGE \
LINE1:soilmoist#CC6600:"Soil moisture"

rrdtool graph rain_h.png --vertical-label "[mm/5 min]" \
--start -1h DEF:rain=database.rrd:rain:AVERAGE \
LINE1:rain#0000FF:"Rain"

rrdtool graph rain_d.png --vertical-label "[mm/5 min]" \
--start -1d DEF:rain=database.rrd:rain:AVERAGE \
LINE1:rain#0000FF:"Rain"

rrdtool graph rain_w.png --vertical-label "[mm/5 min]" \
--start -1w DEF:rain=database.rrd:rain:AVERAGE \
LINE1:rain#0000FF:"Rain"

rrdtool graph rain_m.png --vertical-label "[mm/5 min]" \
--start -1m DEF:rain=database.rrd:rain:AVERAGE \
LINE1:rain#0000FF:"Rain"

rrdtool graph rain_y.png --vertical-label "[mm/5 min]" \
--start -1y DEF:rain=database.rrd:rain:AVERAGE \
LINE1:rain#0000FF:"Rain"

Finally, the graph upload script has been updated to include the new graphs:

$ nano upload_graphs.sh 

#!/bin/bash
sleep 30
lftp -u USER,PASSWORD SERVER <<EOF
cd /temp/
lcd /home/thomas/rrdtool/
put temp_h.png
put temp_d.png
put temp_w.png
put temp_m.png
put temp_y.png
put soil_moisture_h.png
put soil_moisture_d.png
put soil_moisture_w.png
put soil_moisture_m.png
put soil_moisture_y.png
put rain_h.png
put rain_d.png
put rain_w.png
put rain_m.png
put rain_y.png
quit 0
EOF

When the changes have been made the crontab job is activated again:

$ crontab -e

# m h  dom mon dow   command
*/5 * * * * /home/thomas/rrdtool/update_database.sh &> /dev/null
*/5 * * * * /home/thomas/rrdtool/upload_graphs.sh

If you want to inspect your RRDtool database manually you can use rrdtool with the fetch option, which is useful if you want to check if data is stored properly in the database. I used this when I was debugging my script:

$ rrdtool fetch database.rrd AVERAGE

The output looks something like this:

            airtemp        soiltemp       soilmoist        rain
...
1324218600: 1.0633744190e+00 3.6800000000e+00 4.6966255810e+01
3.9866799250e+00
...
1324289100: nan nan nan nan
...

This is the resulting graph showing the amount of rainfall versus time:

This shows a small test I did while I was outside gardening, so I’m looking forward to see some real weather data.

I’m still a bit confused about what unit I should put on the Y axis. The normal rainfall graphs I’ve seen is actually bar charts, where each bar represents 1 hour or perhaps 6 hours of rainfall, with only [mm] as units on the Y axis. I wouldn’t say that my graph is wrong, just that my bars are extremely thin, but they do indeed only cover 5 minutes each, and are actually reduced to a 1 pixel wide vertical line. Maybe the ‘/5 min’ can be removed. The problem is that I don’t know enough about RRDtool to make bar charts, but if you have knowledge about this, please leave a comment below – or any other thoughts that you want to share.

Anyway, the rainfall graph is fun to watch, and even if the values are not absolute, it will give you an idea about what’s going on in the garden. It will be interesting to compare with the soil moisture graph and see how the soil responds to rain.

The next natural step would be to connect a sprinkler to the NSLU2 and let it control the soil moisture to provide the best growing conditions for plants, and not just do measurements. This is something I’ve been rambling about for years, so let’s see when, or if, that happens ;-) I do have an aquaponics setup that needs electronic pimping too…

First Test of RainWise 1-Wire Rain Gauge

It’s time to connect the RainWise rain gauge to the rest of the 1-Wire system. (Check out my last blog post for pictures of the rain gauge: 1-Wire Rain Gauge Pictures )

Since my NSLU2 1-Wire system is running 24/7 I had to log in and shut it down before making any changes to the bus (IP address is hidden for paranoia security reasons):

$ ssh 192.168.1.xx
Linux LKGB5E3E5 2.6.26-2-ixp4xx #1 Mon Jun 13 20:24:52 UTC 2011
armv5tel

$ uptime
 09:55:39 up 14 days, 14:37,  1 user,  load average: 0.44, 0.16, 0.05

$ su
# halt

The uptime command shows that the NSLU2 has been running continuously for 14 days which is pretty cool, since I haven’t touched it at all, just letting it log data from the sensors and draw graphs.

I bought the rain gauge years ago but the internal battery was still okay and showed a voltage of 3.11 V to be used for the counter memory. I connected the 1-Wire to the USB adapter and turned on the NSLU2. (You could probably just unplug the USB adapter and then make the changes to the 1-Wire bus, but I’m not sure how OWFS would behave afterwards, so I powered down the NSLU2 in order to keep the test as simple as possible).

OWFS had to be started again after a reboot. This can be done automatically, I just have to figure out how ;-) . Fortunately OWFS initialized perfectly with the new 1-Wire rain gauge connected to the bus (although it was the only unit connected in order to make a simple test):

$ su
# /opt/owfs/bin/owfs --allow_other -u /home/thomas/owfs
DEFAULT: ow_usb_msg.c:DS9490_open(276) Opened USB DS9490 bus master
at 1:4.

DEFAULT: ow_usb_cycle.c:DS9490_ID_this_master(191) Set DS9490 1:4
unique id to 81 59 25 27 00 00 00 CE

# exit

Rushing into the OWFS directory to check if the rain gauge showed up: Yep, it’s there alright! 1D.50E00D000000 is a new unit:

$ cd owfs

$ ls -la
total 4
drwxr-xr-x 1 root   root      8 Dec  3 10:17 .
drwxr-xr-x 7 thomas thomas 4096 Sep 28 13:36 ..
drwxrwxrwx 1 root   root      8 Dec  3 10:18 1D.50E00D000000
drwxrwxrwx 1 root   root      8 Dec  3 10:18 81.592527000000
drwxr-xr-x 1 root   root      8 Dec  3 10:17 bus.0
drwxr-xr-x 1 root   root      8 Dec  3 10:17 settings
drwxr-xr-x 1 root   root      8 Dec  3 10:17 statistics
drwxr-xr-x 1 root   root     32 Dec  3 10:17 structure
drwxr-xr-x 1 root   root      8 Dec  3 10:17 system
drwxr-xr-x 1 root   root      8 Dec  3 10:17 uncached

Checking the contents of the new unit / directory:

$ cd 1D.50E00D000000/

$ ls -la
total 0
drwxrwxrwx 1 root root   8 Dec  3 10:18 .
drwxr-xr-x 1 root root   8 Dec  3 10:17 ..
-r--r--r-- 1 root root  16 Dec  3 10:17 address
-rw-rw-rw- 1 root root 256 Dec  3 10:17 alias
-r--r--r-- 1 root root  12 Dec  3 10:18 counters.A
-r--r--r-- 1 root root  25 Dec  3 10:18 counters.ALL
-r--r--r-- 1 root root  12 Dec  3 10:18 counters.B
-r--r--r-- 1 root root   2 Dec  3 10:17 crc8
-r--r--r-- 1 root root   2 Dec  3 10:17 family
-r--r--r-- 1 root root  12 Dec  3 10:17 id
-r--r--r-- 1 root root  16 Dec  3 10:17 locator
-rw-rw-rw- 1 root root 512 Dec  3 10:17 memory
-rw-rw-rw- 1 root root  12 Dec  3 10:18 mincount
drwxrwxrwx 1 root root   8 Dec  3 10:18 pages
-r--r--r-- 1 root root  16 Dec  3 10:17 r_address
-r--r--r-- 1 root root  12 Dec  3 10:17 r_id
-r--r--r-- 1 root root  16 Dec  3 10:17 r_locator
-r--r--r-- 1 root root  32 Dec  3 10:17 type

The counters.A file is empty but counters.B contains the data:

$ cat counters.A
           0

$ cat counters.B
        2091

Apparently the reed switch was activated 2091 times since production ;-)

I flipped the small white internal rain bucket a couple of times and verified that the counter is actually working:

$ cat counters.B
        2093

The .ALL register / file holds both the A and B counter:

$ cat counters.ALL
           0,        2095

After this small test of the counters I installed the rain gauge outside in a garden bed:

I’m pretty sure this is the first time I have appreciated the cold December rain :-D Gotta do some testing, right?

With really cold hands from the wiring job outside I turned on the NSLU2 again, and what a relief – all the 1-Wire units were up and running in the OWFS directory:

$ cd owfs

$ ls -la
total 4
drwxr-xr-x 1 root   root      8 Dec  3 13:12 .
drwxr-xr-x 7 thomas thomas 4096 Sep 28 13:36 ..
drwxrwxrwx 1 root   root      8 Dec  3 13:12 10.06A394010800
drwxrwxrwx 1 root   root      8 Dec  3 13:12 10.4F7494010800
drwxrwxrwx 1 root   root      8 Dec  3 13:12 1D.50E00D000000
drwxrwxrwx 1 root   root      8 Dec  3 13:12 30.6A1E62120000
drwxrwxrwx 1 root   root      8 Dec  3 13:12 81.592527000000
drwxr-xr-x 1 root   root      8 Dec  3 13:12 alarm
drwxr-xr-x 1 root   root      8 Dec  3 13:12 bus.0
drwxr-xr-x 1 root   root      8 Dec  3 13:12 settings
drwxrwxrwx 1 root   root      8 Dec  3 13:12 simultaneous
drwxr-xr-x 1 root   root      8 Dec  3 13:12 statistics
drwxr-xr-x 1 root   root     32 Dec  3 13:12 structure
drwxr-xr-x 1 root   root      8 Dec  3 13:12 system
drwxr-xr-x 1 root   root      8 Dec  3 13:12 uncached

Things tend to get a bit harder when you have to build electronics outside in the rain with mud everywhere. If any of the outdoor sensors are going to be moved I have to find an easier and more robust way of connecting the 1-Wire units together. It is easier to use terminal strips compared to soldering and heat shrink, but you still have to provide some weather protection. There’s probably some better solution out there that will cost me a fortune.

Anyway, the counter in the rain gauge tells us that the internal measuring cup flipped several times during the installation in the garden (it was 2095 before installation):

$ cd 1D.50E00D000000/
$ cat counters.B
        2109

Just for fun I slowly emptied a cup of water into the rain gauge, and I could clearly hear the internal cup flipping from side to side:

$ cat counters.B
        2135

Now that I’m confident that the rain gauge is properly set up and working it’s time to pack up the tools, go back inside and come up with a script that will create a nice graph showing how much it rains as time goes by.

1-Wire Rain Gauge Pictures

This is the newest addition to my 1-Wire system: A rain gauge from RainWise, with Hobby-Boards.com electronics inside.

Picture of rain gauge:

Rain gauge, RainWise

I bought this several years ago when I began my gardening frenzy, but never had a chance to install it before now. Well, of course I had, but I think my basic 1-Wire system had to mature a bit first, which it has and it’s running very well now, so it’s time to add more to the system.

The rain gauge has a filter at the bottom to keep leaves out of the internal mechanics:

Rain gauge, RainWise, filter

I like the fact that the whole thing is black, which I hope will cause any snow to melt in the heat absorbed from the sun, so that snow will be counted as precipitation too. After all, it is falling down from the sky too, which is what I want to measure. It will probably eat hail too.

The rain gauge consists of a long 1-Wire cable, a white plastic cup with two compartments, adjustment screws and a PCB:

Rain gauge, RainWise, parts

The amount of rain is measured by registering how many times one of the compartments of the white cup is filled. Each time a compartment is filled, the cup tips over and creates a pulse with a reed switch.

Rain gauge, RainWise, cup, reed magnetic switch

The reed switch is connected to a PCB with a counter and a backup battery. The PCB also takes care of the 1-Wire communication:

Rain gauge, RainWise, PCB, battery

Rain gauge, RainWise, PCB secondary side

I want to connect this rain gauge to my existing Debian NSLU2 1-Wire system to be able to add more data to my RRDtool graphs.

If you want to see a really complex 1-Wire system you should definitely check out the house monitoring project made by Silvano Gai at http://ip6.com/projects/.

How to Calculate the Calibration of Watermark Moisture Sensors for Soil

My 1-Wire Watermark soil moisture sensor board from Hobby-Boards generates a negative number ranging from -1.338 when fully wet to -0.1394 when totally dry. These are the limits and normal everyday readings fall in between these limits.

I already had a basic script installed on my NSLU2 in order to find the limits to be used for calibration, so I just need to update the calculation section with the limits and the necessary math to get a readout in percent instead [%]:

# Calculate soil moisture
drylimit=0.1394
wetlimit=1.338
range=`echo "$wetlimit-$drylimit" | bc`
a=`echo "(-1)*$soilmoist1" | bc`
b=`echo "$a-$drylimit" | bc`
c=`echo "scale=3; $b/$range" | bc`
d=`echo "100*$c" | bc`
soilmoist=`echo $d | cut -c -5`

The original script called update_database.sh is shown in this post: Watermark Soil Moisture Sensor Probe Calibration

With this new modification the soil moisture graph will now show the data in percent:

It shows a remarkably steady low moisture content, but again, it hasn’t rained for days, perhaps even weeks, so for now I trust that this graphs is telling the truth. Time will tell if the system is stuck at this level, or if the rain will be able to change the curve.

1-Wire USB on a Long Ethernet Cable

Units on 1-Wire bus must be connected in a daisy chain, which means you’ll have a lot of different connection points along the bus cable, in my case an ordinary Ethernet cable. This has been a problem for me earlier since my cable was placed outdoors for air and soil temperature measurements, and soil moisture measurements. I actually need a connection point to the 1-Wire bus at each unit I connect to the cable, because of the daisy chain topology. In order to make these connections somewhat weatherproof I chose to solder any cable joints together and cover it with heat shrink. This has worked well and my old outdoor system collected data for almost a year, before I took it down again when I had to move to another house.

But the soldered joints also gave me problems, because it was hard to make adjustments afterwards, like moving a unit, because the cables would have a fixed length, or taking a unit indoors for repair. This can of course be solved by investing in high quality outdoor enclosures for each unit or cable joint but since this weather data collection project is a hobby there not any immediate return on this relatively large investment. However, if you are getting paid to build this, you should be aware that the system would have a much longer lifetime if you mount the units and joints in a weather proof enclosure. But let’s stick with the hobby type of project for a while.

I wanted to make it easier to modify the physical setup of the system, and one of the easiest ways to connect wires is by using terminal strips:

(There’s a DS18S20 1-Wire IC wrapped in heat shrink to the left in the picture.)

The 1-Wire bus uses only 2 wires (?…) for communication and power transfer. (I guess the name is referring to the communication part.)

A small test showed that the bus worked just fine through the terminal strip (and 17 m ~ 56 ft of Ethernet cable), which makes my life a whole lot easier, as I’m now able to modify the physical setup in many ways, without going outside with my soldering iron in the middle of the snow to replace a unit – brrr… Just bring a screwdriver.

For soil temperature measurements I have glued a DS18S20 temperature sensor onto an aluminium sheet. Note the two cables due to the daisy chain topology:

I assume that the metal sheet will give a good average temperature as is has some mass and therefore filters out high frequency temperature changes. The large area helps averaging the temperature too.

This is all of the components in the 1-Wire system so far:

  • To the left: DS18S20 temperature sensor, for air temperature measurements
  • Aluminium sheet: DS18S20 temperature sensor, for soil temperature measurements
  • In the middle: DS2760 PCB, for soil moisture measurements
  • To the right: Watermark soil moisture probe

The DS2760 PCB has been installed in my previous garden, in a cheap plastic enclosure, wrapped in a plastic bag, but the PCB survived for several months in all kinds of weather. It still looks new with no corrosion at all. The plastic enclosure has changed color due to sunlight:

I’ll also be using terminal strips for this unit and see what happens regarding corrosion.

The soil moisture sensor part of this system is a bit special because the circuit board needs 12 volts to function, which I’m injecting into the Ethernet cable using the brown wire pair, next to the 1-Wire bus carried by the blue wire pair. The extra voltage is generated by a generic mains adapter, protected by a fuse (red and black wires in the picture below):

I have mounted the sensor for air temperature measurements on a stick and covered the sensor with a small cap with tin foil on it to reflect the sun:

I also need a barrier between the soil and the soil temperature sensor (hopefully this is not a biodegradable plastic bag ;-) ):

The soil moisture sensor circuit is tied to a stick and covered with a plastic bag to provide some protection from the weather:

Again, if you want a more reliable setup you should use a weather proof enclosure, but I haven’t experienced any problems so far, although it would be an obvious upgrade to make in the future.

The NSLU2 is placed indoors to protect it against the weather, but I have to get the signals and power outside to the sensors, so I have to go through the window. Since this is a rented house I don’t want to drill large holes in the window frame, so I have removed the extra four wires in the Ethernet cable to be able to close the window without cutting any wires accidentally. Using two different sizes of heat shrink I’m able to make a pretty discreet transition from the indoor to the outdoor environment:

There was already a not so neat looking satellite coax cable going through a hole in the window frame, so adding an Ethernet cable is not big deal, although it’s beginning to look messy:

Rather discreet looking 1-Wire cable outside (the two cables in the top are existing coax cable for satellite):

I have dug a 25 cm (10″) deep hole in the ground for the Watermark soil moisture sensor and the temperature sensor on the aluminium sheet, and once I have calibrated the soil moisture sensor the hole will be filled with soil again and the system will collect data over the winter:

The air temperature sensor is also in place and ready to collect data:

Now I’m going to work on the OWFS software setup on my Debian NSLU2.

Automatic File Transfer From NSLU2 to Server

My NSLU2 is generating new temperature graphs every 5 minutes from a network of 1-Wire sensors, but since it doesn’t have a connector for a screen I can’t look at the graphs unless I transfer the image files to my PC. Because my PC is sometimes turned off (scary stuff, I know ;-) ) I have to program the NSLU2 to transfer the files to an ‘always on’ server, and then from there download the graphs to my PC for analysis.

In order to program the NSLU2 I log in from my PC via my local network:

(Replace xx with the actual IP address of the NSLU2)

$ ssh thomas@192.168.1.xx

I put the instructions for the NSLU2 in a script called upload_graphs.sh:

$ cd /home/thomas/rrdtool/

$ nano upload_graphs.sh

nano is a standard terminal text editor, and these are the commands that goes into the script:

#!/bin/bash
sleep 30
lftp -u USER,PASSWORD SERVER <<EOF
cd /temp/
lcd /home/thomas/rrdtool/
put temp_h.png
put temp_d.png
put temp_w.png
put temp_m.png
put temp_y.png
quit 0
EOF

I immediately pause the script for 30 seconds to let the graph update script finish first before uploading the graph files.

lftp is an FTP client, and cd means changing directory on the FTP server, whereas lcd is a local change of directory.

On a standard NSLU2 Debian installation lftp has to be installed before running the script:

($ means I’m working as a standard user, and # means superuser)

$ su
# apt-get install lftp
# exit

The permission settings must be changed to ‘executable’ to allow the new script to execute:

$ chmod +x upload_graphs.sh

Test the script with a single run to see if it’s working correctly:

$ ./upload_graphs.sh

before adding it to the crontab:

$ crontab -e

This line in the crontab list will execute the upload script every 5 minutes:

*/5 * * * * /home/thomas/rrdtool/upload_graphs.sh

Check if crontab has been updated correctly:

$ crontab -l
# m h  dom mon dow   command
*/5 * * * * /home/thomas/rrdtool/update_database.sh &> /dev/null
*/5 * * * * /home/thomas/rrdtool/upload_graphs.sh

Both the graph generation script and the upload script have now been installed as regular jobs to be run every 5 minutes.

Note: I realize that having your user name, password and server name in an lftp script is not very secure, so if you have a better way of doing this, please leave a comment below.

How to Use RRDtool on Debian NSLU2 to Capture Temperature Data

I have a 1-Wire temperature sensor IC connected to my small Debian NSLU2 computer and in order to analyze the temperature data generated I’m using a program called RRDtool:

RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data.

– Tobi Oetiker

RRDtool is able to make all sorts of graphs for different kinds of data but for now I just need to use it for a single temperature sensor measuring in degrees Celsius.

I start by logging into the NSLU2 from my laptop computer (replace .xx with the address of the NSLU2 on the intranet):

$ ssh thomas@192.168.1.xx

and make a directory for rrdtool, and write a script that will create a basic rrdtool database:

(Note that $ in front of command means I’m working as a normal user, and # means I’m working as super user)

$ cd /home/thomas
$ mkdir rrdtool
$ cd /home/thomas/rrdtool
$ nano create_database.sh

This is what goes into the script:

#!/bin/bash
rrdtool create database.rrd --start N --step 300 \
DS:temp:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:12 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:12:168 \
RRA:AVERAGE:0.5:12:720 \
RRA:AVERAGE:0.5:288:365

After the script has been saved you’ll need to change the permissions setting of the file to make it executable:

$ chmod +x create_database.sh

rrdtool is already available in the Debian package system – you just need to install it with apt-get:

$ su
# apt-get install rrdtool
# exit

When you run the script it will create a file called database.rrd which contains the rrdtool database:

$ ./create_database.sh

A directory listing shows that the database file was created:

$ ls -la
total 28
drwxr-xr-x 2 thomas thomas  4096 Sep 15 18:50 .
drwxr-xr-x 6 thomas thomas  4096 Sep 15 17:49 ..
-rwxr-xr-x 1 thomas thomas   208 Sep 15 17:52 create_database.sh
-rw-r--r-- 1 thomas thomas 13764 Sep 15 18:50 database.rrd

The database has to be updated regularly and the commands for that can be collected in another script that I choose to name update_database.sh:

$ nano update_database.sh

The update script takes care of three things:

  1. Reading the temperature value from the sensor, and formatting the reading
  2. Updating the database file
  3. Creating, or updating, image files containing temperature graphs

This is the code for the script:

#!/bin/bash
cd /home/thomas/rrdtool

# Read temperature from sensor
tempread=`cat /home/thomas/owfs/10.4F7494010800/temperature` 

temp=`echo $tempread | cut -c -4`

# Update database
rrdtool update database.rrd N:$temp

# Create graphs
rrdtool graph temp_h.png --start -1h DEF:temp=database.rrd:temp:AVERAGE LINE1:temp#0000FF:"Temperature [deg C]"
rrdtool graph temp_d.png --start -1d DEF:temp=database.rrd:temp:AVERAGE LINE1:temp#0000FF:"Temperature [deg C]"
rrdtool graph temp_w.png --start -1w DEF:temp=database.rrd:temp:AVERAGE LINE1:temp#0000FF:"Temperature [deg C]"
rrdtool graph temp_m.png --start -1m DEF:temp=database.rrd:temp:AVERAGE LINE1:temp#0000FF:"Temperature [deg C]"
rrdtool graph temp_y.png --start -1y DEF:temp=database.rrd:temp:AVERAGE LINE1:temp#0000FF:"Temperature [deg C]"
#0000FF means blue trace color in the graphs.

(You can find more information about owfs in this post: How to Read 1-Wire Temperature Using a NSLU2 With Debian )

echo and cut is used to discard some of the excessive decimals, so that the stored value in the database is for example 23.8 instead of 23.875.

The 5 rrdtool graph commands will create graphs, where the timespan is h = hour, d = day, w = week, m = month and y = year.

A directory listing shows that the update script was created:

$ ls -la
total 32
drwxr-xr-x 2 thomas thomas  4096 Sep 15 19:04 .
drwxr-xr-x 6 thomas thomas  4096 Sep 15 17:49 ..
-rwxr-xr-x 1 thomas thomas   208 Sep 15 17:52 create_database.sh
-rw-r--r-- 1 thomas thomas 13764 Sep 15 18:50 database.rrd
-rw-r--r-- 1 thomas thomas   843 Sep 15 19:05 update_database.sh

You’ll have to modify the permissions of the update script to be able to run it:

$ chmod +x update_database.sh

If everything goes well when you run the script the only output is the dimensions of the 5 graphs:

$ ./update_database.sh
481x163
481x163
481x163
481x163
481x163

and a directory listing now shows that images files have been generated (.png stands for Portable Network Graphics):

$ ls -la
total 76
drwxr-xr-x 2 thomas thomas  4096 Sep 15 19:05 .
drwxr-xr-x 6 thomas thomas  4096 Sep 15 17:49 ..
-rwxr-xr-x 1 thomas thomas   208 Sep 15 17:52 create_database.sh
-rw-r--r-- 1 thomas thomas 13764 Sep 15 19:05 database.rrd
-rw-r--r-- 1 thomas thomas  7206 Sep 15 19:05 temp_d.png
-rw-r--r-- 1 thomas thomas  7966 Sep 15 19:05 temp_h.png
-rw-r--r-- 1 thomas thomas  7951 Sep 15 19:05 temp_m.png
-rw-r--r-- 1 thomas thomas  8040 Sep 15 19:05 temp_w.png
-rw-r--r-- 1 thomas thomas  8630 Sep 15 19:05 temp_y.png
-rwxr-xr-x 1 thomas thomas   843 Sep 15 19:05 update_database.sh

You could probably ask rrdtool to generate .jpg files instead if you can find a way to do so in the manual.

Now the database has been updated with a single snapshot of the temperature but we would like to continuously capture temperature data and keep the graphs updated. For this purpose we can use Linux crontab:

Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading email.

– Wikipedia

The -e option is for editing:

$ crontab -e
no crontab for thomas - using an empty one
crontab: installing new crontab

Every 5 minutes the update script is run, and any output messages are discarded:

# m h  dom mon dow   command
*/5 * * * * /home/thomas/rrdtool/update_database.sh &> /dev/null

If you want to check what jobs are installed you can use the -l option:

$ crontab -l

Since the NSLU2 doesn’t have any monitor connection on it I need to get the graphs copied to a computer with a screen to be able to see the results. For that I use FTP:

$ cd /home/thomas/rrdtool
$ ftp

Replace SERVER and USERNAME below with your own details:

ftp> open
(to) SERVER
Connected to SERVER.
Name (SERVER:thomas): USERNAME
ftp> mkdir temp
ftp> cd temp
ftp> put temp_d.png
ftp> put temp_h.png
ftp> put temp_m.png
ftp> put temp_w.png
ftp> put temp_y.png
ftp> exit

You could also copy the image files to a USB memory stick and from there onto your PC.

From my server on the Internet I can now download and view the generated graphs.

The first one (temp_h.png) covers only 1 hour in time and the air temperature is very stable over the hour so this particular graph is not very informative:

temp_d.png is more interesting as you can begin to see changes in the temperature:

temp_w.png needs a lot more time before it has been filled up with data, but if the system is stable the graph will be completed in about a week:

temp_m.png and temp_y.png are long term graphs but quite interesting to look at when they have been drawn, especially if you mounted the temperature sensor outdoors. There’s nothing to see yet though, because the system is new:

I’m going to add more and different kinds of sensors to the NSLU2 logging system in the coming weeks.

How to Read 1-Wire Temperature Using a NSLU2 With Debian

This is a small Debian NSLU2 1-Wire HowTo that explains the steps needed to get some data out of those small cool devices using a DS18S20 NSLU2 1-Wire setup.

The component covered by green heat shrink in the picture below is a 1-Wire component, specifically a temperature measuring device, model DS18S20:

(18S20 wiring is shown on this page: DS18S20 Wiring )

The 1-Wire bus runs well on both telephone cable and Ethernet cable, and since the DS18S20 was already soldered onto a piece of Ethernet cable and covered in heat shrink, I chose an easy to make test setup by connecting the Ethernet cable to a piece of ordinary telephone cable, because the connector already mounted on the telephone cable fits directly into a DS9490R 1-Wire USB adapter available from hobby-boards.com. It’s the blue device in the picture below:

(See the post called Debian on NSLU2 With USB Hard Disk and Homeplug Network for more details about the rest of the system.)

Paul Alfille wrote a clever piece of software that makes it easy to handle 1-Wire units. It’s called OWFS, and the project has its own website at owfs.org, if you want to know more about how OWFS works. I chose this software to handle the units on my 1-Wire NSLU2 Debian installation, but there’s a bit of work to do to get the 1-Wire software installed and running. Instructions are available at owfs.org / Setup / Install / Download, which points to the project files on SourceForge.net.

In order to get the installation files for OWFS onto the NSLU2 I logged in via my laptop PC using ssh and use wget on NSLU2: (Replace .xx with the address of the NSLU2 on the intranet)

$ ssh thomas@192.168.1.xx

$ mkdir /home/thomas/owfs_install
$ cd /home/thomas/owfs_install
$ wget sourceforge.net/projects/owfs/files/owfs/2.8p13/owfs-2.8p13.tar.gz/download
$ mv download owfs-2.8p13.tar.gz
$ tar -zxvf owfs-2.8p13.tar.gz
$ cd /home/thomas/owfs_install/owfs-2.8p13

For some reason the downloaded file is named download so I use the mv command to rename it to something more precise.

When I try to install OWFS it turns out that I’m missing something on my freshly installed Debian:

$ ./configure

error: no acceptable C compiler found in $PATH

The package build-essential contains the needed C compiler:

$ su
# apt-get install build-essential
# exit

Trying to configure one more time reveals a whole bunch of missing software required for OWFS to compile and run:

$ ./configure

...
configure: WARNING: Cannot find php binary. Install php or php5 package
configure: WARNING: OWPHP is disabled because php binary is not found
configure: WARNING: Cannot find python include-file. Install python-devel package.
configure: WARNING: OWPYTHON is disabled because python include-file is not found
checking for Tcl configuration... configure: WARNING: Can't find Tcl configuration definitions
configure: WARNING: OWTCL is disabled because tclConfig.sh is not found
configure: WARNING: LD_EXTRALIBS= OSLIBS=
configure: WARNING:
Can't find fuse.h - Add the search path with --with-fuseinclude
configure: WARNING: Install FUSE-2.2 or later to enable owfs - download it from http://fuse.sourceforge.net/
configure: WARNING: OWFS is disabled because fuse.h is not found.
configure: WARNING: Can't find libusb
configure: WARNING: libusb not found, usb will be disabled
...
Compile-time options:
USB is DISABLED
Profiling is DISABLED
Tracing memory allocation is DISABLED
1wire bus traffic reports is DISABLED
...
Module configuration:
owfs is DISABLED
swig is DISABLED
owperl is DISABLED
owphp is DISABLED
owpython is DISABLED
owtcl is DISABLED

Fortunately most of the missing stuff is contained in these 7 packages:

$ su
# apt-get install php5-cli python2.4-dev tcl-dev tk-dev libusb-dev swig libperl-dev
# exit

The warning about the missing FUSE software is cleared by downloading and installing like this:

$ mkdir /home/thomas/fuse
$ cd /home/thomas/fuse
$ wget http://sourceforge.net/projects/fuse/files/fuse-2.X/2.8.5/fuse-2.8.5.tar.gz/download
$ mv download fuse-2.8.5.tar.gz
$ tar -zxvf fuse-2.8.5.tar.gz
$ cd /home/thomas/fuse/fuse-2.8.5/
$ ./configure
$ make
$ su
# make install
# exit

Now only one warning is present and a few disabled functions, which is acceptable for the purpose of reading temperature from the DS18S20 IC:

$ cd /home/thomas/owfs_install/owfs-2.8p13

$ ./configure

configure: WARNING: LD_EXTRALIBS= OSLIBS=

Compile-time options:
Profiling is DISABLED
Tracing memory allocation is DISABLED
1wire bus traffic reports is DISABLED

Module configuration:
owlib is enabled
owshell is enabled
owfs is enabled
owhttpd is enabled
owftpd is enabled
owserver is enabled
ownet is enabled
ownetlib is enabled
owtap is enabled
owmon is enabled
owcapi is enabled
swig is enabled
owperl is enabled
owphp is enabled
owpython is enabled
owtcl is enabled

And a final install:

$ make
$ su
# make install
# exit

Note that $ means you are working on the CLI as a normal user, and # means you’re working as root, which should be minimized since you have total power as root which again means that you could easily cause irreversible damage to your system by accident. Therefore it’s best to do as much as you can as a normal user.

Howto access DS9490: FS in OWFS stands for File System so I created a directory for the 1-Wire devices and mounted the one-wire file system in this new directory:

$ mkdir /home/thomas/owfs

$ /opt/owfs/bin/owfs -u /home/thomas/owfs
DEFAULT: owlib.c:SetupSingleInboundConnection(201) Cannot open USB bus master
DEFAULT: owlib.c:LibStart(54) No valid 1-wire buses found

Again, the separation between root and normal users means that as a normal user (thomas) I don’t have direct access to the USB DS9490R adapter, so I have to change to superuser root to mount OWFS:

$ su
# /opt/owfs/bin/owfs -u /home/thomas/owfs
DEFAULT: ow_usb_msg.c:DS9490_open(276) Opened USB DS9490 bus master at 1:4.
DEFAULT: ow_usb_cycle.c:DS9490_ID_this_master(191) Set DS9490 1:4 unique id to 81 59 25 27 00 00 00 CE
# exit

But still more problems related to root versus normal user permissions – the mounted directory containing the 1-Wire data is not available to normal users:

$ ls -la /home/thomas
total 32
drwxr-xr-x 5 thomas thomas 4096 Sep  8 12:44 .
drwxr-xr-x 3 root   root   4096 Sep  2 20:20 ..
-rw------- 1 thomas thomas 1338 Sep  8 12:47 .bash_history
-rw-r--r-- 1 thomas thomas  220 Sep  2 20:20 .bash_logout
-rw-r--r-- 1 thomas thomas 3116 Sep  2 20:20 .bashrc
-rw-r--r-- 1 thomas thomas  675 Sep  2 20:20 .profile
drwxr-xr-x 3 thomas thomas 4096 Sep  8 09:15 fuse
d????????? ? ?      ?         ?            ? owfs
drwxr-xr-x 3 thomas thomas 4096 Sep  7 20:59 owfs_install

and can’t be listed when you’re logged in as a normal user:

$ ls -la /home/thomas/owfs
ls: cannot access owfs: Permission denied

Changing to superuser using su reveals the goodies:

$ su

# ls -la /home/thomas
total 32
drwxr-xr-x 5 thomas thomas 4096 Sep  8 12:44 .
drwxr-xr-x 3 root   root   4096 Sep  2 20:20 ..
-rw------- 1 thomas thomas 1338 Sep  8 12:47 .bash_history
-rw-r--r-- 1 thomas thomas  220 Sep  2 20:20 .bash_logout
-rw-r--r-- 1 thomas thomas 3116 Sep  2 20:20 .bashrc
-rw-r--r-- 1 thomas thomas  675 Sep  2 20:20 .profile
drwxr-xr-x 3 thomas thomas 4096 Sep  8 09:15 fuse
drwxr-xr-x 1 root   root      8 Sep  8 12:51 owfs
drwxr-xr-x 3 thomas thomas 4096 Sep  7 20:59 owfs_install

My OWFS NSLU2 system is up and running, and 10.4F7… is the DS18S20 IC on the 1-Wire bus:

# ls -la /home/thomas/owfs
total 4
drwxr-xr-x 1 root   root      8 Sep  8 12:51 .
drwxr-xr-x 5 thomas thomas 4096 Sep  8 12:44 ..
drwxrwxrwx 1 root   root      8 Sep  8 12:52 10.4F7494010800
drwxrwxrwx 1 root   root      8 Sep  8 12:52 81.592527000000
drwxr-xr-x 1 root   root      8 Sep  8 12:51 alarm
drwxr-xr-x 1 root   root      8 Sep  8 12:51 bus.0
drwxr-xr-x 1 root   root      8 Sep  8 12:51 settings
drwxrwxrwx 1 root   root      8 Sep  8 12:52 simultaneous
drwxr-xr-x 1 root   root      8 Sep  8 12:51 statistics
drwxr-xr-x 1 root   root     32 Sep  8 12:51 structure
drwxr-xr-x 1 root   root      8 Sep  8 12:51 system
drwxr-xr-x 1 root   root      8 Sep  8 12:51 uncached

In order to get access to OWFS as a normal user there’s trick you can do, but first I’m rebooting to make sure OWFS is completely shutdown. (There’s probably a clever way to do this, if you know what you’re doing ;-) ):

# reboot

Log in again from laptop to NSLU2:

$ ssh thomas@192.168.1.xx

The option --allow-other can be added when running OWFS, which allows normal users to access the 1-Wire file system without changing to superuser (the -u option means that you’re connecting via USB adapter instead of a serial connector):

$ su

# /opt/owfs/bin/owfs --allow_other -u /home/thomas/owfs
DEFAULT: ow_usb_msg.c:DS9490_open(276) Opened USB DS9490 bus master at 1:4.
DEFAULT: ow_usb_cycle.c:DS9490_ID_this_master(191) Set DS9490 1:4 unique id to 81 59 25 27 00 00 00 CE
# exit

Now there is access to the owfs directory even when you’re logged in as a normal user:

$ ls -la /home/thomas
total 32
drwxr-xr-x 5 thomas thomas 4096 Sep  8 12:44 .
drwxr-xr-x 3 root   root   4096 Sep  2 20:20 ..
-rw------- 1 thomas thomas 1452 Sep  8 12:57 .bash_history
-rw-r--r-- 1 thomas thomas  220 Sep  2 20:20 .bash_logout
-rw-r--r-- 1 thomas thomas 3116 Sep  2 20:20 .bashrc
-rw-r--r-- 1 thomas thomas  675 Sep  2 20:20 .profile
drwxr-xr-x 3 thomas thomas 4096 Sep  8 09:15 fuse
drwxr-xr-x 1 root   root      8 Sep  8 13:02 owfs
drwxr-xr-x 3 thomas thomas 4096 Sep  7 20:59 owfs_install
$ ls -la /home/thomas/owfs
total 4
drwxr-xr-x 1 root   root      8 Sep  8 13:02 .
drwxr-xr-x 5 thomas thomas 4096 Sep  8 12:44 ..
drwxrwxrwx 1 root   root      8 Sep  8 13:02 10.4F7494010800
drwxrwxrwx 1 root   root      8 Sep  8 13:02 81.592527000000
drwxr-xr-x 1 root   root      8 Sep  8 13:02 alarm
drwxr-xr-x 1 root   root      8 Sep  8 13:02 bus.0
drwxr-xr-x 1 root   root      8 Sep  8 13:02 settings
drwxrwxrwx 1 root   root      8 Sep  8 13:02 simultaneous
drwxr-xr-x 1 root   root      8 Sep  8 13:02 statistics
drwxr-xr-x 1 root   root     32 Sep  8 13:02 structure
drwxr-xr-x 1 root   root      8 Sep  8 13:02 system
drwxr-xr-x 1 root   root      8 Sep  8 13:02 uncached

To read out the temperature from the DS18S20 IC we have to take a look at the file called temperature:

$ ls -la /home/thomas/owfs/10.4F7494010800
total 0
drwxrwxrwx 1 root root   8 Sep  8 13:03 .
drwxr-xr-x 1 root root   8 Sep  8 13:02 ..
-r--r--r-- 1 root root  16 Sep  8 13:02 address
-rw-rw-rw- 1 root root 256 Sep  8 13:02 alias
-r--r--r-- 1 root root   2 Sep  8 13:02 crc8
drwxrwxrwx 1 root root   8 Sep  8 13:03 errata
-r--r--r-- 1 root root   2 Sep  8 13:02 family
-r--r--r-- 1 root root  12 Sep  8 13:02 id
-r--r--r-- 1 root root  16 Sep  8 13:02 locator
-r--r--r-- 1 root root   1 Sep  8 13:03 power
-r--r--r-- 1 root root  16 Sep  8 13:02 r_address
-r--r--r-- 1 root root  12 Sep  8 13:02 r_id
-r--r--r-- 1 root root  16 Sep  8 13:02 r_locator
-r--r--r-- 1 root root  12 Sep  8 13:02 temperature
-rw-rw-rw- 1 root root  12 Sep  8 13:03 temphigh
-rw-rw-rw- 1 root root  12 Sep  8 13:03 templow
-r--r--r-- 1 root root  32 Sep  8 13:02 type

All data from the 1-Wire IC are contained in different files in OWFS, and the content of files can be displayed with the cat command in Linux:

$ cat /home/thomas/owfs/10.4F7494010800/temperature
24

So this value shows that the system is running and temperature measurements are being done (24 deg. C). Information about the type of IC is contained in the type file:

$ cat /home/thomas/owfs/10.4F7494010800/type
DS18S20

Just to proved that the resolution is higher than 1 deg. C I did one more readout and that showed 4 more digits after the previous value:

$ cat /home/thomas/owfs/10.4F7494010800/temperature
24.0625

The obvious next step is to build even more software on top of NSLU2 OWFS installation to make nice graphs over time to gain comprehensive information about the temperature.

The DS18S20 can of course be placed in many different locations, even outdoors if you use heat shrink to protect the IC against the weather.

(Update: Do your OWFS sensors disappear from time to time? Please join the discussion below).

Debian on NSLU2 With USB Hard Disk and Homeplug Network

This is an update on my NSLU2 1-Wire project. I wanted to use a wired Ethernet to WLAN adapter to connect the NSLU2 to the rest of the world, but I couldn’t make it work right away so I decided to use a power line Ethernet adapter instead of digging further into the problem. The system diagram now looks like this:

This is the way the system looks at the moment and I’ll start working on adding the 1-Wire components in the coming days. Here’s a link to the original diagram: NSLU2 1-Wire thermometer system

The power line Ethernet adapter, also called Homeplug, is one I bought from ZyXEL, model PLA-401 v3. There are only 2 connections, mains and Ethernet, so it’s really easy to use. You’ll need two units, one in each end of your power line network:

Here’s a picture of the system built according to the above diagram, with a 30 GB Quantum Fireball hard disk connected via USB:

And what better place to hide it than inside my home aquaponics system?:

Charlotte insisted that the aquaponics system had to be covered with white sheets, now that it has been set up in the corner of the living room, and it actually turned out to be a quite neat looking setup:

… just imagine how much electronics I could fit in there  – mmm… ;-)

The NSLU2 system is now close to the outer wall so I should be easy to get the 1-Wire cable outside to be able to measure outside temperature, both air and soil. And why not add a soil moisture sensor while we’re at it, or perhaps a rain sensor? Being right underneath the aquaponics system should make it easy to measure water temperature and pH too. The good thing about 1-Wire is that you can have many different IC’s connected to the bus at the same time on different addresses.

Getting the NSLU2 up and running with Debian is alway a bit challenging, at least for me, so here’s a brief description for reference:

  1. Google ‘nslu2 debian’ to get to the current installation instructions. I found them at www.cyrius.com/debian/nslu2/install.html
  2. Install upslug2 on Ubuntu laptop: sudo apt-get install upslug2
  3. Download software from www.slug-firmware.net/d-dls.php
  4. Unpack debian-armel-5.0.4.zip to di-nslu2.bin (8.0 MB)
  5. Power off NSLU2 and disconnect USB hard disk
  6. Put NSLU2 into upgrade mode
  7. Check that NSLU2 can be reached on the intranet: sudo upslug2
  8. Install Debian installer on NSLU2: sudo upslug2 -i di-nslu2.bin
  9. Power off NSLU2 and connect USB hub and hard disk
  10. Find IP address of NSLU2 on the intranet: nmap -sP 192.168.1.1-254
  11. Start Debian installer on NSLU2: ssh installer@192.168.1.27, password install
  12. Go to shell inside installer and set up name server: nano /etc/resolv.conf (DON’T reboot afterwards)
  13. Follow the instructions by the Debian installer for the next 4 hours… 8-|

Tip: If you can’t connect to the NSLU2 try removing the known hosts file on your laptop: rm .ssh/known_hosts

Now it’s time to add some 1-Wire components and install more software on the NSLU2 to be able to communicate with the 1-Wire IC’s.