main¶
Update the dashboard, then deep-sleep until the next update.
On battery the mode depends on the charge level and the time of day (see config.BATTERY_MODES and config.NIGHT): fetches (WLAN, new data, whole screen) come every 10 to 60 minutes, and the header shows the time of the last data and of the next fetch. A mode may also run a minute clock, which updates the header every minute with a partial refresh and without WLAN. A low battery shows a charging notice in the bottom-left tile.
On external power (USB) the board stays awake instead: fetches every config.FETCH_INTERVAL_S, and the web interface on http://<hostname>.local/ (tile settings, /battery, /log) is always up. On battery it serves the web interface only after a reset (not a timer wake), for config.AWAKE_AFTER_RESET_S seconds, or while the maintenance switch in Home Assistant is on.
This is the entry point: importing it runs one wake and ends in deep sleep.
Functions¶
|
Keep the watchdog from resetting the board. |
GET /battery: the fuel gauge readings (see battery.as_dict). |
|
|
Whether to show the charging symbol: on USB power, or charging. |
Whether USB power is present, or None without a divider. |
|
|
GET /log: the last lines of the boot log. |
|
Whether the board runs on USB power (see battery.on_external_power). |
How often to fetch and whether the clock runs, on battery. |
|
|
Build the header for now. |
Join one of the configured WLANs unless already connected. |
|
Set the RTC to UTC via NTP. |
|
The data source for the configured tiles (see |
|
Return (device ID, hamqtt.Device) for this board. |
|
|
Create an MQTT client for the configured broker. |
|
Publish battery and charge state to Home Assistant via MQTT. |
|
Fetch new data, report to MQTT, redraw the screen and save the state. |
|
Tiles for the layout, with trend arrows from the kept history. |
Note that a full refresh has happened since this boot. |
|
Lines of the charging notice, or None while the battery is fine. |
|
Return (framebuffer, buffer) for the header band. |
|
|
Redraw only the header, with a partial refresh, if it changed. |
Milliseconds since the start of the current minute. |
|
|
One dashboard update: full with new data when due, else the header. |
Awake mode until the board runs on battery again. |
|
|
Wrap |
Restart the board after the current request (see poll_and_feed). |
|
Web server with the tile settings, status and update endpoints. |
|
Show which files the update changed, if status screens are on. |
|
|
Answer web requests for |
Stay awake while the maintenance switch is on. |
|
|
Full update now, whether due or not. |
|
Store and use a new tile configuration. |
|
Store and use new warning sources. |
|
Schedule a redraw after the web interface saved the tiles. |
|
Status endpoints plus the web interface for the tiles. |
Add this wake's awake time to the statistics in the RTC state. |
|
|
Return how long to deep-sleep. |
Module Contents¶
- main.feed()¶
Keep the watchdog from resetting the board.
- main.battery_status()¶
GET /battery: the fuel gauge readings (see battery.as_dict).
With a USB divider also the measured USB voltage, for checking it.
- main.charging()¶
Whether to show the charging symbol: on USB power, or charging.
- main.usb_power()¶
Whether USB power is present, or None without a divider.
- main.boot_log()¶
GET /log: the last lines of the boot log.
- main.on_external_power(awake=False)¶
Whether the board runs on USB power (see battery.on_external_power).
- main.battery_mode()¶
How often to fetch and whether the clock runs, on battery.
- main.current_header(online, online_at=None, fetched_at=None)¶
Build the header for now.
Its time shows the last data that arrived and the next planned fetch, such as “Stand 14:20 · neu 14:30” (see
header).
- main.connect_wlan()¶
Join one of the configured WLANs unless already connected.
- main.sync_clock()¶
Set the RTC to UTC via NTP.
The RTC keeps running in deep sleep, so a failed sync still leaves the last known time.
- main.make_source()¶
The data source for the configured tiles (see
datasource).
- main.mqtt_device()¶
Return (device ID, hamqtt.Device) for this board.
- main.mqtt_client(device_id, role='status')¶
Create an MQTT client for the configured broker.
Each
roleneeds its own client ID, or the broker drops an open connection when another one with the same ID arrives.
- main.report_status(stats=None)¶
Publish battery and charge state to Home Assistant via MQTT.
Called only when the WLAN is up anyway for fetching.
statsare the awake statistics (see awake_stats.summary), if any.- Returns:
Whether the maintenance switch is on.
- main.fetch_and_redraw(saved)¶
Fetch new data, report to MQTT, redraw the screen and save the state.
savedis the state from the previous wake, or None.
- main.layout_tiles(readings, online, now)¶
Tiles for the layout, with trend arrows from the kept history.
Fresh readings are added to the history; cached ones (offline) are not.
- main.mark_full_refresh()¶
Note that a full refresh has happened since this boot.
- main.low_battery_notice()¶
Lines of the charging notice, or None while the battery is fine.
- main.make_band()¶
Return (framebuffer, buffer) for the header band.
- main.update_header(saved)¶
Redraw only the header, with a partial refresh, if it changed.
- main.ms_into_minute()¶
Milliseconds since the start of the current minute.
- main.update(woke)¶
One dashboard update: full with new data when due, else the header.
- main.stay_awake()¶
Awake mode until the board runs on battery again.
- main.poll_and_feed(server)¶
Wrap
server.pollfor the watchdog and for restarts.The returned function feeds the watchdog and restarts the board once an update has asked for it, after the answer was sent.
- main.request_reset()¶
Restart the board after the current request (see poll_and_feed).
- main.make_server()¶
Web server with the tile settings, status and update endpoints.
- main.show_update()¶
Show which files the update changed, if status screens are on.
- main.serve_for(seconds)¶
Answer web requests for
seconds, feeding the watchdog.
- main.maintenance()¶
Stay awake while the maintenance switch is on.
For at most config.MAINTENANCE_S the web interface and updates over the WLAN are available, with the WLAN symbol shown. Then the board goes back to sleep.
- main.redraw()¶
Full update now, whether due or not.
- main.save_tiles(new)¶
Store and use a new tile configuration.
- main.save_alerts(new)¶
Store and use new warning sources.
- main.tiles_saved(saved)¶
Schedule a redraw after the web interface saved the tiles.
- main.routes()¶
Status endpoints plus the web interface for the tiles.
- main.count_wake()¶
Add this wake’s awake time to the statistics in the RTC state.
- main.sleep_ms()¶
Return how long to deep-sleep.
With the minute clock on, that is until the next minute; otherwise until the next fetch or the end of the night, whichever comes first.