Files
weather-info/pico-client/main.py
2025-11-21 19:07:41 +00:00

82 lines
2.3 KiB
Python

import random
from display import NeoPixel_64x64
from display.fonts import font_5x7
from tryout import Font_Checker, Weather_Checker, Emoji_Checker, API_Server_Checker
from utils import show_system_load
from utils import (
sync_ntp_time,
get_datetime_string,
get_german_datetime,
) # Time-related functions
from utils import SimpleCounter
from utils.digital_clock import DigitalClock
import uasyncio as asyncio # type: ignore
from web import Wlan
async def weather_check_task(weather_checker: Weather_Checker):
CITY_LIST: list[str] = sorted(
["Großhansdorf", "Columbus", "London", "Ebeltoft", "Tokio"]
)
while True:
for city in CITY_LIST:
weather_checker.check(city=city, lang="de", test_mode=False)
print(f"Checked {city}")
await asyncio.sleep(3 * 60)
async def api_server_check_task(api_server_checker: API_Server_Checker):
while True:
rnd_item_id: int = random.randrange(5)
api_server_checker.check(rnd_item_id)
await asyncio.sleep(10)
async def print_time_task() -> None:
bottom_ypos = display.MATRIX_HEIGHT - display.font_height
digitalClock: DigitalClock = DigitalClock(display, 0, bottom_ypos)
while True:
await digitalClock.tick()
await asyncio.sleep(2)
async def sync_ntp_time_task() -> None:
while True:
sync_ntp_time()
await asyncio.sleep(60)
async def main(
weather_checker: Weather_Checker, api_server_checker: API_Server_Checker
) -> None:
# Run both tasks concurrently
await asyncio.gather(
# sync_ntp_time_task(),
# weather_check_task(weather_checker),
api_server_check_task(api_server_checker),
# print_time_task(),
)
# Programm Startpunkt
if __name__ == "__main__":
display = NeoPixel_64x64()
wlan: Wlan = Wlan()
wlan.connect(ssid="Wokwi-Wlan", password="12345678")
# font_checker : Font_Checker = Font_Checker( display)
# font_checker.fonts_check(pretty=False)
# emoji_checker : Emoji_Checker = Emoji_Checker(display)
# emoji_checker.check()
display.set_font(font_5x7)
weather_checker: Weather_Checker = Weather_Checker(display=display)
api_server_checker: API_Server_Checker = API_Server_Checker()
# show_system_load()
asyncio.run(main(weather_checker, api_server_checker))