Compare commits

...

4 Commits
v1.0.0 ... main

5 changed files with 26 additions and 5 deletions

15
main.py
View File

@ -11,6 +11,7 @@ from net import templates
from net import util
from net.config import config
from sensors import MCP9808
from sensors import SimulatedMCP9808
from sensors import WaterSensor
@ -18,8 +19,13 @@ class SensorServer(Server):
def __init__(self):
super().__init__()
try:
self.mcp = MCP9808(I2C(0))
except:
self.mcp = SimulatedMCP9808(temperature=37)
self.waterSensor = WaterSensor(0)
self.mcp = MCP9808(I2C(0))
self.aio = AdafruitIO()
self.ntfy = Ntfy()
self.ntp_interval_in_seconds = 60 * 60
@ -49,7 +55,7 @@ class SensorServer(Server):
if isWaterPresent != self.isWaterPresent:
self.isWaterPresent = isWaterPresent
self.ntfy.message(f'Water is {self.waterTextValue()}')
#self.ntfy.message(f'Water is {self.waterTextValue()}')
def handlePath(self, path):
if path == 'index.json':
@ -75,9 +81,12 @@ class SensorServer(Server):
)
def getReading(self):
readings = self.getState()
readings['is-water-present'] = 1 if readings['is-water-present'] else 0
return {
'timestamp': util.datetimeISO8601(),
'readings': self.getState()
'readings': readings
}
def getState(self):

View File

@ -9,5 +9,6 @@ secrets = {
'adafruit_io_username': '',
'adafruit_io_key': '',
'ntfy_host': '',
'ntfy_topic': ''
'ntfy_topic': '',
'ntfy_auth': ''
}

View File

@ -11,7 +11,8 @@ class Ntfy:
host = secrets['ntfy_host']
topic = secrets['ntfy_topic']
self.url = f'https://{host}/{topic}'
auth = secrets['ntfy_auth']
self.url = f'https://{host}/{topic}?auth={auth}'
def message(self, message):
result = self.sendMessage(message)

View File

@ -1,2 +1,3 @@
from .mcp9808 import MCP9808
from .mcp9808 import SimulatedMCP9808
from .watersensor import WaterSensor

View File

@ -251,3 +251,12 @@ class MCP9808(object):
part = 0 if i > 7 else 1
value = 1 if (cfg[part] & (2**(i % 8))) > 0 else 0
print(meanings[i][0] + ": " + meanings[i][1 + value])
class SimulatedMCP9808():
def __init__(self, temperature):
self.temperature = temperature
def get_temp(self):
return self.temperature