aboutsummaryrefslogtreecommitdiff
path: root/readtemp.py
diff options
context:
space:
mode:
authorD Delmar Davis <don@suspectdevices.com>2023-08-02 11:38:56 -0700
committerD Delmar Davis <don@suspectdevices.com>2023-08-02 11:38:56 -0700
commit6d47499e7f77ee55d3cbe54372d0d0e6c3e8ea5c (patch)
treeb01f44dda19d5c530e5f956810eec13ab6fec210 /readtemp.py
parent98c60c5698c2e5d4858b59f6e01f07022c1a284b (diff)
Test Board Scan
Diffstat (limited to 'readtemp.py')
-rwxr-xr-xreadtemp.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/readtemp.py b/readtemp.py
index 775184e..9b984a1 100755
--- a/readtemp.py
+++ b/readtemp.py
@@ -8,20 +8,30 @@ import board
import adafruit_tc74
import tempfile
import os
+
+GotTemperature = False
+TempRead=0
+
i2c = board.I2C() # uses board.SCL and board.SDA
-# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
-sensor = adafruit_tc74.TC74(i2c)
+for tempsensorid in i2c.scan():
+ if (tempsensorid=72):
+ print ("found a TC74")
+ sensor = adafruit_tc74.TC74(i2c)
+ TempRead=sensor.temperature
+ GotTemperature = True
-tmpfile =os.path.join(tempfile.gettempdir(),'temp.prom')
+if (GotTemperature):
+
+ tmpfile =os.path.join(tempfile.gettempdir(),'temp.prom')
-#file = open('/var/lib/prometheus/node-exporter/temp.prom', 'w')
-file = open(tmpfile, 'w')
-sys.stdout = file
-print("# HELP ambient_temperature_farenheit Temperature read off of external sensor.")
-print("# TYPE ambient_temperature_farenheit gauge")
-print("ambient_temperature_farenheit{type=\"backyard\"} %0.3f" % ((sensor.temperature * 1.8) + 32.0))
-print("# HELP ambient_temperature_celsius Temperature read off of external sensor.")
-print("# TYPE ambient_temperature_celsius gauge")
-print("ambient_temperature_celcius{type=\"backyard\"} %0.3f" % sensor.temperature)
-file.close()
-os.replace(tmpfile, '/var/lib/prometheus/node-exporter/temp.prom')
+ #file = open('/var/lib/prometheus/node-exporter/temp.prom', 'w')
+ file = open(tmpfile, 'w')
+ sys.stdout = file
+ print("# HELP ambient_temperature_farenheit Temperature read off of external sensor.")
+ print("# TYPE ambient_temperature_farenheit gauge")
+ print("ambient_temperature_farenheit{type=\"backyard\"} %0.3f" % ((sensor.temperature * 1.8) + 32.0))
+ print("# HELP ambient_temperature_celsius Temperature read off of external sensor.")
+ print("# TYPE ambient_temperature_celsius gauge")
+ print("ambient_temperature_celcius{type=\"backyard\"} %0.3f" % sensor.temperature)
+ file.close()
+ os.replace(tmpfile, '/var/lib/prometheus/node-exporter/temp.prom')