Skip to content

Instantly share code, notes, and snippets.

@agners
agners / tlv-parser.py
Last active February 3, 2024 19:17
Thread credentials dataset TLV parser
#!/bin/env python3
import binascii
import sys
MESHCOP_TLV_TYPE = {
"CHANNEL": 0,
"PANID": 1,
"EXTPANID": 2,
"NETWORKNAME": 3,
@agners
agners / CommissioningStage.h
Created January 11, 2024 13:05
enum CommissioningStage with numeric values
// enum CommissioningStage with numeric values
// from
// https://github.com/project-chip/connectedhomeip/blob/v1.2.0.1/src/controller/CommissioningDelegate.h
enum CommissioningStage : uint8_t
{
kError = 0,
kSecurePairing = 1, ///< Establish a PASE session with the device
kReadCommissioningInfo = 2, ///< Query General Commissioning Attributes, Network Features and Time Synchronization Cluster
kReadCommissioningInfo2 = 3, ///< Query SupportsConcurrentConnection, ICD state, check for matching fabric
@agners
agners / prune-corrupted-layer-metadata.sh
Last active November 30, 2023 21:18
Prune corrupted Docker layers in overlayfs2 storage
#!/bin/sh
# (c) 2023 Stefan Agner
# This scripts attempts to clear corrupted Docker overlay2 storage metadata
# which can be left over after a power failure.
# See also: https://github.com/moby/moby/issues/42964
#
# Typically the error message when attempting to pull the image for which
# corrupted layers are in the storage looks like:
# failed to register layer: error creating overlay mount to /mnt/data/docker/overlay2/6ee02298ee75a4f96e77f90551673cb700f29867f9ad1c4e20b8c816bfcf0735/merged: too many levels of symbolic links
@agners
agners / iomonitor.sh
Created August 18, 2023 13:35
Simple IO monitoring script usful on Home Assistant OS
#!/bin/sh
#
# IO monitoring for Linux
#
# Taken from armbianmonitor
# https://github.com/armbian/build/blob/master/packages/bsp/common/usr/bin/armbianmonitor
# Adjusted to rely on diskstats only.
#
MonitorIO() {
@agners
agners / glc006p.py
Created April 29, 2023 07:14
ZHA custom device (quirk) to override GL-C-006P warm-white/cold-white color temperature
"""GLEDOPTO GL-C-006P device."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
GreenPowerProxy,
Groups,
Identify,
LevelControl,
OnOff,
@agners
agners / rpi-eeprom-ver.sh
Created January 30, 2023 14:10
Get Raspberry Pi EEPROM version (CM4/RPi4, inspired by https://github.com/raspberrypi/rpi-eeprom/blob/master/rpi-eeprom-update)
#!/bin/sh
DT_BOOTLOADER_TS=${DT_BOOTLOADER_TS:-/proc/device-tree/chosen/bootloader/build-timestamp}
BOOTLOADER_CURRENT_VERSION=$(printf "%d" "0x$(od "${DT_BOOTLOADER_TS}" -v -An -t x1 | tr -d ' ' )")
date -u "-d@${BOOTLOADER_CURRENT_VERSION}"
@agners
agners / elgate-wave3-fix.sh
Created June 5, 2022 12:22
Elgato Wave:3 Pulseaudio "unstuck"
#!/bin/sh
# Getting Elgato Wave:3 Microphone input "unstuck" on Linux & Pulseaudio
# Replace <card-name> with your microphones card name (check "pacmd list-cards")
# It looks something like "usb-Elgato_Systems_Elgato_Wave_3_<serial>-00"
pacmd set-card-profile alsa_card.<card-name> output:analog-stereo
pacmd set-card-profile alsa_card.<card-name> input:mono-fallback
@agners
agners / main.py
Last active May 9, 2022 11:48
asyncio aiohttp timeout
import aiohttp
import asyncio
async def work(i: int):
#print(f"start working on {i}")
for i in range(50):
pass
async def main():
tasks = []
@agners
agners / serial_asyncio_test.py
Created April 2, 2022 10:36
Test serial_asyncio with socat
import asyncio
import serial_asyncio
import serial
class Output(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
print('port opened', transport)
# This causes an exception
#transport.serial.rts = False
@agners
agners / README.md
Created February 22, 2022 13:33
Silicon Labs OpenThread native git repositories

Silicon Labs OpenThread native git repositories

Background: Silicon Labs offers OpenThread with modifications to support multi-protocol operations as described in AN1333. At least since Gecko SDK release 4.0.0 (Silicon Labs OpenThread release 2.0.0.0) the OpenThread repositories are available through their unified Gecko SDK releases at https://github.com/siliconLabs/gecko_sdk.

However, this repositories has several flaws:

  • It combines all their SDKs in a single big repository