Why can't I include socketpool on Matrix Portal M4?

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bp2008
 
Posts: 4
Joined: Thu Jun 30, 2022 8:15 pm

Why can't I include socketpool on Matrix Portal M4?

Post by bp2008 »

Hello everyone!

I've been learning CircuitPython by programming a Matrix Portal M4 to operate as a digital wall clock with a custom text readout along the bottom.

One of the first things I tried to do was adapt the network connected clock example to use the NTP helper instead of the adafruit.io service to synchronize time. However this fails because the NTP helper requires the socketpool module and I get this error when I try to import socketpool at the top of the code.py file:

Code: Select all

ImportError: no module named 'socketpool'
Later I found the Module Support Matrix which shows socketpool is not available on the Matrix Portal M4. Is this somehow because the device uses an "airlift" coprocessor for wifi? Is there a way around this limitation? I've looked everywhere for a socketpool.mpy library or anything like that which I could copy into CIRCUITPY/libs but I can find nothing. socketpool seems to be a pretty common dependency in a lot of network-related examples, so I'm hopeful that someone knows a way to use it here, or could explain why it isn't available.

Same goes for other modules like traceback. I was trying to figure out how to log a stack trace when some code throws an exception, and internet searches led me to the traceback module, but that is also unavailable on the Matrix Portal M4. So ultimately the only way I've figured out to get a stack trace out of circuitpython is to not catch the exception, and let the system catch it, at which point it will output the stack trace to console (using traceback!??).

I feel like I'm missing something fundamental here, like a JavaScript developer who has never heard of npm or something.

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by neradoc »

Hi, the socketpool module is for builtin wifi, on ESP32-* boards.
The adafruit_ntp library was changed to use builtin wifi, because the feature is already supported in the ESP32SPI library.
To use the NTP module of the ESP32SPI library, see the example here: https://github.com/adafruit/Adafruit_Ci ... /tag/3.0.0

Traceback is a builtin module, it was accidentally removed from the Matrix Portal in 7.3.0 and will be added back when 7.3.2 is released.
(Some builtin modules can be removed from certain builds to save space).
You can try 7.2.5 to get it back, or the build from the 7.3.x PR that fixed it should work, the matrixportal_m4 zip file at the bottom of the following page:
https://github.com/adafruit/circuitpyth ... 2578875461

User avatar
bp2008
 
Posts: 4
Joined: Thu Jun 30, 2022 8:15 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by bp2008 »

Nice. Thanks for your help. I had tried 7.3.1 and 8.0.0 alpha 1, but nothing older than those!

Regarding the NTP example you linked, that actually raises more questions. Are you saying the esp.get_time() method uses NTP? Where would the NTP server address be configured? Docs for get_time() just say "The current unix timestamp" which is pretty unspecific. It doesn't even say what type is returned. In the example, it is shown being used like this:

Code: Select all

time.localtime(esp.get_time()[0])
And that suggests to me that get_time() actually returns an array or list of some kind where the first value is the timestamp in integer seconds. Unless I don't understand python as well as I think I do...

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by tannewt »

bp2008 wrote:Nice. Thanks for your help. I had tried 7.3.1 and 8.0.0 alpha 1, but nothing older than those!

Regarding the NTP example you linked, that actually raises more questions. Are you saying the esp.get_time() method uses NTP? Where would the NTP server address be configured? Docs for get_time() just say "The current unix timestamp" which is pretty unspecific. It doesn't even say what type is returned. In the example, it is shown being used like this:

Code: Select all

time.localtime(esp.get_time()[0])
And that suggests to me that get_time() actually returns an array or list of some kind where the first value is the timestamp in integer seconds. Unless I don't understand python as well as I think I do...
Its either NTP or time from the access point I'm not sure.

It does return a tuple of one element that is the timestamp. (Hence the [0]) I don't know why the API does that but it does.

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by neradoc »

Yeah, it's a builtin feature of the Arduino Nina firmware running on the ESP32, and I don't know either how it retrieves the time.
Looking quickly at the source, it looks like it uses the Arduino Time library maybe ? Or some function of the ESP-IDF.

User avatar
bp2008
 
Posts: 4
Joined: Thu Jun 30, 2022 8:15 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by bp2008 »

I found the get_time source code and I agree there doesn't seem to be any way to set the NTP server address either (or even to learn what it is), which means it is most likely 100% internet-dependent. Not great for a clock.

I also found this merged pull request which provides an example low-level NTP client that I may be able to use. Although at this point I am most likely going to use MQTT or simple JSON-over-HTTP to feed data into my very over-engineered "clock". Whatever data channel I use, I can just include the current local time in the data and that will eliminate the need for NTP and also handle daylight savings issues transparently.

JSON-over-HTTP is tempting because it is easy. MQTT is tempting because I'm pretty impressed with the MiniMQTT client library and its "non-blocking" polling, and I suspect it would be a much more efficient way to asynchronously push text changes to the Matrix Portal. I looked at the source. The MiniMQTT loop() method doesn't need to send data over wifi and wait for a response every time I call it, only once in a while for keepalive purposes, so it should keep the airwaves relatively quiet compared to polling with HTTP every second.

User avatar
bp2008
 
Posts: 4
Joined: Thu Jun 30, 2022 8:15 pm

Re: Why can't I include socketpool on Matrix Portal M4?

Post by bp2008 »

I've got to say, I am really impressed by adafruit's expertise in so many areas. Online shopping, electronics hardware design and production, and a huge amount of software development too from the look of things. And all the very good tutorials and guides. This is an exciting time.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”