Skip to content

Commit c133431

Browse files
Merge pull request #43 from AllskyTeam/dev
Point release 4
2 parents c381a72 + 61191ce commit c133431

12 files changed

Lines changed: 381 additions & 193 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 AllskyTeam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

allsky_dewheater/allsky_dewheater.py

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,31 @@
99
- Added extra pin that is triggered with heater pin
1010
- Fixed dhtxxdelay (was not implemented)
1111
- Fixed max heater time (was not implemented)
12-
12+
V1.0.2 by Alex Greenland
13+
- Updated code for pi 5
14+
- Moved to core allsky
1315
'''
1416
import allsky_shared as s
1517
import time
18+
import sys
19+
import board
1620
import adafruit_sht31d
1721
import adafruit_dht
1822
from adafruit_bme280 import basic as adafruit_bme280
1923
from adafruit_htu21d import HTU21D
20-
import board
21-
import busio
22-
import RPi.GPIO as GPIO
2324
from meteocalc import heat_index
2425
from meteocalc import dew_point
25-
26+
from digitalio import DigitalInOut, Direction, Pull
27+
2628
metaData = {
2729
"name": "Sky Dew Heater Control",
2830
"description": "Controls a dew heater via a temperature and humidity sensor",
2931
"module": "allsky_dewheater",
30-
"version": "v1.0.1",
32+
"version": "v1.0.2",
3133
"events": [
3234
"periodic"
3335
],
34-
"experimental": "true",
36+
"experimental": "false",
3537
"arguments":{
3638
"type": "None",
3739
"inputpin": "",
@@ -223,8 +225,9 @@ def readSHT31(sht31heater):
223225
sensor.heater = sht31heater
224226
temperature = sensor.temperature
225227
humidity = sensor.relative_humidity
226-
except:
227-
pass
228+
except RuntimeError as e:
229+
eType, eObject, eTraceback = sys.exc_info()
230+
s.log(4, f"ERROR: Module readSHT31 failed on line {eTraceback.tb_lineno} - {e}")
228231

229232
return temperature, humidity
230233

@@ -238,10 +241,12 @@ def doDHTXXRead(inputpin):
238241
try:
239242
temperature = dhtDevice.temperature
240243
humidity = dhtDevice.humidity
241-
except RuntimeError as error:
242-
s.log(4, "INFO: {}".format(error))
243-
except Exception as error:
244-
s.log(4, "INFO: {}".format(error))
244+
except RuntimeError as e:
245+
eType, eObject, eTraceback = sys.exc_info()
246+
s.log(4, f"ERROR: Module doDHTXXRead failed on line {eTraceback.tb_lineno} - {e}")
247+
except Exception as e:
248+
eType, eObject, eTraceback = sys.exc_info()
249+
s.log(4, f"ERROR: Module doDHTXXRead failed on line {eTraceback.tb_lineno} - {e}")
245250

246251
return temperature, humidity
247252

@@ -276,9 +281,9 @@ def readBme280I2C(i2caddress):
276281
if i2caddress != "":
277282
try:
278283
i2caddressInt = int(i2caddress, 16)
279-
except:
280-
result = "Address {} is not a valid i2c address".format(i2caddress)
281-
s.log(0,"ERROR: {}".format(result))
284+
except Exception as e:
285+
eType, eObject, eTraceback = sys.exc_info()
286+
s.log(0, f"ERROR: Module readBme280I2C failed on line {eTraceback.tb_lineno} - {e}")
282287

283288
try:
284289
i2c = board.I2C()
@@ -292,8 +297,9 @@ def readBme280I2C(i2caddress):
292297
relHumidity = bme280.relative_humidity
293298
altitude = bme280.altitude
294299
pressure = bme280.pressure
295-
except ValueError:
296-
pass
300+
except ValueError as e:
301+
eType, eObject, eTraceback = sys.exc_info()
302+
s.log(0, f"ERROR: Module readBme280I2C failed on line {eTraceback.tb_lineno} - {e}")
297303

298304
return temperature, humidity, pressure, relHumidity, altitude
299305

@@ -317,49 +323,50 @@ def readHtu21(i2caddress):
317323

318324
temperature = htu21.temperature
319325
humidity = htu21.relative_humidity
320-
except ValueError:
321-
pass
322-
326+
except ValueError as e:
327+
eType, eObject, eTraceback = sys.exc_info()
328+
s.log(4, f"ERROR: Module readHtu21 failed on line {eTraceback.tb_lineno} - {e}")
329+
323330
return temperature, humidity
324331

325-
def setmode():
326-
try:
327-
GPIO.setmode(GPIO.BOARD)
328-
except:
329-
pass
330-
331-
def turnHeaterOn(heaterpin, invertrelay):
332-
result = "Turning Heater on"
333-
setmode()
334-
GPIO.setup(heaterpin.id, GPIO.OUT)
332+
def turnHeaterOn(heaterpin, invertrelay, extra=False):
333+
if extra:
334+
type = 'Extra'
335+
else:
336+
type = 'Heater'
337+
338+
result = f"Turning {type} on using pin {heaterpin}"
339+
pin = DigitalInOut(heaterpin)
340+
pin.switch_to_output()
341+
335342
if invertrelay:
336-
if GPIO.input(heaterpin.id) == 0:
337-
result = "Leaving Heater on"
338-
GPIO.output(heaterpin.id, GPIO.LOW)
343+
pin.value = 0
339344
else:
340-
if GPIO.input(heaterpin.id) == 1:
341-
result = "Leaving Heater on"
342-
GPIO.output(heaterpin.id, GPIO.HIGH)
345+
pin.value = 1
346+
343347
if not s.dbHasKey("dewheaterontime"):
344348
now = int(time.time())
345349
s.dbAdd("dewheaterontime", now)
346-
s.log(1,"INFO: {}".format(result))
350+
s.log(1,f"INFO: {result}")
347351

348-
def turnHeaterOff(heaterpin, invertrelay):
349-
result = "Turning Heater off"
350-
setmode()
351-
GPIO.setup(heaterpin.id, GPIO.OUT)
352+
def turnHeaterOff(heaterpin, invertrelay, extra=False):
353+
if extra:
354+
type = 'Extra'
355+
else:
356+
type = 'Heater'
357+
358+
result = f"Turning {type} off using pin {heaterpin}"
359+
pin = DigitalInOut(heaterpin)
360+
pin.direction = Direction.OUTPUT
361+
352362
if invertrelay:
353-
if GPIO.input(heaterpin.id) == 1:
354-
result = "Leaving Heater off"
355-
GPIO.output(heaterpin.id, GPIO.HIGH)
363+
pin.value = 1
356364
else:
357-
if GPIO.input(heaterpin.id) == 0:
358-
result = "Leaving Heater off"
359-
GPIO.output(heaterpin.id, GPIO.LOW)
365+
pin.value = 0
366+
360367
if s.dbHasKey("dewheaterontime"):
361368
s.dbDeleteKey("dewheaterontime")
362-
s.log(1,"INFO: {}".format(result))
369+
s.log(1,f"INFO: {result}")
363370

364371
def getSensorReading(sensorType, inputpin, i2caddress, dhtxxretrycount, dhtxxdelay, sht31heater):
365372
temperature = None
@@ -409,8 +416,8 @@ def getLastRunTime():
409416

410417
def debugOutput(sensorType, temperature, humidity, dewPoint, heatIndex, pressure, relHumidity, altitude):
411418
s.log(1,f"INFO: Sensor {sensorType} read. Temperature {temperature} Humidity {humidity} Relative Humidity {relHumidity} Dew Point {dewPoint} Heat Index {heatIndex} Pressure {pressure} Altitude {altitude}")
412-
413-
def dewheater(params, event):
419+
420+
def dewheater(params, event):
414421
result = ""
415422
sensorType = params["type"]
416423
heaterstartupstate = params["heaterstartupstate"]
@@ -446,7 +453,7 @@ def dewheater(params, event):
446453

447454
shouldRun, diff = s.shouldRun('allskydew', frequency)
448455

449-
if shouldRun:
456+
if shouldRun:
450457
try:
451458
heaterpin = int(heaterpin)
452459
except ValueError:
@@ -473,14 +480,14 @@ def dewheater(params, event):
473480
s.log(1,"INFO: {}".format(result))
474481
turnHeaterOff(heaterpin, invertrelay)
475482
if extrapin != 0:
476-
turnHeaterOff(extrapin, invertextrapin)
483+
turnHeaterOff(extrapin, invertextrapin, True)
477484
heater = 'Off'
478485
elif force != 0 and temperature <= force:
479486
result = "Temperature below forced level {}".format(force)
480487
s.log(1,"INFO: {}".format(result))
481488
turnHeaterOn(heaterpin, invertrelay)
482489
if extrapin != 0:
483-
turnHeaterOn(extrapin, invertextrapin)
490+
turnHeaterOn(extrapin, invertextrapin, True)
484491
heater = 'On'
485492
else:
486493
if ((temperature-limit) <= dewPoint):
@@ -495,9 +502,9 @@ def dewheater(params, event):
495502
s.log(1,"INFO: {}".format(result))
496503
turnHeaterOff(heaterpin, invertrelay)
497504
if extrapin != 0:
498-
turnHeaterOff(extrapin, invertextrapin)
505+
turnHeaterOff(extrapin, invertextrapin, True)
499506
heater = 'Off'
500-
507+
501508
extraData = {}
502509
extraData["AS_DEWCONTROLAMBIENT"] = str(temperature)
503510
extraData["AS_DEWCONTROLDEW"] = str(dewPoint)

allsky_dewheater/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ adafruit-circuitpython-sht31d
22
adafruit-circuitpython-bme280
33
adafruit-circuitpython-dht
44
adafruit-circuitpython-htu21d
5-
Adafruit_DHT
5+
adafruit-circuitpython-dht
6+
barbudor-circuitpython-ina3221
67
meteocalc

allsky_fans/allsky_fans.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import shutil
1212
from vcgencmd import Vcgencmd
1313
import board
14-
import RPi.GPIO as GPIO
14+
from digitalio import DigitalInOut, Direction, Pull
1515

1616
metaData = {
1717
"name": "Control Allsky Fans",
@@ -79,40 +79,30 @@ def getTemperature():
7979

8080
return tempC
8181

82-
def setmode():
83-
try:
84-
GPIO.setmode(GPIO.BOARD)
85-
except:
86-
pass
8782

8883
def turnFansOn(fanpin, invertrelay):
8984
result = "Turning Fans ON"
90-
setmode()
91-
GPIO.setup(fanpin.id, GPIO.OUT)
85+
pin = DigitalInOut(fanpin)
86+
pin.switch_to_output()
87+
9288
if invertrelay:
93-
if GPIO.input(fanpin.id) == 0:
94-
result = "Leaving Fans ON"
95-
GPIO.output(fanpin.id, GPIO.LOW)
89+
pin.value = 0
9690
else:
97-
if GPIO.input(fanpin.id) == 1:
98-
result = "Leaving Fans ON"
99-
GPIO.output(fanpin.id, GPIO.HIGH)
100-
s.log(1,"INFO: {}".format(result))
91+
pin.value = 1
92+
93+
s.log(1,f"INFO: {result}")
10194

10295
def turnFansOff(fanpin, invertrelay):
10396
result = "Turning Fans OFF"
104-
setmode()
105-
GPIO.setup(fanpin.id, GPIO.OUT)
97+
pin = DigitalInOut(fanpin)
98+
pin.switch_to_output()
10699

107100
if invertrelay:
108-
if GPIO.input(fanpin.id) == 1:
109-
result = "Leaving Fans OFF"
110-
GPIO.output(fanpin.id, GPIO.HIGH)
101+
pin.value = 1
111102
else:
112-
if GPIO.input(fanpin.id) == 0:
113-
result = "Leaving Fans OFF"
114-
GPIO.output(fanpin.id, GPIO.LOW)
115-
s.log(1,"INFO: {}".format(result))
103+
pin.value = 0
104+
105+
s.log(1,f"INFO: {result}")
116106

117107
def fans(params, event):
118108
result = ''

allsky_ina3221/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# AllSky INA3221 Module
2+
3+
| | |
4+
| ------------ | ------------ |
5+
| **Status** | Experimental |
6+
| **Level** | Experienced |
7+
| **Runs In** | Periodic |
8+
9+
A simple module to read 1 to 3 channels from an INA3221 voltage and current sensor.
10+
11+
These modules can be useful for monitoring the current being fed to a dew heater to determine if its actually working or not

0 commit comments

Comments
 (0)