diff --git a/app.py b/app.py deleted file mode 100644 index 4b4eb4a..0000000 --- a/app.py +++ /dev/null @@ -1,3 +0,0 @@ -from app.utils.colors import RAINBOW - -print(f'app says {RAINBOW}') diff --git a/app/classes/location.py b/app/classes/location.py index 48b2ea0..f22bcfd 100644 --- a/app/classes/location.py +++ b/app/classes/location.py @@ -6,4 +6,4 @@ class Location: self.localtime = kwargs.get('localtime', '') def __repr__(self): - return f"Location(name='{self.name}', region='{self.region}', country='{self.country}')" + return f"Location(name='{self.name}', region='{self.region}', country='{self.country}', localtime='{self.localtime}')" diff --git a/app/utils/system_load.py b/app/utils/system_load.py index b46a606..c3cac86 100644 --- a/app/utils/system_load.py +++ b/app/utils/system_load.py @@ -31,7 +31,12 @@ def show_system_load(): print('==================') -# Run periodically -while True: - show_system_load() - time.sleep(5) +def go(): + # Run periodically + while True: + show_system_load() + time.sleep(5) + + +if __name__ == '__main__': + go() diff --git a/app/web/wlan.py b/app/web/wlan.py index ef07bcd..a5c4beb 100644 --- a/app/web/wlan.py +++ b/app/web/wlan.py @@ -3,74 +3,91 @@ import network import urequests from ..classes.location import Location from ..classes.weather import CurrentCondition, Weather +import json API_KEY = '3545ce42d0ba436e8dc164532250410' ACTUAL_WEATHER = 'https://api.weatherapi.com/v1/current.json?key={{key}}&q={{city}}&aqi=yes' -WEATHER_QUERY_MOCK = { - 'location': { - 'name': 'Grosshansdorf', - 'region': 'Schleswig-Holstein', - 'country': 'Germany', - 'lat': 53.6667, - 'lon': 10.2833, - 'tz_id': 'Europe/Berlin', - 'localtime_epoch': 1760779328, - 'localtime': '2025-10-18 11:22', - }, - 'current': { - 'last_updated_epoch': 1760778900, - 'last_updated': '2025-10-18 11:15', - 'temp_c': 8.3, - 'temp_f': 46.9, - 'is_day': 1, - 'condition': { - 'text': 'Sonnig', - 'icon': '//cdn.weatherapi.com/weather/64x64/day/113.png', - 'code': 1000, - }, - 'wind_mph': 2.5, - 'wind_kph': 4.0, - 'wind_degree': 31, - 'wind_dir': 'NNE', - 'pressure_mb': 1029.0, - 'pressure_in': 30.39, - 'precip_mm': 0.0, - 'precip_in': 0.0, - 'humidity': 76, - 'cloud': 0, - 'feelslike_c': 8.2, - 'feelslike_f': 46.8, - 'windchill_c': 10.0, - 'windchill_f': 50.0, - 'heatindex_c': 9.9, - 'heatindex_f': 49.8, - 'dewpoint_c': 2.2, - 'dewpoint_f': 35.9, - 'vis_km': 10.0, - 'vis_miles': 6.0, - 'uv': 0.9, - 'gust_mph': 2.8, - 'gust_kph': 4.6, - 'air_quality': { - 'co': 163.678, - 'no2': 7.278, - 'o3': 47.0, - 'so2': 1.178, - 'pm2_5': 5.778, - 'pm10': 7.178, - 'us-epa-index': 1, - 'gb-defra-index': 1, - }, - }, -} - class Wlan: def __init__(self, ssid, password): self.ssid = ssid self.password = password + def mock_weather_data(self): + data = """ + { + "location": { + "name": "Grosshansdorf", + "region": "Schleswig-Holstein", + "country": "Germany", + "lat": 53.6667, + "lon": 10.2833, + "tz_id": "Europe/Berlin", + "localtime_epoch": 1760779328, + "localtime": "2025-10-18 11:22" + }, + "current": { + "last_updated_epoch": 1760778900, + "last_updated": "2025-10-18 11:15", + "temp_c": 8.3, + "temp_f": 46.9, + "is_day": 1, + "condition": { + "text": "Sonnig", + "icon": "//cdn.weatherapi.com/weather/64x64/day/113.png", + "code": 1000 + }, + "wind_mph": 2.5, + "wind_kph": 4.0, + "wind_degree": 31, + "wind_dir": "NNE", + "pressure_mb": 1029.0, + "pressure_in": 30.39, + "precip_mm": 0.0, + "precip_in": 0.0, + "humidity": 76, + "cloud": 0, + "feelslike_c": 8.2, + "feelslike_f": 46.8, + "windchill_c": 10.0, + "windchill_f": 50.0, + "heatindex_c": 9.9, + "heatindex_f": 49.8, + "dewpoint_c": 2.2, + "dewpoint_f": 35.9, + "vis_km": 10.0, + "vis_miles": 6.0, + "uv": 0.9, + "gust_mph": 2.8, + "gust_kph": 4.6, + "air_quality": { + "co": 163.678, + "no2": 7.278, + "o3": 47.0, + "so2": 1.178, + "pm2_5": 5.778, + "pm10": 7.178, + "us-epa-index": 1, + "gb-defra-index": 1 + } + } + }""" + + filepath = 'restapi/mock-weather.json' + try: + with open(filepath, 'r', encoding='utf-8') as file: + return json.load(file) + except OSError: # Use OSError instead of FileNotFoundError + print(f"Error: File '{filepath}' not found.") + return None + except FileNotFoundError: + print(f"Error: File '{filepath}' not found.") + return None + except json.JSONDecodeError as e: + print(f"Error: Invalid JSON in '{filepath}': {e}") + return None + def connect(self): wlan = network.WLAN(network.STA_IF) wlan.active(True) @@ -89,16 +106,18 @@ class Wlan: print(f'query: {weather_url}') if not test_mode: + self.connect() + r = urequests.get(weather_url) print('Status-Code:', r.status_code) json_resp = r.json() - print(json_resp.keys()) r.close() else: print('Status-Code: test_mode') - json_resp = WEATHER_QUERY_MOCK + # json_resp = WEATHER_QUERY_MOCK + json_resp = self.mock_weather_data() loc = Location(**json_resp['location']) cc = CurrentCondition(**json_resp['current']) diff --git a/deploy.fish b/deploy.fish index c511f1a..e31f233 100755 --- a/deploy.fish +++ b/deploy.fish @@ -10,6 +10,7 @@ end echo "1. Copying app directory to device..." mpremote connect port:rfc2217://localhost:4000 cp -r app : +mpremote connect port:rfc2217://localhost:4000 cp -r restapi : echo "2. Starting main.py..." mpremote connect port:rfc2217://localhost:4000 run main.py diff --git a/diagram.json b/diagram.json index 97b3950..18ebf5f 100644 --- a/diagram.json +++ b/diagram.json @@ -7,8 +7,7 @@ "type": "board-pi-pico-w", "id": "picow", "top": 1014.35, - "left": 3.55, - "attrs": { "env": "micropython-20241129-v1.24.1" } + "left": 3.55 }, { "type": "wokwi-led-matrix", diff --git a/firmware/RPI_PICO-20250911-v1.26.1.uf2 b/firmware/Pico/RPI_PICO-20250911-v1.26.1.uf2 similarity index 100% rename from firmware/RPI_PICO-20250911-v1.26.1.uf2 rename to firmware/Pico/RPI_PICO-20250911-v1.26.1.uf2 diff --git a/firmware/Pico/RPI_PICO_W-20250911-v1.26.1.uf2 b/firmware/Pico/RPI_PICO_W-20250911-v1.26.1.uf2 new file mode 100644 index 0000000..f606ea8 Binary files /dev/null and b/firmware/Pico/RPI_PICO_W-20250911-v1.26.1.uf2 differ diff --git a/firmware/Pico2/RPI_PICO2_W-20250911-v1.26.1.uf2 b/firmware/Pico2/RPI_PICO2_W-20250911-v1.26.1.uf2 new file mode 100644 index 0000000..6828a09 Binary files /dev/null and b/firmware/Pico2/RPI_PICO2_W-20250911-v1.26.1.uf2 differ diff --git a/main.py b/main.py index 8783ec5..7495336 100644 --- a/main.py +++ b/main.py @@ -14,47 +14,45 @@ from app.display.fonts.font_16x16 import font_16x16 print('Hello, Pi Pico!') -display = NeoPixel_64x64() -display.clear() -# display.set_font(font_8x8) -# display.show_hello() -# display.rotate_text_left_continuous('FLOATING TEXT', 0, speed=8.0, duration=30) +def emoji_test(): + display = NeoPixel_64x64() + display.clear() + # display.set_font(font_8x8) + # display.show_hello() + # display.rotate_text_left_continuous('FLOATING TEXT', 0, speed=8.0, duration=30) -display.set_font(font_16x16) -display.draw_text('ABCD', 1, 1, color=GOLD) + display.set_font(font_16x16) + display.draw_text('ABCD', 1, 1, color=GOLD) + + # try emoji + display.set_font(emoji_8x8) + display.draw_text('😀', 1, 20, color=GREEN) + display.draw_text('⭐', 1, 29) + display.draw_text('✅', 1, 38) + display.draw_text('😎', 1, 47, color=RED) + display.draw_text('💙', 10, 47) + display.draw_text('💚', 19, 47) + display.draw_text('💛', 28, 47) + + # try emoji + # display.set_font(emoji_16x16) + # display.draw_text('😀', 10, 20, color=ORANGE) + + display.write() + + show_system_load() -# try emoji -display.set_font(emoji_8x8) -display.draw_text('😀', 1, 20, color=GREEN) -display.draw_text('⭐', 1, 29) -display.draw_text('✅', 1, 38) -display.draw_text('😎', 1, 47, color=RED) -display.draw_text('💙', 10, 47) -display.draw_text('💚', 19, 47) -display.draw_text('💛', 28, 47) - -# try emoji -# display.set_font(emoji_16x16) -# display.draw_text('😀', 10, 20, color=ORANGE) - - -display.write() - -show_system_load() - - -def main(): +def weather_check(): wlan = Wlan('WOKWI-Guest', '12345678') try: + display = NeoPixel_64x64() display.clear() display.draw_text('search wlan', 0, 0, color=YELLOW) display.write() - wlan.connect() - - display.clear_row(0, effect=True) + display.clear_row(0, effect=False) # display.clear() display.draw_text('wlan connected', 0, 0, color=RAINBOW[1]) @@ -62,14 +60,14 @@ def main(): display.draw_text('weather data', 0, 16, color=RAINBOW[1]) display.write() - w_resp = wlan.actual_weather(test_mode=False) + w_resp = wlan.actual_weather(test_mode=True) display.clear() display.draw_text(f'{str(w_resp.location.name)}', 0, 0, color=RAINBOW[0]) display.draw_text(f'{str(w_resp.current.temp_c)}°C', 0, 8, color=RAINBOW[1]) - display.draw_text(f'{str(w_resp.current.last_updated)[-5:]}', 0, 16, color=RAINBOW[2]) - display.draw_text(f'{str(w_resp.location.localtime)[-5:]}', 0, 24, color=RAINBOW[3]) + display.draw_text(f'upd: {str(w_resp.current.last_updated)[-5:]}', 0, 16, color=RAINBOW[2]) + display.draw_text(f'cur: {str(w_resp.location.localtime)[-5:]}', 0, 24, color=RAINBOW[3]) display.write() @@ -80,3 +78,8 @@ def main(): print(f'Error: connection closed - {e}') finally: print('finally done.') + + +if __name__ == '__main__': + # emoji_test() + weather_check() diff --git a/restapi/mock-weather.json b/restapi/mock-weather.json new file mode 100644 index 0000000..6eeb63b --- /dev/null +++ b/restapi/mock-weather.json @@ -0,0 +1,57 @@ +{ + "location": { + "name": "Grosshansdorf", + "region": "Schleswig-Holstein", + "country": "Germany", + "lat": 53.6667, + "lon": 10.2833, + "tz_id": "Europe/Berlin", + "localtime_epoch": 1760977041, + "localtime": "2025-10-20 18:17" + }, + "current": { + "last_updated_epoch": 1760976900, + "last_updated": "2025-10-20 18:15", + "temp_c": 12.3, + "temp_f": 54.1, + "is_day": 0, + "condition": { + "text": "leichter Regenfall", + "icon": "//cdn.weatherapi.com/weather/64x64/night/296.png", + "code": 1183 + }, + "wind_mph": 12.1, + "wind_kph": 19.4, + "wind_degree": 151, + "wind_dir": "SSE", + "pressure_mb": 999.0, + "pressure_in": 29.5, + "precip_mm": 0.0, + "precip_in": 0.0, + "humidity": 77, + "cloud": 100, + "feelslike_c": 10.3, + "feelslike_f": 50.6, + "windchill_c": 10.1, + "windchill_f": 50.1, + "heatindex_c": 12.1, + "heatindex_f": 53.8, + "dewpoint_c": 7.7, + "dewpoint_f": 45.8, + "vis_km": 10.0, + "vis_miles": 6.0, + "uv": 0.0, + "gust_mph": 19.8, + "gust_kph": 31.9, + "air_quality": { + "co": 171.678, + "no2": 9.778, + "o3": 54.0, + "so2": 1.678, + "pm2_5": 10.078, + "pm10": 12.578, + "us-epa-index": 1, + "gb-defra-index": 1 + } + } +} diff --git a/wokwi.toml b/wokwi.toml index 3053dd3..2f3b6b3 100644 --- a/wokwi.toml +++ b/wokwi.toml @@ -1,5 +1,6 @@ [wokwi] version = 1 -elf = "firmware/RPI_PICO-20250911-v1.26.1.uf2" -firmware = "firmware/RPI_PICO-20250911-v1.26.1.uf2" +elf = "firmware/Pico/RPI_PICO_W-20250911-v1.26.1.uf2" +firmware = "firmware/Pico/RPI_PICO_W-20250911-v1.26.1.uf2" rfc2217ServerPort = 4000 +gdbServerPort = 3333 \ No newline at end of file