Skip to content

Commit 8865984

Browse files
author
OSi (Ondrej Sienczak)
committed
Fixed weater forecast unreachable state
1 parent 7c5979d commit 8865984

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+219
-121
lines changed

esp32/micropython.bin

1.13 KB
Binary file not shown.

micropython/net.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,22 @@ def ifconfig(self):
8989
def http_get_json(self, url):
9090
logger.info(f"HTTP GET: {url}")
9191

92-
for retry in range(CONN_RETRY_CNT):
92+
for _ in range(CONN_RETRY_CNT):
9393
try:
9494
return urequests.get(url).json()
9595
collect()
9696
return
9797
except OSError as e:
98-
logger.warning("ECONNRESET -> retry")
9998
if e.errno == ECONNRESET:
99+
logger.warning("ECONNRESET -> retry")
100100
continue
101+
logger.error(f"Connection error: {e}")
102+
...
103+
except Exception as e:
104+
logger.error(f"Connection error: {e}")
105+
...
101106

102-
raise e
107+
raise OSError("Page does not respond")
103108

104109
def _attach(self):
105110
# Activate WiFi interface

simulator/app.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def run():
3838
app.hotspot()
3939

4040
# And finally - meteostation display - basic functionality ;-)
41-
else:
41+
# Checks if we will display RAW image from remote display server
42+
# or makes own meteostation screen based on openweathermap data.
43+
elif not app.remote_display():
4244
# Once we are connected to network, we can download forecast.
4345
# Just note that once forecast is download, WiFi is disconnected
4446
# to save as much battery capacity as possible.
@@ -193,12 +195,28 @@ def web_server(self):
193195

194196
reset()
195197

198+
def remote_display(self):
199+
if not behavior.get("remote_display", True):
200+
return False
201+
202+
self.net.connect()
203+
addr = self.net.config.get("remote_display", None)
204+
205+
if addr is None:
206+
return False
207+
208+
logger.info(f"Connecting to display server: {addr}")
209+
return False
210+
196211
def forecast(self):
197212
if self.net is None:
198213
return None
199214
else:
200215
self.net.connect()
201-
return Forecast(self.net, self.temp)
216+
try:
217+
return Forecast(self.net, self.temp)
218+
except OSError:
219+
return None
202220

203221
def repaint(self, forecast):
204222
from ui.main import MeteoUi

simulator/bitmap/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
elif v == "epd47":
1414
from .gs.fonts import FONTS
1515
from .gs.bmp import BMP
16-
from .bwy.wind import WIND
16+
17+
WIND = None
18+
# from .bwy.wind import WIND
1719
else:
1820
raise TypeError(f"Don't know display type for variant {v}")

simulator/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
behavior = Json(
8888
"cfg/behavior.json",
89-
{"refresh": 15, "dbl": (0, 7), "show_radar": 5},
89+
{"refresh": 15, "dbl": (0, 7), "show_radar": 5, "remote_display": True},
9090
)
9191

9292
hw = Json(

simulator/forecast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from machine import Pin, deepsleep, RTC
77
from micropython import const
88
from collections import namedtuple
9-
from config import api, sys, location, hw
9+
from config import api, location, hw
1010
from ltime import Time
1111
from buzzer import play
1212

simulator/lang/lang_cz.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@
5353
"Submit": "Potvrdit",
5454
"Summer time": "Letní čas",
5555
"Two days": "Dvoudenní",
56+
"Unable to download": "Nepodařilo se stáhnout",
5657
"Units": "Jednotky",
5758
"Use with BSSID": "použít včetně BSSID",
5859
"Use": "Použít",
5960
"Variant": "Varianta",
6061
"WiFi setup": "Nastavení WiFi",
62+
"weather data!": "stav počasí!",
6163
"{} min (doubled from {}:00 to {}:00)": "{} min (mezi {}:00 a {}:00 dvakrát delší)",
6264
}
6365

simulator/net.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,22 @@ def ifconfig(self):
5454
def http_get_json(self, url):
5555
logger.debug("HTTP GET: " + url)
5656

57-
for retry in range(CONN_RETRY_CNT):
57+
for _ in range(CONN_RETRY_CNT):
5858
try:
5959
return urequests.get(url).json()
6060
collect()
6161
return
62-
except OSError as font:
63-
logger.info("ECONNRESET -> retry")
64-
if font.errno == ECONNRESET:
62+
except OSError as e:
63+
if e.errno == ECONNRESET:
64+
logger.warning("ECONNRESET -> retry")
6565
continue
66+
logger.error(f"Connection error: {e}")
67+
...
68+
except Exception as e:
69+
logger.error(f"Connection error: {e}")
70+
...
6671

67-
raise font
72+
raise OSError("Page does not respond")
6873

6974
def disconnect(self):
7075
...

simulator/ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
logger = getLogger(__name__)
44

55
from micropython import const
6-
from .base import Vect, ZERO, ONE, TWO, Bitmap, UiFrame, Ui
6+
from .base import Vect, ZERO, ONE, TWO, Bitmap, UiFrame, Ui, with_forecast

simulator/ui/acep/calendar.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
logger = getLogger(__name__)
44

5-
from ui import UiFrame, Vect, ZERO
5+
from ui import UiFrame, Vect, ZERO, with_forecast
66
from display.epd import BLACK, GREEN
77
from micropython import const
88
from lang import day_of_week
99
from config import api
1010

1111

1212
class UiCalendar(UiFrame):
13-
def draw(self, show_days):
14-
forecast = self.ui.forecast.forecast
13+
@with_forecast
14+
def draw(self, forecast, show_days):
1515
block = self.ui.block
1616
h_space = const(4)
1717

@@ -27,18 +27,18 @@ def draw(self, show_days):
2727
self.canvas.hline(ZERO, self.dim.x - 1)
2828

2929
# Find time related to next day
30-
week_day = self.ui.forecast.time.get_date_time(forecast[0].dt)[6]
30+
week_day = forecast.time.get_date_time(forecast.forecast[0].dt)[6]
3131

32-
for i in range(len(forecast)):
33-
dt = self.ui.forecast.time.get_date_time(forecast[i].dt)
32+
for i in range(len(forecast.forecast)):
33+
dt = forecast.time.get_date_time(forecast.forecast[i].dt)
3434
if not week_day == dt[6]:
3535
dh = dt[3]
3636
break
3737

3838
# Draw all items related to forecast
3939
first = True
4040
for x, f in self.ui.forecast_singles():
41-
dt = self.ui.forecast.time.get_date_time(f.dt)
41+
dt = forecast.time.get_date_time(f.dt)
4242
hour = dt[3] - dh
4343

4444
# Draw weekends

0 commit comments

Comments
 (0)