diff options
| author | D Delmar Davis <don@suspectdevices.com> | 2023-08-07 20:50:18 -0700 |
|---|---|---|
| committer | D Delmar Davis <don@suspectdevices.com> | 2023-08-07 20:50:18 -0700 |
| commit | f6a0e996240a8dda1f742700f13a8e77dc18c08e (patch) | |
| tree | 1e40c695f9b06e9349913306b3286eaef73039ac | |
| parent | a7c74d2f92980c568f8da48e832636a90463427d (diff) | |
| parent | eb806d556c3b67eb5021af7498c6a72de1bf43f1 (diff) | |
add barametric pressure sensor
| -rw-r--r-- | docs/connections.md | 4 | ||||
| -rw-r--r-- | docs/images/qwiic.png | bin | 0 -> 38528 bytes | |||
| -rw-r--r-- | docs/images/refinement.png | bin | 0 -> 187241 bytes | |||
| -rwxr-xr-x | fetchtemp.py | 6 | ||||
| -rw-r--r-- | fetchtemp.py.save | 8 | ||||
| -rwxr-xr-x | readtemp.py | 53 | ||||
| -rw-r--r-- | requirements.txt | 4 |
7 files changed, 60 insertions, 15 deletions
diff --git a/docs/connections.md b/docs/connections.md new file mode 100644 index 0000000..d7e003a --- /dev/null +++ b/docs/connections.md @@ -0,0 +1,4 @@ +- dht20  +- tc74  +- pi header  +- qwiic 
\ No newline at end of file diff --git a/docs/images/qwiic.png b/docs/images/qwiic.png Binary files differnew file mode 100644 index 0000000..56e50bf --- /dev/null +++ b/docs/images/qwiic.png diff --git a/docs/images/refinement.png b/docs/images/refinement.png Binary files differnew file mode 100644 index 0000000..97bcdf0 --- /dev/null +++ b/docs/images/refinement.png diff --git a/fetchtemp.py b/fetchtemp.py new file mode 100755 index 0000000..92a4b8f --- /dev/null +++ b/fetchtemp.py @@ -0,0 +1,6 @@ +#!/usr/bin/python +with open('/var/lib/prometheus/node-exporter/temp.prom', 'r') as f: + for line in f.readlines(): + if 'Xhome_temperature_farenheit' in ('X'+line) : + print(line.split(' ')[1]) + diff --git a/fetchtemp.py.save b/fetchtemp.py.save new file mode 100644 index 0000000..6297272 --- /dev/null +++ b/fetchtemp.py.save @@ -0,0 +1,8 @@ + +with open('/var/lib/prometheus/node-exporter/temp.prom', 'r') as f: + for line in f.readlines(): + if 'Xhome_temperature_farenheit' in ('X'+line) : + print(line) + else: + print("???", line, "???") + diff --git a/readtemp.py b/readtemp.py index 9e2e112..899fc47 100755 --- a/readtemp.py +++ b/readtemp.py @@ -7,32 +7,51 @@ import sys import board import adafruit_tc74 import adafruit_ahtx0 +import adafruit_sht4x +from adafruit_dps310.basic import DPS310 import tempfile import os -GotTemperature = False -GotHumidity = False -TempRead=0 -HumidityRead=0 +i_can_has_temperature = False +i_can_has_humidity = False +i_can_has_pressure = False +temperature_read=0 +humidity_read=0 +pressure_read=0 i2c = board.I2C() # uses board.SCL and board.SDA +print(i2c.scan()) for tempsensorid in i2c.scan(): if (tempsensorid==72): print ("found a TC74") sensor = adafruit_tc74.TC74(i2c) - TempRead=sensor.temperature - GotTemperature = True + temperature_read=sensor.temperature + i_can_has_temperature = True elif (tempsensorid==56): print ("found an AHTx0") sensor = adafruit_ahtx0.AHTx0(i2c) - TempRead=sensor.temperature - GotTemperature = True - HumidityRead = sensor.relative_humidity - GotHumidity = True + temperature_read=sensor.temperature + i_can_has_temperature = True + humidity_read = sensor.relative_humidity + i_can_has_humidity = True + elif (False): # tempsensorid==44): + print ("found an SHT4x") + sensor = adafruit_sht4x.SHT4x(board.I2C()) + temperature_read=sensor.temperature + i_can_has_temperature = True + humidity_read = sensor.relative_humidity + i_can_has_humidity = True + elif (tempsensorid==119): + print ("found a EPS310") + sensor = DPS310(i2c) + temperature_read=sensor.temperature + i_can_has_temperature = True + pressure_read = sensor.pressure + i_can_has_pressure = True else: print ("found something else ", tempsensorid) -if (GotTemperature): +if (i_can_has_temperature): tmpfile =os.path.join(tempfile.gettempdir(),'temp.prom') @@ -41,13 +60,17 @@ if (GotTemperature): sys.stdout = file print("# HELP home_temperature_farenheit Temperature read off of external sensor.") print("# TYPE home_temperature_farenheit gauge") - print("home_temperature_farenheit %0.3f" % ((sensor.temperature * 1.8) + 32.0)) + print("home_temperature_farenheit %0.3f" % ((temperature_read * 1.8) + 32.0)) print("# HELP home_temperature_celsius Temperature read off of external sensor.") print("# TYPE home_temperature_celsius gauge") - print("home_temperature_celcius %0.3f" % sensor.temperature) - if (GotHumidity): + print("home_temperature_celcius %0.3f" % temperature_read) + if (i_can_has_humidity): print("# HELP home_relative_humidity Temperature read off of external sensor.") print("# TYPE home_relative_humidity gauge") - print("home_relative_humidity %0.3f" % sensor.relative_humidity) + print("home_relative_humidity %0.3f" % humidity_read) + if (i_can_has_pressure): + print("# HELP home_barometric_pressure Barometric Pressure read off of external sensor.") + print("# TYPE home_barometric_pressure gauge") + print("home_barometric_pressure %0.3f" % pressure_read) file.close() os.replace(tmpfile, '/var/lib/prometheus/node-exporter/temp.prom') diff --git a/requirements.txt b/requirements.txt index 4c4e447..b29d2e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,12 @@ Adafruit-Blinka==8.20.1 adafruit-circuitpython-ahtx0==1.0.18 adafruit-circuitpython-busdevice==5.2.6 +adafruit-circuitpython-dps310==2.1.12 +adafruit-circuitpython-epd==2.12.0 +adafruit-circuitpython-framebuf==1.6.3 adafruit-circuitpython-register==1.9.16 adafruit-circuitpython-requests==2.0.1 +adafruit-circuitpython-sht4x==1.0.17 adafruit-circuitpython-tc74==1.0.15 adafruit-circuitpython-typing==1.9.4 Adafruit-PlatformDetect==3.49.0 |
