Skip to content

Commit

Permalink
current dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Baumeister committed Nov 1, 2021
1 parent 22792ed commit b7a7436
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ but to everyone who shares with the community ♥🙏.
- Power usage and deep sleep:
https://www.youtube.com/watch?v=6SdyImetbp8&t=7s
- HT7333 Specs: https://www.angeladvance.com/HT73xx.pdf
- finding the right pins for deep sleep on WEMOS D1 Mini:
- finding the right pins for deep sleep on WEMOS D1 Mini (it's RST
with D0):
https://www.mischianti.org/2019/11/21/wemos-d1-mini-esp8266-the-three-type-of-sleep-mode-to-manage-energy-savings-part-4/
- EEPROM lifetime: https://youtu.be/r-hEOL007nw?t=50
- ~~https://github.com/rdehuyss/micropython-ota-updater~~ as of writing
this, there is a problem with MicroPyhton on ESP8266 with SSL
certificates, so this OTA library cannot be used
- logging: https://github.com/pfalcon/pycopy-lib/tree/master/logging
- MQTT: https://github.com/pfalcon/pycopy-lib/tree/master/umqtt.simple
- TODO Energy Saving: https://arduinodiy.wordpress.com/2020/01/18/very-deepsleep-and-energy-saving-on-esp8266/
- TODO Energy Saving:
https://arduinodiy.wordpress.com/2020/01/18/very-deepsleep-and-energy-saving-on-esp8266/

Basic stuff

Expand Down
3 changes: 2 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

MQTT_TOPIC_BASE = b"wohnung/sensor_tmp_wp_1"

MEASUREMENT_INTERVAL = 5 * 60
MEASUREMENT_INTERVAL = 5
# seconds between measurements (device will deep-sleep during this time)

WATCHDOG_ENABLED = False

def all():
attributes_as_dict = dict()
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/watchdog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import machine

class Watchdog:
def __init__(self, active=True):
self._active=active
if (self._active):
self._watchdog = machine.WDT()

def feed(self):
if (self._active):
self._watchdog.feed()
11 changes: 11 additions & 0 deletions src/led/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import machine
import time

led = machine.Pin(2, machine.Pin.OUT)

def blink(times = 3, duration = 0.25):
for _ in range(times):
led.off()
time.sleep(duration)
led.on()
time.sleep(duration)
13 changes: 10 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import time
import sys

import led
import logging
from umqtt.simple import MQTTClient
from helpers.watchdog import Watchdog

import secrets
import config
Expand Down Expand Up @@ -94,7 +96,13 @@ def start():
log.info("Sensors initialized")
watchdog.feed()

while True:
# led.blink()
log.debug("DOING MY JOB NOW")
log.debug("going to deep sleep")
# rtc.alarm(rtc.ALARM0, 15 * 1000)
# machine.deepsleep()

while False:
try:
results = read_dssensor(ds_sensor)
log.debug("Temperature(s): %s" % results)
Expand All @@ -114,8 +122,7 @@ def start():
except OSError as e:
restart("ERROR: Problem in sensor reading loop")


watchdog = machine.WDT() # enable it with a timeout of 2s
watchdog = Watchdog(config.WATCHDOG_ENABLED)

logging.basicConfig(
level=logging.DEBUG,
Expand Down

0 comments on commit b7a7436

Please sign in to comment.