Maybe It's Just Me
As I work on different projects I find myself implementing similar things across projects. This has led to a lot of copy/paste work. Which in turn leads to having to update multiple projects when I find an issue or improvement.
So I decided to start a helpers project. It is essentially a set of wrapper classes that I can use across projects.
What's In The Big Pink Box?
I've just started to build this project and have started with the ones that were in use with my current projects. I plan to add more as I move to other projects.
- time_lord.py
- Provides a time singleton that supports RTC if desired
- Currently does not support using SPI and Network to get the time (maybe in a later release)
- local_logger.py
- Provides a logging singleton that supports adding/removing different handlers and accessing files on your SD card
- rotating log files is currently incomplete
- local_mqtt.py
- Provides an MQTT singleton that uses SSL by default
- Supports publishing independently or via the MQTTHandler in adafruit_logging
Any Gotchas?
I have done my best to keep all the helpers independent. I didn't want to force anyone to use local_logger just to use the time_lord wrapper.
The responsibility use the helpers together falls to the program.
How Does it Work?
I clone this project into the project in which I want to use the wrappers. From there I just copy the wrappers I'm using to my microcontroller.
Example code - implementing time_lord.py without using a real-time clock:
...
import socketpool
import wifi
import time_lord
...
pool = socketpool.SocketPool(wifi.radio)
my_time = time_lord.configure_time(pool)
...
Example code - implementing local_logger with time_lord and a real-time clock:
...
import rtc
import socketpool
import wifi
import time_lord
import local_logger
...
pool = socketpool.SocketPool(wifi.radio)
rtc = RTC() # using a QTPY ESP32 Pico
my_time = time_lord.configure_time(pool, rtc)
my_log = local_logger.getLocalLogger(use_time=True)
...
Example code - implementing local_mqtt with local_logger without time_lord:
...
import local_mqtt
import local_logger
...
my_log = local_logger.getLocalLogger()
my_mqtt = local_mqtt.getMQTT(use_logger=True)
Where To Get the Project
You can find the project on Github
Please feel free to contribute!