Raspberry Pi, Xively and DS18B20 the Unix Way

This post is building up on previous Xively Data Logging the Unix Way, so read that one first.

DS18B20 is a cheap digital thermometer with One-Wire interface. There are many tutorials how to make it work in Arduino, Raspberry Pi and other platforms. For the Raspberry Pi I was following excellent Adafruit Tutorial. As far as the HW goes, this is perfect.

Then I didn’t like the idea of python programming. There are alternatives to the Adafruit proposed script. The most robust is probably OWFS – collection of drivers to create filesystem like access to all kinds of One-Wire devices. For my purpose that seemed as too much of an overkill.

I wanted to build the scripts on top of my previously created siple xively logging script. So the only challenge was how to get the temperature reading from DS18B20 using only standard unix commandline tools.

Once you make the kernel modules run, as Adafruit suggest here, you can read the temperature from special files /sys/bus/w1/devices/*/w1_slave (the * stands for DSs’ ids). With my particular DS18B20 the file is /sys/bus/w1/devices/28-000001b451d9/w1_slave and normally contains this:

6d 01 4b 46 7f ff 03 10 70 : crc=70 YES
6d 01 4b 46 7f ff 03 10 70 t=22812

The temperature in this example is 22.812 Celsius.

So I created the following bash script, which given the DS18B20′s ID as a parameter, prints current temperature. It’s basically one line of grep&awk plus some boilerplate.

To periodically log temperature to xively, just put the second small script to your /etc/cron.hourly or /etc/corn.minutely folder (of course you need to update it with your particular DS18B20 id and your xively channel name).



Xively Data Logging the Unix Way

Motivation I wanted to log my Raspberry Pi’s CPU load and temperature into xively for easy monitoring. Later maybe add a few more Arduino sensors spread around my home. There are multiple libraries in several programming languages/platforms supplied by xively itself. I believe they are all good, well tested and well maintained pieces of code. [...]

michaela.synackova.com up and running

After 2 years of me paying for the domain, Míša finally decided what to put there. Minimal, kind of professional ;) business card of “Michaela Synáčková, film production assistant” up running since yesterday at http://michaela.synackova.com/.

Punto

It is exactly one year since I started my “gap year” traveling on 2nd September 2011. Now I’m back and settling in the “normal” life again. So it is time to close this trip and stop blogging for some time. Here is a little debrief. When I started I had three objectives: to learn Spanish, [...]

Book Exchange

Normally at home I read about one book per year. While travelling I realized I can catch up on some reading. The book exchange with other travelers, in many hostels and even in pubs is actually much better than going to the library as it makes you read things you would otherwise not know even [...]

Coming Back

When the boat got to Panama, my trip looped. Coming to Panama City after 11 months felt a bit like coming home already. It has not changed much. The skyscraper that had only the concrete structure last time was almost finished with shiny glass. My favorite, and also only one, photography shop that still did [...]

Sailing from Colombia to Panama

Almost a year ago I went with Ewan to Portobelo on the Caribean side of Panama. This was my first trip in Panama actually. There in Captain Jack’s I met people that had come to Panama with a sailboat from Colombia. I learned how this works and that it is the most sensible way how [...]

The Rest of Colombia

After salsa life in Cali I went to relax in Salento. Salento is a coffee region of Colombia, but also a home to Colombia’s national tree – the funny looking high palm. Valle de Cocora at EveryTrail My first night there I was welcomed by hundreds of lightning beetles. Quite similar to Nicaraguan experience earlier [...]

The Capital of Salsa

Forget Cuba. Cali or Santiago de Cali is the true capital of salsa. Once I found the salsa hostel in Cali (Jovita’s) I started taking salsa classes and dancing. The day schedule was totaly different from whatever I had experienced before on this trip. Sleep all morning. Group salsa lesson in the early afternoon, individual [...]

Ecuatorianamente Refrescante

After Chimborazo I went directly to Baños. I could not wait to get to the hot springs for some rapid regeneration. The springs open at 6pm, so everybody is advised to arrive just at that time so that the water is still clean and the place not overcrowded. This means it does not work, because [...]