Skip to content

Instantly share code, notes, and snippets.

@ryang14
ryang14 / serve_file.py
Last active June 13, 2021 12:54
Serve file add-on for CircuitPython WSGI server
import os
import time
class ServeFile:
def __init__(self, app, path="", webpath=""):
self._app = app
self._path = path
self._webpath = webpath
# Common MIME types from https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
@ryang14
ryang14 / http_server.py
Last active January 31, 2022 00:17
CircuitPython HTTP server
class HTTPRequest:
def __init__(self, method="", path="", req_bytearray=None):
if req_bytearray is None:
self.method = method
self.path = path
else:
# Parse request data from byte array
lines = req_bytearray.decode("utf8").split('\r\n')
request = lines[0].split(' ')
self.method = request[0]
@ryang14
ryang14 / cannode.py
Created December 19, 2020 15:16
A canio based CAN node library
import struct
import time
import board
import canio
import digitalio
# Create a node on a CAN network
# Uses the 29-bit extended message ID which contains both a node ID and topic ID
# Node ID is the source when sending from a node and destination when sending from the controller to a node
@ryang14
ryang14 / code.py
Created May 12, 2020 22:39
Code to use CircuitPython over WiFi. Very rough around the edges, but seems to work pretty well
import storage
import adafruit_requests as requests
import networkInit # Board specific network connection
try:
from secrets import secrets
connectionString = secrets["ota_connection_string"]
except (ImportError, KeyError):
print("Connection string is kept in secrets.py, please add it there!")