Getting Started
Adafruit Playground is a wonderful and safe place to share your interests with Adafruit's vibrant community of makers and doers. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.
The goal of Adafruit Playground is to make it as simple as possible to share your work. On the Adafruit Playground users can create Notes. A note is a single-page space where you can document your topic using Adafruit's easy-to-use editor. Notes are like Guides on the Adafruit Learning System but guides are high-fidelity content curated and maintained by Adafuit. Notes are whatever you want them to be. Have fun and be kind.
Click here to learn more about Adafruit Playground and how to get started.
-
SocketPoolLogger
Have you ever needed to troubleshoot why you are having issues with your MCU and the internet? Ever been curious how internet requests work? Well this might get you a little closer.
Introducing: SocketPoolLogger
What is
SocketPoolLogger? it's a little class, that allows you to log everything that happens with a socket.And instead of the normal message we get from the
response.text, we get all of this: -
Get Radio
I've been spending a bunch of time testing code across different MCUs and networking chips. It started with my work with Connection Manager. Then I was digging into Requests and MiniMQTT . Which of course lead me to places like NTP, AzureIoT and AWS_IOT.
As I jumped around, I needed a way to always get the right radio. Sometimes it's native WiFi, which is easy:
wifi.raidio, but other times, it's some SPI based FeatherWing or maybe a M4 with and AirLift (talking to youPyPortalandMatrixPortal M4)...Introducing:
get_radioIt's not perfect, and I'm guessing there are things I haven't thought of, but it works for me so far.
The only thing a normal developer, with the right libraries installed and only one radio needs to do is:
The nice thing is it will connect for you and everything! Store your creds as
WIFI_SSID? Got you covered. What aboutCIRCUITPY_WIFI_SSID? Got you covered there too. What about insecrets.py? Sadly not there,settings.tomlis the way to go.Now let's say you aren't using a FeatherWing, or you are connecting things to different pins? Well your set there too!
-
Adafruit Connection Manager
What is the Adafruit Connection Manager? It is a helper class designed around making connections to the internet easier and does this by simplifying a few things.
First, what are the underlying pieces we need to connect to the internet?
Sockets
Everything that connects to the internet needs a socket. A socket is what handles the basic sending and receiving of messages between 2 devices (like your microcontroller and a web API).
Microcontrollers, unlike desktop computers, have limited memory and can't have 100s of sockets open. The average chip can have maybe 2-3 and the bigger ones top out around 10.
Previously the sockets were controlled at a per library level. Meaning if you used
adafruit_requests(to get info from the web) andadafruit_minimqtt(to send something to AdafruitIO) they both managed sockets separately, which means that one might block the other from getting one. And on top of that, the way you interfaced with them was different!Here comes ConnectionManager to the rescue! Both these libraries now ask the ConnectionManager for a socket and it handles tracking what's open and what's not. And to make code even simpler, it's what's called a singleton. There is only one, where previously you needed to create your
requests.Session()early in your code and use that one everywhere, now it doesn't matter.Socket Pool and SSL Context Helpers
What are these?
The
socketpoolis what creates the sockets for each internet connected chip, and thessl_contextis what has all the certificate information to validate that the connection is secure.For the
Adafruit AirLift(which uses an ESP32 WiFi Co-Processor):