This page looks best with JavaScript enabled

CO2 traffic light by Watterott - data shown at Conky

 ·  ☕ 2 min read  ·  🤖 SWU

The CO2 traffic lights by Watterott signs co2 concentration of the air with colored leds and since firmware versionn v7 from here serial commands and data output is enabled.
See entries at the publications at my site.

The serial interface of the co2 traffic lights at linux

At my computer the seriel interface is /dev/ttyACM0. You can use it e. g. with Minicom or Screen, but you can also use cat at the commandline to display it. The latter is what we will use for our script.

Conky’s shell-script interface

Aside Conky’s internal commands there are some calling shell-scripts periodically that you can use to get co2 traffic lights state and show it at the conky window.

Objective: Show co2 values at the Conky window

There are two shell-scripts needed, one to gain the state and the other to tell it. The first scipt will be waiting for change of state, so it can’t be used to inform conky constantly. That’s why it has to write new states to a file, the other script reads and tells conky.

Collecting data from the serial interface of the co2 traffic lights

The co2 traffics light must be connected to the computer of course - which might not be the case. So we use a watcher script again, if the device is connected data will be filtered and put to a file. If it is not, then there is a NIL as output.

The bash-script co2ampel.watcher.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
INTERFACE='/dev/ttyACM0'
SIGNAL="/var/tmp/co2ampel.txt"

if test -c $INTERFACE
then
        echo "1" > $SIGNAL
        sleep 10 
else
        echo "0" > $SIGNAL
        exit
fi

action() {
        readarray -t ALINE < <(echo $line)
        if [[ ${ALINE[0]} =~ .*c:.* ]]
        then
                echo ${ALINE[0]} | sed -e 's/c:/CO2:/g'> $SIGNAL
        fi
}
cat $INTERFACE |
        while read line; do
                action
        done
echo "0" > $SIGNAL

The shell-Script co2ampel.conky.sh

1
2
3
4
#!/bin/sh
SIGNAL="/var/tmp/co2ampel.txt"
pgrep -fl "co2ampel.watcher.sh" >/dev/null || nohup bin/co2ampel.watcher.sh > /var/tmp/co2ampel.watcher.out &
cat $SIGNAL

The Conky entry

1
${execp ~/bin/co2ampel.conky.sh} ppm

Example of the co2ampel.txt file

1
CO2: 838 ppm

wüsti
WRITTEN BY
SWU
human