Skip to content

Commit

Permalink
Merge pull request #43 from AllskyTeam/dev
Browse files Browse the repository at this point in the history
Point release 4
  • Loading branch information
Alex-developer authored Dec 22, 2023
2 parents c381a72 + 61191ce commit c133431
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 193 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 AllskyTeam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
119 changes: 63 additions & 56 deletions allsky_dewheater/allsky_dewheater.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@
- Added extra pin that is triggered with heater pin
- Fixed dhtxxdelay (was not implemented)
- Fixed max heater time (was not implemented)
V1.0.2 by Alex Greenland
- Updated code for pi 5
- Moved to core allsky
'''
import allsky_shared as s
import time
import sys
import board
import adafruit_sht31d
import adafruit_dht
from adafruit_bme280 import basic as adafruit_bme280
from adafruit_htu21d import HTU21D
import board
import busio
import RPi.GPIO as GPIO
from meteocalc import heat_index
from meteocalc import dew_point

from digitalio import DigitalInOut, Direction, Pull

metaData = {
"name": "Sky Dew Heater Control",
"description": "Controls a dew heater via a temperature and humidity sensor",
"module": "allsky_dewheater",
"version": "v1.0.1",
"version": "v1.0.2",
"events": [
"periodic"
],
"experimental": "true",
"experimental": "false",
"arguments":{
"type": "None",
"inputpin": "",
Expand Down Expand Up @@ -223,8 +225,9 @@ def readSHT31(sht31heater):
sensor.heater = sht31heater
temperature = sensor.temperature
humidity = sensor.relative_humidity
except:
pass
except RuntimeError as e:
eType, eObject, eTraceback = sys.exc_info()
s.log(4, f"ERROR: Module readSHT31 failed on line {eTraceback.tb_lineno} - {e}")

return temperature, humidity

Expand All @@ -238,10 +241,12 @@ def doDHTXXRead(inputpin):
try:
temperature = dhtDevice.temperature
humidity = dhtDevice.humidity
except RuntimeError as error:
s.log(4, "INFO: {}".format(error))
except Exception as error:
s.log(4, "INFO: {}".format(error))
except RuntimeError as e:
eType, eObject, eTraceback = sys.exc_info()
s.log(4, f"ERROR: Module doDHTXXRead failed on line {eTraceback.tb_lineno} - {e}")
except Exception as e:
eType, eObject, eTraceback = sys.exc_info()
s.log(4, f"ERROR: Module doDHTXXRead failed on line {eTraceback.tb_lineno} - {e}")

return temperature, humidity

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

try:
i2c = board.I2C()
Expand All @@ -292,8 +297,9 @@ def readBme280I2C(i2caddress):
relHumidity = bme280.relative_humidity
altitude = bme280.altitude
pressure = bme280.pressure
except ValueError:
pass
except ValueError as e:
eType, eObject, eTraceback = sys.exc_info()
s.log(0, f"ERROR: Module readBme280I2C failed on line {eTraceback.tb_lineno} - {e}")

return temperature, humidity, pressure, relHumidity, altitude

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

temperature = htu21.temperature
humidity = htu21.relative_humidity
except ValueError:
pass

except ValueError as e:
eType, eObject, eTraceback = sys.exc_info()
s.log(4, f"ERROR: Module readHtu21 failed on line {eTraceback.tb_lineno} - {e}")

return temperature, humidity

def setmode():
try:
GPIO.setmode(GPIO.BOARD)
except:
pass

def turnHeaterOn(heaterpin, invertrelay):
result = "Turning Heater on"
setmode()
GPIO.setup(heaterpin.id, GPIO.OUT)
def turnHeaterOn(heaterpin, invertrelay, extra=False):
if extra:
type = 'Extra'
else:
type = 'Heater'
result = f"Turning {type} on using pin {heaterpin}"
pin = DigitalInOut(heaterpin)
pin.switch_to_output()

if invertrelay:
if GPIO.input(heaterpin.id) == 0:
result = "Leaving Heater on"
GPIO.output(heaterpin.id, GPIO.LOW)
pin.value = 0
else:
if GPIO.input(heaterpin.id) == 1:
result = "Leaving Heater on"
GPIO.output(heaterpin.id, GPIO.HIGH)
pin.value = 1

if not s.dbHasKey("dewheaterontime"):
now = int(time.time())
s.dbAdd("dewheaterontime", now)
s.log(1,"INFO: {}".format(result))
s.log(1,f"INFO: {result}")

def turnHeaterOff(heaterpin, invertrelay):
result = "Turning Heater off"
setmode()
GPIO.setup(heaterpin.id, GPIO.OUT)
def turnHeaterOff(heaterpin, invertrelay, extra=False):
if extra:
type = 'Extra'
else:
type = 'Heater'

result = f"Turning {type} off using pin {heaterpin}"
pin = DigitalInOut(heaterpin)
pin.direction = Direction.OUTPUT

if invertrelay:
if GPIO.input(heaterpin.id) == 1:
result = "Leaving Heater off"
GPIO.output(heaterpin.id, GPIO.HIGH)
pin.value = 1
else:
if GPIO.input(heaterpin.id) == 0:
result = "Leaving Heater off"
GPIO.output(heaterpin.id, GPIO.LOW)
pin.value = 0

if s.dbHasKey("dewheaterontime"):
s.dbDeleteKey("dewheaterontime")
s.log(1,"INFO: {}".format(result))
s.log(1,f"INFO: {result}")

def getSensorReading(sensorType, inputpin, i2caddress, dhtxxretrycount, dhtxxdelay, sht31heater):
temperature = None
Expand Down Expand Up @@ -409,8 +416,8 @@ def getLastRunTime():

def debugOutput(sensorType, temperature, humidity, dewPoint, heatIndex, pressure, relHumidity, altitude):
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}")

def dewheater(params, event):
def dewheater(params, event):
result = ""
sensorType = params["type"]
heaterstartupstate = params["heaterstartupstate"]
Expand Down Expand Up @@ -446,7 +453,7 @@ def dewheater(params, event):

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

if shouldRun:
if shouldRun:
try:
heaterpin = int(heaterpin)
except ValueError:
Expand All @@ -473,14 +480,14 @@ def dewheater(params, event):
s.log(1,"INFO: {}".format(result))
turnHeaterOff(heaterpin, invertrelay)
if extrapin != 0:
turnHeaterOff(extrapin, invertextrapin)
turnHeaterOff(extrapin, invertextrapin, True)
heater = 'Off'
elif force != 0 and temperature <= force:
result = "Temperature below forced level {}".format(force)
s.log(1,"INFO: {}".format(result))
turnHeaterOn(heaterpin, invertrelay)
if extrapin != 0:
turnHeaterOn(extrapin, invertextrapin)
turnHeaterOn(extrapin, invertextrapin, True)
heater = 'On'
else:
if ((temperature-limit) <= dewPoint):
Expand All @@ -495,9 +502,9 @@ def dewheater(params, event):
s.log(1,"INFO: {}".format(result))
turnHeaterOff(heaterpin, invertrelay)
if extrapin != 0:
turnHeaterOff(extrapin, invertextrapin)
turnHeaterOff(extrapin, invertextrapin, True)
heater = 'Off'

extraData = {}
extraData["AS_DEWCONTROLAMBIENT"] = str(temperature)
extraData["AS_DEWCONTROLDEW"] = str(dewPoint)
Expand Down
3 changes: 2 additions & 1 deletion allsky_dewheater/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ adafruit-circuitpython-sht31d
adafruit-circuitpython-bme280
adafruit-circuitpython-dht
adafruit-circuitpython-htu21d
Adafruit_DHT
adafruit-circuitpython-dht
barbudor-circuitpython-ina3221
meteocalc
38 changes: 14 additions & 24 deletions allsky_fans/allsky_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import shutil
from vcgencmd import Vcgencmd
import board
import RPi.GPIO as GPIO
from digitalio import DigitalInOut, Direction, Pull

metaData = {
"name": "Control Allsky Fans",
Expand Down Expand Up @@ -79,40 +79,30 @@ def getTemperature():

return tempC

def setmode():
try:
GPIO.setmode(GPIO.BOARD)
except:
pass

def turnFansOn(fanpin, invertrelay):
result = "Turning Fans ON"
setmode()
GPIO.setup(fanpin.id, GPIO.OUT)
pin = DigitalInOut(fanpin)
pin.switch_to_output()

if invertrelay:
if GPIO.input(fanpin.id) == 0:
result = "Leaving Fans ON"
GPIO.output(fanpin.id, GPIO.LOW)
pin.value = 0
else:
if GPIO.input(fanpin.id) == 1:
result = "Leaving Fans ON"
GPIO.output(fanpin.id, GPIO.HIGH)
s.log(1,"INFO: {}".format(result))
pin.value = 1

s.log(1,f"INFO: {result}")

def turnFansOff(fanpin, invertrelay):
result = "Turning Fans OFF"
setmode()
GPIO.setup(fanpin.id, GPIO.OUT)
pin = DigitalInOut(fanpin)
pin.switch_to_output()

if invertrelay:
if GPIO.input(fanpin.id) == 1:
result = "Leaving Fans OFF"
GPIO.output(fanpin.id, GPIO.HIGH)
pin.value = 1
else:
if GPIO.input(fanpin.id) == 0:
result = "Leaving Fans OFF"
GPIO.output(fanpin.id, GPIO.LOW)
s.log(1,"INFO: {}".format(result))
pin.value = 0

s.log(1,f"INFO: {result}")

def fans(params, event):
result = ''
Expand Down
11 changes: 11 additions & 0 deletions allsky_ina3221/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AllSky INA3221 Module

| | |
| ------------ | ------------ |
| **Status** | Experimental |
| **Level** | Experienced |
| **Runs In** | Periodic |

A simple module to read 1 to 3 channels from an INA3221 voltage and current sensor.

These modules can be useful for monitoring the current being fed to a dew heater to determine if its actually working or not
Loading

0 comments on commit c133431

Please sign in to comment.