Uživatelské nástroje

Nástroje pro tento web


zarizeni:raspberry_pi

Toto je starší verze dokumentu!


Raspberry PI

Mini počítač Raspberry PI lze jednoduše využít k logování naměřených hodnot na cloud Tmep.cz. Následující příklady počítají s nainstalovaným systémem RASPBIAN JESSIE (Release date: 2017-01-11).

Raspberry PI + DS18B20

Nejprve je nutné zprovoznit podporu 1-Wire sběrnice. V souboru /boot/config.txt zrušíme poznámku či doplníme následující nastavení:

dtoverlay=w1-gpio,gpiopin=4

Po restartu zařízení již bude funkční 1-wire sběrnice na GPIO 4. Pokud máme připojeno čidlo můžeme provést kontrolu:

ls /sys/bus/w1/devices/

V našem příkladu máme připojeno čidlo s unikátní výrobní adresou 0000070aeea3, 28 značí čidlo 18B20.

pi@raspberrypi:~ $ ls /sys/bus/w1/devices/
28-0000070aeea3  w1_bus_master1

Pro periodické ukládání hodnot na cloud Tmep.cz můžeme využít skript.

Nezapomeňte upravit proměnné GUID a SERVER dle aktuálního nastavení Tmep.cz

#! /bin/bash
 
# This script reads the temperature from all connected 1-wire temperature
# sensors of the DS1820 family.
# The script will answer nothing if it can't find any sensors.
#
# Author: San Bergmans
#         www.sbprojects.com
#
# Modified for Tmep.cz Petr Domorazek
#
 
GUID="1234567890"
 
SERVER="tst.tmep.cz"
 
W1DIR="/sys/bus/w1/devices"
 
# Exit if 1-wire directory does not exist
if [ ! -d $W1DIR ]
then
    echo "Can't find 1-wire device directory"
    exit 1
fi
 
# Get a list of all devices
DEVICES=$(ls $W1DIR)
 
# Loop through all devices
for DEVICE in $DEVICES
do
    # Ignore the bus master device
    if [ $DEVICE != "w1_bus_master1" ]
    then
        # Get an answer from this device
        ANSWER=$(cat $W1DIR/$DEVICE/w1_slave)
 
        # See if device really answered
        # When a previously existing device is removed it will
        # read 00 00 00 00 00 00 00 00 00, which results in a
        # valid CRC. That's why we need this extra test.
        echo -e "$ANSWER" | grep -q "00 00 00 00 00 00 00 00 00"
 
        if [ $? -ne 0 ]
        then
            # The temperature is only valid if the CRC matches
            echo -e "$ANSWER" | grep -q "YES"
            if [ $? -eq 0 ]
            then
                # Isolate the temprature from the second line
                TEMPERATURE=$(echo -e "$ANSWER" | grep "t=" | cut -f 2 -d "=")
                let TEMPE=$TEMPERATURE/100
                TEMPERATURE=$TEMPE
                # Isolate integer and fraction parts so we know where 
                # the decimal point should go
                INTEGER=${TEMPERATURE:0:(-1)}
                FRACTION=${TEMPERATURE:(-1)}
 
                # Restore the leading 0 for positive and negative numbers
                if [ -z $INTEGER ]
                then
                    INTEGER="0"
                fi
                if [ "$INTEGER" == "-" ]
                then
                    INTEGER="-0"
                fi
 
                # Write result of this sensor
                echo "$DEVICE=$INTEGER.$FRACTION"
                curl -s -H "Cache-Control: no-cache" $SERVER/?$GUID=$INTEGER.$FRACTION > /dev/null
            else
                # A CRC was found, show error message instead
                echo "$DEVICE=CRC error"
            fi
        fi
    fi
done

Pravidelným spouštěním každou minutu prostřednictvím plánovače zajistíte automatické ukládání hodnot.

crontab –e
# m h  dom mon dow   command
  * *   *   *   *    /home/pi/tmep.sh > /dev/null 2>&1


Raspberry PI s více DS18B20 senzory na jedné sběrnici

Nezapomeňte upravit proměnou SERVER dle aktuálního nastavení Tmep.cz. GUID odpovídá unikátní adrese každého čidla.

#! /bin/bash
 
# This script reads the temperature from all connected 1-wire temperature
# sensors of the DS1820 family.
# The script will answer nothing if it can't find any sensors.
#
# Author: San Bergmans
#         www.sbprojects.com
#
# Modified for Tmep.cz Petr Domorazek
#
 
SERVER="tst.tmep.cz"
 
W1DIR="/sys/bus/w1/devices"
 
# Exit if 1-wire directory does not exist
if [ ! -d $W1DIR ]
then
    echo "Can't find 1-wire device directory"
    exit 1
fi
 
# Get a list of all devices
DEVICES=$(ls $W1DIR)
 
# Loop through all devices
for DEVICE in $DEVICES
do
    # Ignore the bus master device
    if [ $DEVICE != "w1_bus_master1" ]
    then
        # Get an answer from this device
        ANSWER=$(cat $W1DIR/$DEVICE/w1_slave)
 
        # See if device really answered
        # When a previously existing device is removed it will
        # read 00 00 00 00 00 00 00 00 00, which results in a
        # valid CRC. That's why we need this extra test.
        echo -e "$ANSWER" | grep -q "00 00 00 00 00 00 00 00 00"
 
        if [ $? -ne 0 ]
        then
            # The temperature is only valid if the CRC matches
            echo -e "$ANSWER" | grep -q "YES"
            if [ $? -eq 0 ]
            then
                # Isolate the temprature from the second line
                TEMPERATURE=$(echo -e "$ANSWER" | grep "t=" | cut -f 2 -d "=")
                let TEMPE=$TEMPERATURE/100
                TEMPERATURE=$TEMPE
                # Isolate integer and fraction parts so we know where 
                # the decimal point should go
                INTEGER=${TEMPERATURE:0:(-1)}
                FRACTION=${TEMPERATURE:(-1)}
 
                # Restore the leading 0 for positive and negative numbers
                if [ -z $INTEGER ]
                then
                    INTEGER="0"
                fi
                if [ "$INTEGER" == "-" ]
                then
                    INTEGER="-0"
                fi
 
                # Write result of this sensor
                echo "$DEVICE=$INTEGER.$FRACTION"
                curl -s -H "Cache-Control: no-cache" $SERVER/?$DEVICE=$INTEGER.$FRACTION > /dev/null
            else
                # A CRC was found, show error message instead
                echo "$DEVICE=CRC error"
            fi
        fi
    fi
done