diff --git a/read_one-wire_sensor.py b/read_one-wire_sensor.py index 6023747..5e899c9 100755 --- a/read_one-wire_sensor.py +++ b/read_one-wire_sensor.py @@ -19,12 +19,16 @@ try: try: value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1) except ValueError: - print (now()+" "+room+": Expected temperature, got garbage: "+returned_output) + print ("Got garbage: "+returned_output) sys.exit(1) except Exception as e: print(e) sys.exit(1) 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)) diff --git a/read_yocto_sensor.py b/read_yocto_sensor.py new file mode 100755 index 0000000..4c3e9fc --- /dev/null +++ b/read_yocto_sensor.py @@ -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))