adafruit / adafruit/Adafruit_CircuitPython_PortalBase
PyPortal.get_local_time() calls incorrect IP/domain
- Dominant language
- Python
- Stars
- 17
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I'm using PyPortal 7.X to create a weather station display for Netatmo. I have an on-prem ASP.NET 6 proxy against the Netatmo API, so PyPortal qeries my proxy, which queries Netatmo and prepares the response in a json structure that's easy to display as widgets on the PyPortal.
I have the following program loop:
```
while True:
# only query the online time once per hour (and on first run)
if (not localtile_refresh) or (time.monotonic() - localtile_refresh) > 3600:
try:
print("Getting time from internet!")
pyportal.get_local_time()
localtile_refresh = time.monotonic()
except RuntimeError as e:
print("Some error occured, retrying! -", e)
continue
# only query the weather every 10 minutes (and on first run)
if (not weather_refresh) or (time.monotonic() - weather_refresh) > 600:
try:
value = pyportal.fetch()
gfx.draw_display(value)
weather_refresh = time.monotonic()
except RuntimeError as re:
print("Some error occured, retrying! -", re)
gfx.draw_error()
continue
except TimeoutError as te:
print("Timeout - ", te)
gfx.draw_error()
continue
gfx.draw_time()
updateTime = .5
if mode == "weekday":
updateTime = 30
time.sleep(updateTime) # wait X seconds before updating anything again
```
I experience unexpected behavior when `pyportal.get_local_time()` executes the second time (and all times after). First time the Adafruit API at http://io.adafruit.com is called as expected. But the second time, even though the URL looks correct, my local ASP.NET proxy is called instead. That's the same IP as `pyportal.fetch()` calls.
This is a flowchart describing what happens:

I added Azure Application Insights to my ASP.NET proxy to figure out what's going on, and was surprised to see requests for the domain `io.adafruit.com` hitting my on-prem proxy. I've documented proof of the traffic in my own project in this issue:
https://github.com/blog-eivindgl-com/netatmo-pyportal-display/issues/9
I don't know why this happens, but I suspect there's some kind of local DNS issue on the PyPortal that incorrectly maps `io.adafruit.com` to the same IP address as the URL of the `fetch()` call.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the loop from the issue, comparing the first and subsequent calls to pyportal.get_local_time() with pyportal.fetch(). Trace the requested host and resolved destination for each call; done means repeated time requests reach io.adafruit.com rather than the proxy used by fetch().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100