DIDA:
Ja bych spis sazel na nejaky HW problem, to cidlo proste zmizi ze systemu a neni videt v
"/sys/bus/w1/devices" Zapojene to mam presne podle nize uvedeneho obrazku, vcetne 4,7kOhmu odporu. Kazdou minutu pak spousitm vlastni skript ktery krome teploty cidla, nacita i teplotu CPU a volne misto na ulozistich, priradi IDX pro domoticz a posle ma MQTT broker. Vsechny tyto sluzby bezi na jednom zarizeni a krome teploty cidla ostatni hodnoty posbirane skriptem chodi, z toho usuzuji, ze k zadnemu zacykleni nedochazi. Zkusim to jak radis, prehodit datovy vodic na jiny GPIO.
sensor.sh
#!/bin/bash
# /etc/crontab
# * * * * * root bash /data/sensor.sh
# --VARIABLES ------------------------------------------------------------
# definice IDX jednotlivych polozek
IDX1="21"
IDX2="22"
IDX3="23"
IDX4="32"
SERIAL="28-03049779e23f"
# globalni nastaveni
TARGET="172.29.55.98"
PORT="1883"
TOPIC="domoticz/in"
PAUSE="15"
# needitovat
CMD="mosquitto_pub -h "$TARGET" -p "$PORT" -t '"$TOPIC"' -m "
SEND=""
# -----------------------------------------------------------------------
sleep 5
for (( CYCLE=0; CYCLE<$(echo $(( 60/$PAUSE ))); CYCLE++ )); do
# nacte a odesle teplotu CPU Raspberry PiX
CPU_TEMP=""
CPU_TEMP=$(echo $(/opt/vc/bin/vcgencmd measure_temp))
CPU_TEMP=${CPU_TEMP:5:4}
SEND="'{\"idx\":"$IDX1",\"nvalue\":0,\"svalue\":\"$CPU_TEMP\"}'"
if [ -n "$CPU_TEMP" ]; then echo $CMD$SEND | bash; fi
# nacte a odesle kapacitu disku "/dev/sda1"
DISK_SYSTEM="/"
DISK_SYSTEM=$(echo $(df $DISK_SYSTEM -l -h --output=pcent))
DISK_SYSTEM=$(echo $DISK_SYSTEM | cut -d '%' -f 2)
DISK_SYSTEM=${DISK_SYSTEM:1:3}
SEND="'{\"idx\":"$IDX2",\"nvalue\":0,\"svalue\":\"$DISK_SYSTEM\"}'"
if [ -n "$DISK_SYSTEM" ]; then echo $CMD$SEND | bash; fi
# nacte a odesle kapacitu disku "/dev/md0"
DISK_DATA="/data"
DISK_DATA=$(echo $(df $DISK_DATA -l -h --output=pcent))
DISK_DATA=$(echo $DISK_DATA | cut -d '%' -f 2)
DISK_DATA=${DISK_DATA:1:3}
SEND="'{\"idx\":"$IDX3",\"nvalue\":0,\"svalue\":\"$DISK_DATA\"}'"
if [ -n "$DISK_DATA" ]; then echo $CMD$SEND | bash; fi
# nacte a odesle teplotu z cidla DS18B20
DS18B20=""
DS18B20=$( cat /sys/bus/w1/devices/w1_bus_master1/$SERIAL/w1_slave|grep "t=" )
DS18B20=${DS18B20:29:7}
DS18B20=$(echo "scale=1; $DS18B20/1000"|bc)
SEND="'{\"idx\":"$IDX4",\"nvalue\":0,\"svalue\":\"$DS18B20\"}'"
if [ -n "$DS18B20" ]; then echo $CMD$SEND | bash; fi
if (( $CYCLE < $(echo $(( 60/$PAUSE-1 ))) )); then sleep $PAUSE; fi
done