The DS18B20 is a popular temperature sensor that uses the 1-Wire protocol for communication. Recent versions of the Linux kernel include a kernel driver for this protocol, making it relatively convenient to connect one or more of these devices to a Raspberry Pi or similar device. 1-Wire devices can be daisy chained, so it is possible to connect several devices to your Pi using only a single GPIO pin, and you'll find many articles out there that describe how to do so.

Occasionally, it may be necessary to have more than a single chain of connected devices. For example, you may have reached the limits on the size of your 1-Wire network, or you may simply need to route your cables in a way that makes a single chain difficult. You can enable multiple 1-Wire buses on your Raspberry Pi to handle these situations.

For a single 1-Wire bus, you add the following to /boot/config.txt:

dtoverlay=w1-gpio

This will enable the 1-Wire bus on GPIO 4. To enable multiple 1-Wire buses, you will use multiple dtoverlay statements and the gpiopin parameter to the w1-gpio overlay. For example, to enable 1-Wire buses on GPIO 4 and GPIO 17, you would use:

dtoverlay=w1-gpio,gpiopin=4
dtoverlay=w1-gpio,gpiopin=17

In the picture at the top of this post, there are four DS18B20 sensors. Three are connected to the 1-Wire bus on GPIO 4, and one is connected to the 1-Wire bus on GPIO 17. Looking in /sys/bus/w1/devices, I see two w1_bus_master devices (and the four temperature sensors):

$ ls /sys/bus/w1/devices/
28-041722cbacff  28-0417231547ff  w1_bus_master1
28-041722ce24ff  28-04172318c0ff  w1_bus_master2

I can check the temperature on all four devices like this:

$ cat /sys/bus/w1/devices/28-*/w1_slave
50 01 4b 46 7f ff 0c 10 e8 : crc=e8 YES
50 01 4b 46 7f ff 0c 10 e8 t=21000
50 01 4b 46 7f ff 0c 10 e8 : crc=e8 YES
50 01 4b 46 7f ff 0c 10 e8 t=21000
57 01 4b 46 7f ff 0c 10 38 : crc=38 YES
57 01 4b 46 7f ff 0c 10 38 t=21437
57 01 4b 46 7f ff 0c 10 38 : crc=38 YES
57 01 4b 46 7f ff 0c 10 38 t=21437

You may have noted that there is also a DHT22 sensor in the picture. Much like the 1-Wire overlay, the kernel driver for the DHT22 can be associated with an arbitrary GPIO pin like this:

dtoverlay=dht11,gpiopin=27

Using Docker macvlan networks

Mon 12 March 2018 by Lars Kellogg-Stedman Tags networking docker

A question that crops up regularly on #docker is "How do I attach a container directly to my local network?" One possible answer to that question is the macvlan network type, which lets you create "clones" of a physical interface on your host and use that to attach containers directly …

read more

Listening for connections on all ports/any port

Tue 27 February 2018 by Lars Kellogg-Stedman Tags networking

On IRC -- and other online communities -- it is common to use a "pastebin" service to share snippets of code, logs, and other material, rather than pasting them directly into a conversation. These services will typically return a URL that you can share with others so that they can see the …

read more

Grouping aggregation queries in Gnocchi 4.0.x

Mon 26 February 2018 by Lars Kellogg-Stedman Tags openstack gnocchi metrics

In this article, we're going to ask Gnocchi (the OpenStack telemetry storage service) how much memory was used, on average, over the course of each day by each project in an OpenStack environment.

Environment

I'm working with an OpenStack "Pike" deployment, which means I have Gnocchi 4.0.x. More …

read more

Listing iptables rules with line numbers

Thu 08 February 2018 by Lars Kellogg-Stedman Tags shell iptables

You can list iptables rules with rule numbers using the --line-numbers option, but this only works in list (-L) mode. I find it much more convenient to view rules using the output from iptables -S or iptables-save.

You can augment the output from these commands with rule numbers with the …

read more