Skip to content

Instantly share code, notes, and snippets.

@karlp
karlp / decode-esp32-backtrace.sh
Created September 19, 2023 10:58
example decoding backtraces by hand for esp32
#!/bin/sh
[ -e "$1" ] || { printf "Must provide .elf as argument\n"; exit 1; }
printf "Paste your backtrace and press ctrl-d\n";
sed -e 's/ /\n/g' | grep 0x | cut -d':' -f1 | xargs xtensa-esp32-elf-addr2line -pfiaC -e $1
# Nominally, you _could_ autoconstruct which toolchain to use from
# the CONFIG_IDF_TARGET_ARCH and CONFIG_IDF_TARGET fields in sdkconfig...
#!/usr/bin/env python3
"""
Testing handling exceptions from threads inside asyncio
"""
import asyncio
import logging
import random
import threading
import time
@karlp
karlp / SimpleSecureHTTPServer.py
Created October 31, 2012 16:04
HTTPS python server
'''
SimpleSecureHTTPServer.py - simple HTTP server supporting SSL.
- replace fpem with the location of your .pem server file.
- the default port is 443.
usage: python SimpleSecureHTTPServer.py [server.pem] [port]
prereq: make a cert!
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
@karlp
karlp / diff-for-stm32l1-patch
Created September 11, 2020 14:00
renode for stm32l1 stuff (renode 1.10.1 era)
--- /home/karlp/src/renode-git/platforms/cpus/stm32l151.repl 2020-09-11 10:16:06.627671941 +0000
+++ /opt/renode/platforms/cpus/stm32l151.repl 2020-09-11 12:09:07.482336609 +0000
@@ -77,7 +77,8 @@
sysbus:
init:
- ApplySVD @https://dl.antmicro.com/projects/renode/svd/STM32L1xx.svd.gz
+ //ApplySVD @https://dl.antmicro.com/projects/renode/svd/STM32L1xx.svd.gz
+ ApplySVD @https://raw.githubusercontent.com/posborne/cmsis-svd/master/data/STMicro/STM32L1xx.svd
Tag <0x4000280C, 0x40002810> "RTC_ISR" 0x60
$ ./rmw
set: from initial: 0xffffffff, setting mode: 6 => 0xffff6fff
set2: from initial: 0xffffffff, setting mode: 6 => 0xffff6fff
set: from initial: 0, setting mode: 6 => 0 <<<< failed to set properly.
set2: from initial: 0, setting mode: 6 => 0x6000
@karlp
karlp / MANIFEST.in
Created August 16, 2013 08:37
Including git version in setup.py files. (Requires at least _one_ tag in the repo) Normally used to make things like, "python setup.py sdist" give you a predictable name for files. Normally used with tags on the repo like 0.1 or 2.3.0 You should add RELEASE-VERSION to MANIFEST.in so that end users of the tarball can use this too.
include RELEASE-VERSION
include version.py
# Anything else you normally use
@karlp
karlp / demo.html
Created February 16, 2018 12:24
mosquitto simple speed
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
<script>
client = new Paho.MQTT.Client("somehost", 8083, "clientId");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
@karlp
karlp / wemos_dht.lua
Last active June 30, 2016 14:09
Publish DHT22 to MQTT on an ESP8266 (wemos D1 mini)
-- DHT22 to MQTT Publisher
-- Andrew Elwell, 2016-06-08
client='ESP-'..node.chipid()
m = mqtt.Client(client, 60)
m:lwt("status/"..client, "offline", 0, 1)
m:connect("10.1.1.251", 1883, 0, 1, function(hohoho)
print("connected")
hohoho:publish(string.format("status/%s", client, 0, 1))
@karlp
karlp / controller-jquery.lua
Last active February 9, 2016 10:48
jquery ajax post application/json to luci openwrt lua web admin
module("luci.controller.rme.jquery", package.seeall)
local http = require("luci.http")
local protocol = require("luci.http.protocol")
local json = require("luci.json")
function index()
entry({'karl', 'modbus_devices'}, call("action_modbus_devices"), "Modbus Devices", 20).dependent=false
end
function kkdumpt(tt, label)
@karlp
karlp / gist:6502796
Last active December 22, 2015 16:58
#!/usr/bin/python
# script to poll growatt PV inverter and spit out values
# Andrew Elwell <Andrew.Elwell@gmail.com> 2013-09-01
import ConfigParser
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import time
import mosquitto