Last active
October 12, 2022 04:09
-
-
Save RobertCNelson/80ea67f5aac482a1cfdaff88e374e273 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import os | |
| import time | |
| import sys | |
| temp_raw = open("/sys/bus/iio/devices/iio:device0/in_temp_raw", "r") | |
| temp_offset = open("/sys/bus/iio/devices/iio:device0/in_temp_offset", "r") | |
| temp_scale = open("/sys/bus/iio/devices/iio:device0/in_temp_scale", "r") | |
| devID = "i2c_hts221" | |
| temp_raw_value = float(temp_raw.read()) | |
| temp_raw.seek(0) | |
| temp_raw.close() | |
| temp_offset_value = float(temp_offset.read()) | |
| temp_offset.seek(0) | |
| temp_offset.close() | |
| temp_scale_value = float(temp_scale.read()) | |
| temp_scale.seek(0) | |
| temp_scale.close() | |
| tempC = (temp_offset_value + temp_raw_value) * temp_scale_value | |
| tempF = (tempC * 9/5) + 32 | |
| humidity_raw = open("/sys/bus/iio/devices/iio:device0/in_humidityrelative_raw", "r") | |
| humidity_offset = open("/sys/bus/iio/devices/iio:device0/in_humidityrelative_offset", "r") | |
| humidity_scale = open("/sys/bus/iio/devices/iio:device0/in_humidityrelative_scale", "r") | |
| humidity_raw_value = float(humidity_raw.read()) | |
| humidity_raw.seek(0) | |
| humidity_raw.close() | |
| humidity_offset_value = float(humidity_offset.read()) | |
| humidity_offset.seek(0) | |
| humidity_offset.close() | |
| humidity_scale_value = float(humidity_scale.read()) | |
| humidity_scale.seek(0) | |
| humidity_scale.close() | |
| humidity = (humidity_offset_value + humidity_raw_value) * humidity_scale_value | |
| print("metric:id=%s,n=Temperature,vd=%0.2f,u=F" % (devID, tempF)) | |
| print("metric:id=%s,n=Humidity,vd=%0.2f,u=%%" % (devID, humidity)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment