#ESP32-32 internet clock

1 messages · Page 1 of 1 (latest)

sick thorn
#

I'm trying to build a simple internet clock with an esp32s2 and a 7-segment display. I am pulling the current time from an API (openweathermap), and using adafruit_datetime to make a string from the unix timestamp in the parsed json, which I then format down to a hh:mm format. It seems to work ONLY when I am running it from a shell on my computer, and not when it runs as code.py, bare. In the latter, the display seems to show a default time of 12:00, and not whatever time is pulled from the request. Any ideas?

    print("starting loop")
    print("Fetching json from", TIME_DATA_SOURCE)
    json_data = requests.get(TIME_DATA_SOURCE)
    formatted_data = json_data.json()
    current_time_unix = (formatted_data.get("dt"))
    current_time = datetime.fromtimestamp(current_time_unix)   
    timestring = str(current_time)
    parsed_time = parse_time(timestring)
    simple_time = hh_mm(parsed_time)
    print(simple_time)
    display.fill(0)
    display.print(simple_time)
    time.sleep(10)’’’
fiery grove
#

what does print(simple_time) show?

sick thorn
#

If I run it from Thonny, the terminal shell shows "10:55", which is correct. That also shows up on the display. But when I save as code.py, and run it without the shell, the display shows a current time, beginning with 12:00.

#

I think something in the code is pulling a localtime from my computer, and not setting it on the esp32 based on the API call.

fiery grove
#

I don't know what dark magic Thonny does. Can you post the entire code (fix the backticks)? That would make it easier to load it up and try it.

#

I'd suggest trying to with an editor that doesn't do any interactions with the desktop environment... editor and serial console only.