stromzaehler

This commit is contained in:
mwiegand 2021-10-28 04:45:22 +02:00
parent 43cf6cabea
commit bc898c8009
3 changed files with 15 additions and 13 deletions

View file

@ -1,14 +1,12 @@
#!/bin/bash #!/bin/bash
#set -x # gpiochip number + pin number
gpio=$(expr 458 + 3) gpio=$(expr 458 + 3)
# prepare # prepare
if ! [[ -e "/sys/class/gpio/gpio$gpio" ]]; then if ! [[ -e "/sys/class/gpio/gpio$gpio" ]]; then
echo $gpio > "/sys/class/gpio/export" echo $gpio > "/sys/class/gpio/export"
fi fi
echo in > "/sys/class/gpio/gpio$gpio/direction" echo in > "/sys/class/gpio/gpio$gpio/direction"
# loop # loop
@ -22,14 +20,14 @@ while sleep 0.001; do
delay=$(expr $(date --utc +%s%N) - $previous_impulse) delay=$(expr $(date --utc +%s%N) - $previous_impulse)
impulse_per_hour=$(expr 3600000000000 / $delay) impulse_per_hour=$(expr 3600000000000 / $delay)
watt=$(expr $impulse_per_hour / $(expr 2000 / 1000)) watt=$(expr $impulse_per_hour / $(expr 2000 / 1000))
echo $watt > /tmp/watt echo "$watt watts"
echo $delay $impulse_per_hour $watt curl "https://${influxdb_domain}/api/v2/write?org=${influxdb_org}&bucket=${influxdb_bucket}&precision=ns" ${'\\'}
# curl "https://${influxdb_domain}/ping" ${'\\'} -X POST ${'\\'}
# -X POST ${'\\'} --header "Authorization: Token ${influxdb_token}" ${'\\'}
# -H "Authentication: Token ${influxdb_token}" ${'\\'} --header "Content-Type: text/plain; charset=utf-8" ${'\\'}
# -d "bucket=${influxdb_bucket}" ${'\\'} --header "Accept: application/json" ${'\\'}
# -d "ord=${influxdb_org}" ${'\\'} --data-binary "powermeter,host=${node_name} watts=$watt" ${'\\'}
# -d "data=powermeter,host=${node_name} watts=$watt" 2&> /dev/null &
fi fi
previous_impulse=$(date --utc +%s%N) previous_impulse=$(date --utc +%s%N)
fi fi

View file

@ -11,13 +11,16 @@ files = {
'influxdb_org': influxdb_metadata['org'], 'influxdb_org': influxdb_metadata['org'],
'influxdb_token': influxdb_metadata['admin_token'], 'influxdb_token': influxdb_metadata['admin_token'],
}, },
'triggers': [
'svc_systemd:stromzaehler:restart'
],
}, },
} }
svc_systemd = { svc_systemd = {
'stromzaehler': { 'stromzaehler': {
'enabled': False, # 'enabled': False,
'running': False, # 'running': False,
'needs': [ 'needs': [
'file:/opt/stromzaehler', 'file:/opt/stromzaehler',
], ],

View file

@ -1,6 +1,7 @@
defaults = { defaults = {
'apt': { 'apt': {
'packages': { 'packages': {
'curl': {},
'gpiod': {}, 'gpiod': {},
}, },
}, },