From bc898c800912f066eba72e8310a88d0bf0c34265 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Thu, 28 Oct 2021 04:45:22 +0200 Subject: [PATCH] stromzaehler --- bundles/stromzaehler/files/stromzaehler | 20 +++++++++----------- bundles/stromzaehler/items.py | 7 +++++-- bundles/stromzaehler/metadata.py | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/bundles/stromzaehler/files/stromzaehler b/bundles/stromzaehler/files/stromzaehler index 8766f5b..6f0aa4f 100644 --- a/bundles/stromzaehler/files/stromzaehler +++ b/bundles/stromzaehler/files/stromzaehler @@ -1,14 +1,12 @@ #!/bin/bash -#set -x - +# gpiochip number + pin number gpio=$(expr 458 + 3) # prepare if ! [[ -e "/sys/class/gpio/gpio$gpio" ]]; then echo $gpio > "/sys/class/gpio/export" fi - echo in > "/sys/class/gpio/gpio$gpio/direction" # loop @@ -22,14 +20,14 @@ while sleep 0.001; do delay=$(expr $(date --utc +%s%N) - $previous_impulse) impulse_per_hour=$(expr 3600000000000 / $delay) watt=$(expr $impulse_per_hour / $(expr 2000 / 1000)) - echo $watt > /tmp/watt - echo $delay $impulse_per_hour $watt - # curl "https://${influxdb_domain}/ping" ${'\\'} - # -X POST ${'\\'} - # -H "Authentication: Token ${influxdb_token}" ${'\\'} - # -d "bucket=${influxdb_bucket}" ${'\\'} - # -d "ord=${influxdb_org}" ${'\\'} - # -d "data=powermeter,host=${node_name} watts=$watt" + echo "$watt watts" + curl "https://${influxdb_domain}/api/v2/write?org=${influxdb_org}&bucket=${influxdb_bucket}&precision=ns" ${'\\'} + -X POST ${'\\'} + --header "Authorization: Token ${influxdb_token}" ${'\\'} + --header "Content-Type: text/plain; charset=utf-8" ${'\\'} + --header "Accept: application/json" ${'\\'} + --data-binary "powermeter,host=${node_name} watts=$watt" ${'\\'} + 2&> /dev/null & fi previous_impulse=$(date --utc +%s%N) fi diff --git a/bundles/stromzaehler/items.py b/bundles/stromzaehler/items.py index b861f1e..1cc12f5 100644 --- a/bundles/stromzaehler/items.py +++ b/bundles/stromzaehler/items.py @@ -11,13 +11,16 @@ files = { 'influxdb_org': influxdb_metadata['org'], 'influxdb_token': influxdb_metadata['admin_token'], }, + 'triggers': [ + 'svc_systemd:stromzaehler:restart' + ], }, } svc_systemd = { 'stromzaehler': { - 'enabled': False, - 'running': False, + # 'enabled': False, + # 'running': False, 'needs': [ 'file:/opt/stromzaehler', ], diff --git a/bundles/stromzaehler/metadata.py b/bundles/stromzaehler/metadata.py index f5ba9a8..7d74f4a 100644 --- a/bundles/stromzaehler/metadata.py +++ b/bundles/stromzaehler/metadata.py @@ -1,6 +1,7 @@ defaults = { 'apt': { 'packages': { + 'curl': {}, 'gpiod': {}, }, },