Skip to content

PyPortal.get_local_time() calls incorrect IP/domain #86

@eloekset

Description

@eloekset

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:
image

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:
blog-eivindgl-com/netatmo-pyportal-display#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions