Skip to content

Instantly share code, notes, and snippets.

@anecdata
anecdata / RADS.md
Last active Sep 22, 2022
RADS: Redundant Array of mDNS http Servers
View RADS.md

In the configuration pictured below, multiple Adafruit CircuitPython 8.0.0-beta.0 on 2022-08-18; Adafruit QT Py ESP32S2 with ESP32S2 are used to create a Redundant Array of mDNS http Servers. The devices could be physically together or scattered around, as long as they are on the same LAN. Once configured, no USB connection is necessary for operation.

Each is running CircuitPython 8 Web Workflow: https://docs.circuitpython.org/en/latest/docs/workflows.html#web

Web Workflow automatically connects to a Wi-Fi Access Point based on credentials in a /.env file in the root of the CIRCUITPY drive filesystem, and creates an HTTP Server (port can be changed with CIRCUITPY_WEB_API_PORT= in the /.env file; it's port 80 by default).

In code.py, run an HTTP Server using (for example): https://docs.circuitpython.org/projects/httpserver/en/latest/api.html Make sure that the ports are different between the Web Workflow HTTP Server and the code.py HTTP Server (e.g., set the code.py HTTP Serv

@anecdata
anecdata / cadata.py
Created Sep 12, 2022
Espressif port: context.load_verify_locations(cadata=CA_STRING)
View cadata.py
import wifi
import socketpool
import ssl
import adafruit_requests
# local
from secrets import secrets
URL = "https://jwst.nasa.gov/content/webbLaunch/flightCurrentState2.0.json?unique=1643741752388"
@anecdata
anecdata / about.py
Last active Aug 31, 2022
CircuitPython: basic info about a device
View about.py
print(f"\nBOARD")
import os
print(f"Name: {os.uname().machine}")
import microcontroller
uid = ''.join('%02X' % _ for _ in microcontroller.cpu.uid)
print(f"CPU UID: {uid}")
import sys
print(f"Platform: {sys.platform}")
import board
print(f"board_id: {board.board_id}")
@anecdata
anecdata / mdns_finder.py
Created Aug 31, 2022
CircuitPython mDNS finder for ESP32-S2/S3
View mdns_finder.py
import time
import wifi
import ipaddress
import socketpool
import mdns
from secrets import secrets
MDNSFINDTIMEOUT = 5
pool = socketpool.SocketPool(wifi.radio)
@anecdata
anecdata / wwotg.md
Last active Aug 24, 2022
Web Workflow OTG
View wwotg.md

Using iOS to place files onto a CircuitPython [CP] device has been possible for several years: https://blog.adafruit.com/2019/09/19/program-circuitpython-devices-with-iphone-ios-13/ https://learn.adafruit.com/use-circuitpython-devices-with-iphone-ipad/copy-edit-paste

However, iOS doesn't support USB CDC, so there is no REPL or serial capability.

Goal:

A "traveling light" configuration for setting up and using CircuitPython Web Workflow without a large computer. Basic ingredients would be an iPhone, one or two small CP microcontrollers (QT Py ESP32-S2 for example, but perhaps including a device without native-USB, like ESP32-C3 or ESP32), and assorted accessories.

@anecdata
anecdata / code.py
Created Mar 20, 2022
UDP Server ESP32SPI read-only (very rudimentary)
View code.py
import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
from secrets import secrets
@anecdata
anecdata / code.py
Last active Feb 11, 2022
HTTPS request via TCP Socket - CircuitPython on Espressif
View code.py
# initial read only (typically headers)
import wifi
import socketpool
import ssl
import ipaddress
from secrets import secrets
HOST = "example.com"
PATH = "/"
@anecdata
anecdata / code.py
Last active Aug 29, 2022
Simple HTTPS request - CircuitPython on Espressif
View code.py
import wifi
import socketpool
import ssl
import adafruit_requests
# local
from secrets import secrets
URL = "https://example.com"
@anecdata
anecdata / code.py
Last active Feb 3, 2022
RGB Matrix (is31fl3741) Wi-Fi Monitor
View code.py
import random
import time
import board
import busio
import wifi
import adafruit_is31fl3741
from adafruit_is31fl3741.adafruit_rgbmatrixqt import Adafruit_RGBMatrixQT
QUEUELEN = 128 # ESP32-S2 (ESP32-S3 can be much longer)
@anecdata
anecdata / ambient.py
Last active Jan 26, 2022
CircuitPython Espressif Monitor mode ambient frame count per channel
View ambient.py
import time
import wifi
QUEUELEN = 128 # ESP32-S2 (ESP32-S3 can be much longer)
NS_PER_CH = 5_000_000_000 # nanoseconds per channel
def monitor_ambient(channel, duration):
report = {}
monitor = wifi.Monitor()