thinkpad executor done as well
This commit is contained in:
parent
46fb24150f
commit
077d4ca4d8
3 changed files with 60 additions and 53 deletions
|
@ -104,8 +104,8 @@ V_VA=55
|
||||||
V_POWER_FACTOR=56
|
V_POWER_FACTOR=56
|
||||||
|
|
||||||
function test_i2c_device {
|
function test_i2c_device {
|
||||||
if [ ! -d "/sys/bus/i2c/devices/i2c-${I2CBUS}/${I2CBUS}-00${2}" ]; then
|
if [ ! -d "/sys/bus/i2c/devices/i2c-${I2CBUS}/${I2CBUS}-00${1}" ]; then
|
||||||
echo "run ${3} 0x${2} > /sys/bus/i2c/devices/i2c-${I2CBUS}/new_device"
|
echo "run ${2} 0x${1} > /sys/bus/i2c/devices/i2c-${I2CBUS}/new_device"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -160,3 +160,8 @@ function mymqtt_update {
|
||||||
mymqtt_test
|
mymqtt_test
|
||||||
mosquitto_pub -t "${MQTT_TOPIC}/${1}/${2}/1/0/${3}" -m "${4}"
|
mosquitto_pub -t "${MQTT_TOPIC}/${1}/${2}/1/0/${3}" -m "${4}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mymqtt_battery {
|
||||||
|
mymqtt_test
|
||||||
|
mosquitto_pub -t "${MQTT_TOPIC}/${1}/${2}/3/0/0" -m "${3}"
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ mymqtt_init "${ID}" "${TEM_ID}" "${S_TEMP}" "CBG TEMPERATURE"
|
||||||
mymqtt_init "${ID}" "${HUM_ID}" "${S_HUM}" "CBG HUMIDITY"
|
mymqtt_init "${ID}" "${HUM_ID}" "${S_HUM}" "CBG HUMIDITY"
|
||||||
mymqtt_init "${ID}" "${BAR_ID}" "${S_BARO}" "CBG BAROMETER"
|
mymqtt_init "${ID}" "${BAR_ID}" "${S_BARO}" "CBG BAROMETER"
|
||||||
mymqtt_init "${ID}" "${RAIN_ID}" "${S_RAIN}" "CBG RAIN"
|
mymqtt_init "${ID}" "${RAIN_ID}" "${S_RAIN}" "CBG RAIN"
|
||||||
mymqtt_init "${ID}" "${SUN_ID}" "${S_CUSTOM}" "CBG SUN"
|
#mymqtt_init "${ID}" "${SUN_ID}" "${S_CUSTOM}" "CBG SUN"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
cbg="$(wget -O- -q https://www.cl.cam.ac.uk/research/dtg/weather/current-obs.txt)"
|
cbg="$(wget -O- -q https://www.cl.cam.ac.uk/research/dtg/weather/current-obs.txt)"
|
||||||
|
@ -48,7 +48,7 @@ while true; do
|
||||||
mymqtt_update "${ID}" "${HUM_ID}" "${V_HUM}" "${data[humidity]}"
|
mymqtt_update "${ID}" "${HUM_ID}" "${V_HUM}" "${data[humidity]}"
|
||||||
mymqtt_update "${ID}" "${BAR_ID}" "${V_PRESSURE}" "${data[pressure]}"
|
mymqtt_update "${ID}" "${BAR_ID}" "${V_PRESSURE}" "${data[pressure]}"
|
||||||
mymqtt_update "${ID}" "${RAIN_ID}" "${V_RAIN}" "${data[rain]}"
|
mymqtt_update "${ID}" "${RAIN_ID}" "${V_RAIN}" "${data[rain]}"
|
||||||
mymqtt_update "${ID}" "${SUN_ID}" "${V_VAR1}" "${data[sunshine]}"
|
#mymqtt_update "${ID}" "${SUN_ID}" "${V_VAR1}" "${data[sunshine]}"
|
||||||
|
|
||||||
sleep "$INTERVAL"
|
sleep "$INTERVAL"
|
||||||
done
|
done
|
||||||
|
|
100
thinkpad.sh
100
thinkpad.sh
|
@ -2,22 +2,23 @@
|
||||||
|
|
||||||
source /usr/local/lib/collectd/_functions.sh
|
source /usr/local/lib/collectd/_functions.sh
|
||||||
|
|
||||||
HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
|
ID="90"
|
||||||
INTERVAL="${COLLECTD_INTERVAL:-60}"
|
|
||||||
DOMOTICZ_PORT="${2:-8080}"
|
|
||||||
DOMOTICZ_IDX="${1:-1}"
|
|
||||||
DOMOTICZ_URL="http://${HOSTNAME}:${DOMOTICZ_PORT}/json.htm?type=command¶m=udevice"
|
|
||||||
|
|
||||||
IFS=';' read -ra KEYVALS <<< "${DOMOTICZ_IDX}"
|
POWER_ID="1"
|
||||||
declare -A idx
|
CURRENT_ID="2"
|
||||||
for item in "${KEYVALS[@]}"; do
|
VOLTAGE_ID="3"
|
||||||
idx[${item%=*}]=${item##*=}
|
AC_ID="4"
|
||||||
done
|
TEM_ID="5"
|
||||||
|
|
||||||
|
mymqtt_init "${ID}" "${POWER_ID}" "${S_POWER}" "THINKPAD POWER"
|
||||||
|
mymqtt_init "${ID}" "${CURRENT_ID}" "${S_MULTIMETER}" "THINKPAD CURRENT"
|
||||||
|
mymqtt_init "${ID}" "${VOLTAGE_ID}" "${S_MULTIMETER}" "THINKPAD VOLTAGE"
|
||||||
|
mymqtt_init "${ID}" "${AC_ID}" "${S_BINARY}" "THINKPAD AC"
|
||||||
|
mymqtt_init "${ID}" "${TEM_ID}" "${S_TEMP}" "THINKPAD TEMPERATURE"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
# battery
|
|
||||||
ac="$(cat /sys/devices/platform/smapi/ac_connected)"
|
ac="$(cat /sys/devices/platform/smapi/ac_connected)"
|
||||||
|
|
||||||
for battery in /sys/devices/platform/smapi/BAT*; do
|
for battery in /sys/devices/platform/smapi/BAT*; do
|
||||||
|
|
||||||
if [ $(cat "${battery}/installed") -eq 0 ]; then
|
if [ $(cat "${battery}/installed") -eq 0 ]; then
|
||||||
|
@ -25,6 +26,9 @@ while true; do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bname="$(basename $battery | tr '[:upper:]' '[:lower:]')"
|
bname="$(basename $battery | tr '[:upper:]' '[:lower:]')"
|
||||||
|
ID=$(($ID+${bname/bat/}))
|
||||||
|
|
||||||
|
|
||||||
prefix="thinkpad-${bname}"
|
prefix="thinkpad-${bname}"
|
||||||
suffix=""
|
suffix=""
|
||||||
declare -A data
|
declare -A data
|
||||||
|
@ -39,48 +43,46 @@ while true; do
|
||||||
data[current-current]=$(echo "scale=2;$(cat ${battery}/current_now)/1000" | bc)
|
data[current-current]=$(echo "scale=2;$(cat ${battery}/current_now)/1000" | bc)
|
||||||
|
|
||||||
for key in "${!data[@]}"; do
|
for key in "${!data[@]}"; do
|
||||||
value=${data[$key]}
|
echo "PUTVAL $HOSTNAME/${prefix}/${key}${suffix} interval=$INTERVAL N:${data[$key]}"
|
||||||
echo "PUTVAL $HOSTNAME/${prefix}/${key}${suffix} interval=$INTERVAL N:${value}"
|
|
||||||
|
|
||||||
if [ ! ${idx[$key]+test} ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
sensor=${idx[$key]}
|
|
||||||
SEND="${DOMOTICZ_URL}&idx=${sensor}&battery=${data[percent-percent]}"
|
|
||||||
if grep -q "ac_connected" <<< "${key}"; then
|
|
||||||
svalue="ONLINE"
|
|
||||||
if [ "$value" == "0" ]; then
|
|
||||||
value=4
|
|
||||||
svalue="OFFLINE"
|
|
||||||
fi
|
|
||||||
SEND="${SEND}&nvalue=${value}&svalue=${svalue}"
|
|
||||||
else
|
|
||||||
SEND="${SEND}&nvalue=0&svalue=${value}"
|
|
||||||
fi
|
|
||||||
domoticz_send ${SEND}
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
mymqtt_update "${ID}" "${POWER_ID}" "${V_WATT}" "${data[power-power]}"
|
||||||
|
mymqtt_battery "${ID}" "${POWER_ID}" "${data[percent-percent]}"
|
||||||
|
|
||||||
|
mymqtt_update "${ID}" "${CURRENT_ID}" "${V_CURRENT}" "${data[current-current]}"
|
||||||
|
mymqtt_battery "${ID}" "${CURRENT_ID}" "${data[percent-percent]}"
|
||||||
|
|
||||||
|
mymqtt_update "${ID}" "${VOLTAGE_ID}" "${V_VOLTAGE}" "${data[voltage-voltage]}"
|
||||||
|
mymqtt_battery "${ID}" "${VOLTAGE_ID}" "${data[percent-percent]}"
|
||||||
|
|
||||||
|
mymqtt_update "${ID}" "${TEM_ID}" "${V_TEMP}" "${data[temperature-temperature]}"
|
||||||
|
mymqtt_battery "${ID}" "${TEM_ID}" "${data[percent-percent]}"
|
||||||
|
|
||||||
|
mymqtt_update "${ID}" "${AC_ID}" "${V_STATUS}" "${data[gauge-ac_connected]}"
|
||||||
|
mymqtt_battery "${ID}" "${AC_ID}" "${data[percent-percent]}"
|
||||||
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# fan
|
## fan
|
||||||
prefix="thinkpad-fan"
|
#prefix="thinkpad-fan"
|
||||||
suffix=""
|
#suffix=""
|
||||||
declare -A data
|
#declare -A data
|
||||||
status="$(cat /proc/acpi/ibm/fan)"
|
#status="$(cat /proc/acpi/ibm/fan)"
|
||||||
data[fanspeed-speed]=$(grep 'speed:' <<< "$status" | awk '{print $2}')
|
#data[fanspeed-speed]=$(grep 'speed:' <<< "$status" | awk '{print $2}')
|
||||||
data[gauge-fanlevel]=$(grep 'level:' <<< "$status" | awk '{print $2}')
|
#data[gauge-fanlevel]=$(grep 'level:' <<< "$status" | awk '{print $2}')
|
||||||
for key in "${!data[@]}"; do
|
#for key in "${!data[@]}"; do
|
||||||
value=${data[$key]}
|
#value=${data[$key]}
|
||||||
echo "PUTVAL $HOSTNAME/${prefix}/${key}${suffix} interval=$INTERVAL N:${data[$key]}"
|
#echo "PUTVAL $HOSTNAME/${prefix}/${key}${suffix} interval=$INTERVAL N:${data[$key]}"
|
||||||
|
|
||||||
if [ ! ${idx[$key]+test} ]; then
|
#if [ ! ${idx[$key]+test} ]; then
|
||||||
continue
|
#continue
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
sensor=${idx[$key]}
|
#sensor=${idx[$key]}
|
||||||
SEND="${DOMOTICZ_URL}&idx=${sensor}&battery=${data[percent-percent]}&svalue=${value}"
|
#SEND="${DOMOTICZ_URL}&idx=${sensor}&battery=${data[percent-percent]}&svalue=${value}"
|
||||||
domoticz_send ${SEND}
|
#domoticz_send ${SEND}
|
||||||
done
|
#done
|
||||||
|
|
||||||
sleep "$INTERVAL"
|
sleep "$INTERVAL"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue