=> 69810b8c7cfcb71fc5794c398de168639d9a2810
[1mdiff --git a/main.py b/main.py[m [1mindex a9afdd2..50d2cd2 100644[m [1m--- a/main.py[m [1m+++ b/main.py[m [36m@@ -1,20 +1,23 @@[m import json[m import time[m [m [31m-from machine import Pin[m [32m+[m[32mfrom machine import I2C[m from net import AdafruitIO[m from net import logging[m from net import ntp[m from net import Server[m from net import templates[m from net import util[m [32m+[m[32mfrom sensors import MCP9808[m [32m+[m[32mfrom sensors import WaterSensor[m [m [m class LedServer(Server):[m [m def __init__(self):[m super().__init__()[m [31m- self.led = Pin('LED', Pin.OUT)[m [32m+[m[32m self.waterSensor = WaterSensor(0)[m [32m+[m[32m self.mcp = MCP9808(I2C(0))[m self.aio = AdafruitIO()[m self.ntp_interval_in_seconds = 60 * 60[m self.aio_interval_in_seconds = 60 * 5[m [36m@@ -42,12 +45,6 @@[m [mclass LedServer(Server):[m def handlePath(self, path):[m if path == 'index.json':[m return self.getJsonData()[m [31m- elif path == 'light/on':[m [31m- self.led.on()[m [31m- return self.getJsonData()[m [31m- elif path == 'light/off':[m [31m- self.led.off()[m [31m- return self.getJsonData()[m [m return self.getPathData(path)[m [m [36m@@ -61,22 +58,32 @@[m [mclass LedServer(Server):[m [m return templates.render([m f'www/{path or self.default_path}',[m [31m- ledStatus=self.ledTextValue(),[m [31m- ledClass=self.ledCssClass(),[m [31m- datetime=util.datetime()[m [32m+[m[32m datetime=util.datetime(),[m [32m+[m[32m temperature=self.getTemperatureTextValue(),[m [32m+[m[32m waterStatus=self.waterTextValue(),[m [32m+[m[32m waterClass=self.waterCssClass()[m )[m [m def getReading(self):[m [31m- return {'timestamp': util.datetimeISO8601(), 'readings': self.getState()}[m [32m+[m[32m return {[m [32m+[m[32m 'timestamp': util.datetimeISO8601(),[m [32m+[m[32m 'readings': self.getState()[m [32m+[m[32m }[m [m def getState(self):[m [31m- return {'is-led-on': bool(self.led.value())}[m [32m+[m[32m return {[m [32m+[m[32m 'is-water-present': self.waterSensor.isWaterPresent(),[m [32m+[m[32m 'temperature': self.mcp.get_temp()[m [32m+[m[32m }[m [32m+[m [32m+[m[32m def getTemperatureTextValue(self):[m [32m+[m[32m return round(self.mcp.get_temp(), 2)[m [m [31m- def ledTextValue(self):[m [31m- return 'ON' if self.led.value() else 'OFF'[m [32m+[m[32m def waterTextValue(self):[m [32m+[m[32m return 'Present' if self.waterSensor.isWaterPresent() else 'Absent'[m [m [31m- def ledCssClass(self):[m [31m- return 'led-on' if self.led.value() else 'led-off'[m [32m+[m[32m def waterCssClass(self):[m [32m+[m[32m return 'water-present' if self.waterSensor.isWaterPresent() else 'water-absent'[m [m [m def main():[m [1mdiff --git a/net/logging.py b/net/logging.py[m [1mindex 1415ff0..675683d 100644[m [1m--- a/net/logging.py[m [1m+++ b/net/logging.py[m [36m@@ -67,8 +67,8 @@[m [mdef truncate(file, target_size):[m [m # try to find a line break nearby to split first chunk on[m break_position = max([m [31m- chunk.find(b'\n', -discard), # search forward[m [31m- chunk.rfind(b'\n', -discard) # search backwards[m [32m+[m[32m chunk.find(b'\n', -discard), # search forward[m [32m+[m[32m chunk.rfind(b'\n', 0, -discard) # search backwards[m )[m if break_position != -1: # if we found a line break..[m outfile.write(chunk[break_position + 1:])[m [1mdiff --git a/sensors/__init__.py b/sensors/__init__.py[m [1mindex e69de29..af4d296 100644[m [1m--- a/sensors/__init__.py[m [1m+++ b/sensors/__init__.py[m [36m@@ -0,0 +1,2 @@[m [32m+[m[32mfrom .mcp9808 import MCP9808[m [32m+[m[32mfrom .watersensor import WaterSensor[m [1mdiff --git a/sensors/watersensor.py b/sensors/watersensor.py[m [1mindex 2485bfa..32c25e5 100644[m [1m--- a/sensors/watersensor.py[m [1m+++ b/sensors/watersensor.py[m [36m@@ -13,6 +13,3 @@[m [mclass WaterSensor:[m [m def isWaterPresent(self):[m return self.reading > self.threshold[m [31m-[m [31m- def waterStatus(self):[m [31m- return 'Present' if self.isWaterPresent() else 'Absent'[m [1mdiff --git a/www/index.html b/www/index.html[m [1mindex a2a1c46..778179b 100644[m [1m--- a/www/index.html[m [1m+++ b/www/index.html[m [36m@@ -12,14 +12,6 @@[m color: #ddd;[m }[m [m [31m- .led-on {[m [31m- color: greenyellow;[m [31m- }[m [31m-[m [31m- .led-off {[m [31m- color: lightblue;[m [31m- }[m [31m-[m .water-present {[m color: pink;[m }[m [36m@@ -28,13 +20,18 @@[m color: lightblue;[m }[m [m [32m+[m[32m .temperature {[m [32m+[m[32m font-family: monospace;[m [32m+[m[32m }[m [32m+[m [m [m [m [mPico W
[m{{datetime}}
[m [31m-Led is {{ledStatus}}
[m [32m+[m[32m{{temperature}} °C
[m [32m+[m[32mWater is {{waterStatus}}
[m [m [m