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 / 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 / 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 / luasrc-controller-demo.lua
Last active August 29, 2015 14:10
luci json post quirk
--[[
just tries to parse the json posted and reply ok/NAK
--]]
module("luci.controller.rme.demo", package.seeall)
local http = require("luci.http")
local protocol = require("luci.http.protocol")
local json = require("dkjson")
--local json = require("luci.json")
function index()
@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
@karlp
karlp / badkeys.py
Created September 9, 2013 17:34
hrmm, how to make sure that the publish handler isn't called before I've saved the MID? Is my only safe answer here to use the non-threaded api, and call loop only when I'm actually ready?
#!/usr/bin/env python
from __future__ import division
import collections
import logging
import math
import random
import string
import time