#Getting time with esp32spi

1 messages Β· Page 1 of 1 (latest)

terse slate
#

Hello! New to this server and doing my very first project with an adafruit board, so very much in the "know practically nothing" category.

I have a Metro M4 Airlift Lite and am connecting to wifi via esp32spi since it doesn't have the wifi module as an option. (CircuitPython 7.3.3)

I can connect to wifi and confirm internet connectivity just fine, but esp.get_time() can't get beyond the OSERROR about returning 0. I've set it to reattempt every second, but it's still just returning that exception after 30 minutes of trying.

Below is the section of code I have connecting to the internet and trying to get time (stitched together from different adafruit tutorials).

I confirmed that it is connecting to my wifi, reporting back its local ip address, and able to reach the internet to report the ip address of adafruit.com and ping to google.com. I'm about ready to just manually scrape the current time from the web or other api, but I wanted to check if someone might be familiar with this issue and could point out a simple error/solution. πŸ™‚ (I've read several posts about the method initally returning 0, before getting a good response after 15 seconds or so. However, patience doesn't seem to be working here.)

Code is truncated since Discord says it's too long:

###...

# Create esp
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)

###...

# Set current datetime
now_utc = None
attempt = 1
while now_utc is None:
    try:
        now_utc = time.localtime(esp.get_time()[0])
    except OSError:
        print(f'Attempt {attempt}')
        attempt += 1
        time.sleep(1)
print(now_utc)

Much thanks for taking the time to read. πŸ™‚

red sequoia
#

I haven't seen that behavior, just the delay after start-up. What version of NINA firmware is on the Metro? I t ships with 1.2.2 probably, 1.7.4 is latest I believe, but get_time() has always been there so it may improve some things to update it won't fix this.

#

there's an older version of the NTP library tht was written for ESP32SPI, but it uses that same call so I doubt it would help

#

what if you lengthen the delay in your code above? maybe it doesn't like something about being asked at 1 Hz? reaching, I know

#

On my PyPortal, I get:```py
code.py output:
Attempt 1
Attempt 2
struct_time(tm_year=2023, tm_mon=1, tm_mday=14, tm_hour=0, tm_min=40, tm_sec=36, tm_wday=5, tm_yday=14, tm_isdst=-1)

#

is something on your network blocking port 123 NTP?

terse slate
#

I did originally attempt things with NTP and generally had the same non-starter condition, ultimately reading a thread "NTP isn't recommended anymore" without explanation. A couple hours later I had the above code with esp32spi.

I've seen the word NINA, but I am ignorant, so I will google that now and see about version/updating. I had followed the tutorial for the board up update the firmware, then update CircuitPython, so not sure if that's embedded in there as I am at the "monkey see, monkey do" level currently.

My current INFO_UF2.TXT reads (in case its relevant):

UF2 Bootloader v3.14.0 SFHWRO
Model: Metro M4 AirLift
Board-ID: SAMD51J19A-Metro-AirLift-v0
red sequoia
#

print("Firmware vers.", esp.firmware_version)

#

not a big deal if it's 1.2.2, I don't think that affects this

#

but once you get going, you probably want to think about updating it, there's a learn guide

#

(NINA is the firmware that runs on the ESP32... it's the other end of the SPI connection)

terse slate
#

I might have fried my board. 🫠 I did find the tutorial to update NINA at the end of the board tutorial (after the wifi connect part I was working on). I followed along, got it the new binary transferred and when it said to reset at the end, my board is no longer recognized. It's not coming up on USB at all anymore, not the CircuitPython drive, nor the boot drive from a double-reset.

Red Neopixel, Green On, others off
I'm currently googling to try and decode that....

red sequoia
#

can you link me to the update procedure you used (passthru .ino?)

#

it's probably recoverable

#

it's hard to really brick these things

terse slate
#

I started from here:
https://learn.adafruit.com/upgrading-esp32-firmware/upgrade-all-in-one-esp32-airlift-firmware

Used the Metro_M4 download, drag and dropped into the boot drive.

It came up correctly as a com port

Used this link with Edge version 108: https://adafruit.github.io/Adafruit_WebSerial_ESPTool/

Com port was seen fine, selected the .bin file I'd downloaded from GitHub and it seemed to complete fine, but then when it said to reset. πŸ’₯

Adafruit Learning System

Keep the firmware on your ESP32 WiFi-BLE Co-Processor up-to-date!

red sequoia
#

so this is where it went bad? ""To run the new firmware,..." then pressing reset?

#

I haven't used that process, only command line esptool, but if the bootloader won't even come up, something is truly borked, let me do a little checking

#

if nothing there rings a bell, you may want to post the new issue and question back in the main channel (I'm not too familiar with Windows, and haven't used the Chrome esptool)

terse slate
#

Now I am doubting myself and wondering if I misread a line or something. The green bar definitely completed and went away and the screen wasn't changing for a few minutes, but now I am filled with doubt if I misread what it really said and did something stupid late in the day on a Friday... πŸ€ͺ

I think it just came back as a com port...randomly. (I tried switching USB cables and ports, just in case.) I have access to the board in the web tool again...

red sequoia
#

that's a relief, are you trying again

#

on a separate track... the other thing I was going to suggest about getting the time... can you hotspot to your phone to rule out the network doing something funny with NTP?

terse slate
#

I HAVE NO IDEA WHY, BUT...

After I got it to come back up in edge, I thought, "hey, let's try starting over in Chrome." It wouldn't connect in Chrome since the port was "already in use." I went back to Edge and coudn't connect because the port was "already in use." So I reset, and it didn't seem to respond, then I doube-reset and got the boot drive back...for whatever reason.

red sequoia
#

(when it's working again)

terse slate
#

(When you mentioned maybe a port being blocked, my mind went to trying my phone hotspot too. I just bricked it too fast to try that, so I will definitely add that to my trials if I can get on stable ground after whatever the firmware oopsie this was.)

#

At the moment, I can reliably get to the boot drive with a double-reset. But the CircuitPython drive won't show up with a single reset. I'll redo the board firmware and CircuitPython first, then maybe try to redo NINA if it's still not coming up.

red sequoia
#

the CircuitPython drive won't show up until you re-install CircuitPython UF2 onto the bootloader drive after finishing with the passthru UF2

terse slate
#

Phew. I'm at least back to being able to see the CircuitPython drive and a bunch of failed attempts to get time (with successful connection to wifi and internet pings).

red sequoia
#

CIRCUITPY is on the 8MB external flash, the bootloader and passthru.uf2 or circuitpython UF2 are on the onboard flash

#

ah, good

terse slate
red sequoia
#

so no firmware change to NINA, still presumably 1.2.2? (which is ok)

terse slate
#

Let me see if I can check that. (I did presumably transfer the file the first time...)

red sequoia
#

that would be nice if it actually worked after all this πŸ˜‰

terse slate
#

The snippet you provided returned:

Firmware vers. bytearray(b'1.7.4\x00')

red sequoia
#

w00t

terse slate
#

Indeed! At least I got something out of that little romp. 😁 Trying phone hotspot now....

#

No luck on the phone with a minute of attempts @ 1Hz. Trying on the phone with .2Hz...

red sequoia
#

that's really strange, have not encountered never getting time back before

terse slate
#

I did buy a couple different boards, including a PyPortal, so maybe I can set that up. If the PyPortal works, maybe I've got something defective in the M4. If it doesn't work, then I'm not sure what's wrong locally since I tried my phone. I can't imagine the wifi chip behaves differently when connected to a computer, but I guess I could program it to make some attempts and send the result instead of watching it through Mu.

Obviously I have no clue what I'm doing and so have no gauge with which to judge strangeness other than....I think I'm following the directions... (Thank you again for your help.)

Booting up PyPortal now...but might not finish the test tonight as I'm running out of steam a bit. πŸ™‚

#

(Oh the lengths I go to to put a speedometer on my cat's exercise wheel...) toebeans

red sequoia
#

The PyPortal and Metro Airlift are so similar internally. I can't even imagine how this could be a soiftware or firmware issue though.

terse slate
#

I know I'm definitely stumped. πŸ€·β€β™€οΈ

#

I do still have the fallback plan of manually scraping time from the web, one way or another. So I'm sure I'll survive, but it is definitely a curiosity...

red sequoia
#

you seem to have a good handle on this stuff, some clue will hopefully arise

#

CircuitPython 7.3.3 and current libraries should be quite stable

#

(well, except for all the networking things that go wrong that try / except helps with)

#

I've spent way too much time thinking about time too... ways to get it, how to deal with timezone, etc

terse slate
#

You said you were running PyPortal, right? Are you on CircuitPython 7.3.3 with the latest NINA version as well?

red sequoia
#

I have 8.0.0-beta.6 on PyPortal, no other Airlift / ESP32-co-processor configs without constructing something ...but I had 7.3.3 on it for a long time

#

yes to NINA 1.7.4

#

although I have stuff with all kinds of NINA versions on it, some improvements over time, but the old stuf still works'

terse slate
#

Thanks, I'll try 7.3.3 and follow with 8 if I have problems. Who knows, maybe there is some stray line of code or package file that's wrong in the download package for the M4. Or maybe something got corrupted in the download and I should try redownloading everything from scratch...

red sequoia
#

can't hurt

#

PyPortal results will give a good clue

#

if you pick this back up later, this thread will be kind of buried, so put something back in the main channel, or feel free to ping me

terse slate
#

I'm hoping so, but I think I'll take a little break tonight since I've been at it for several hours already. Thank you so much and I'll post here with my next results. Fingers crossed.

terse slate
#

@red sequoia Apparently there were two problems. After redownloading the uf2 file, the circuitpython installation files, and the adafruit bundle to get fresh mpy files, it was still not connecting on my home network. I pulled up my firewall to monitor the traffic and saw it was getting blocked, added an exception for ntp (even though it was already on a rather permissive guest vlan), and it finally worked. Confused as to why it hadn't worked on my cell phone hotspot before, I made another attempt there to see if it was still getting blocked that way, and now it's working there too! Since my phone was blocking it before and isn't anymore, I have to guess that some little bit somewhere got scrambled in the download and unzipping....but I also had a firewall issue on my home network as you first guessed. So thank you! It works now. Now on to streaming data to quantify my little one's zoomies! (I can't wait to find out her top speed.) 😁