Finish sensors reading scripts.

This commit is contained in:
yohan 2024-02-05 22:57:52 +01:00
parent 1bef7a67d3
commit b02aecfb89
2 changed files with 38 additions and 2 deletions

View File

@ -19,12 +19,16 @@ try:
try: try:
value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1) value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1)
except ValueError: except ValueError:
print (now()+" "+room+": Expected temperature, got garbage: "+returned_output) print ("Got garbage: "+returned_output)
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit(1) sys.exit(1)
data = {} data = {}
data[args.metric] = value if "luminosity" in args.metric:
# conversion en lm
data[args.metric] = int(float(value) * 122900.45063498567)
else:
data[args.metric] = value
print(json.dumps(data)) print(json.dumps(data))

32
read_yocto_sensor.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import json
import subprocess
import sys
parser = argparse.ArgumentParser(description='Read Yocto sensor.')
parser.add_argument('metric', type=str,
help='Metric name.')
parser.add_argument('binary', type=str,
help='Yocto binary.')
parser.add_argument('sensor', type=str,
help='Sensor name.')
args = parser.parse_args()
try:
returned_output = subprocess.check_output(["/usr/local/YoctoLib.cmdline.24497/Binaries/linux/32bits/"+args.binary, "-r", "localhost", "-f", "[result]", args.sensor, "get_currentValue"])
try:
value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1)
except ValueError:
print ("Got garbage: "+returned_output)
sys.exit(1)
except Exception as e:
print(e)
sys.exit(1)
data = {}
data[args.metric] = value
print(json.dumps(data))