Skip to content

Instantly share code, notes, and snippets.

View nbuchwitz's full-sized avatar
👋
hi there

Nicolai nbuchwitz

👋
hi there
View GitHub Profile
#!/bin/bash
rpi_revision_code() {
# see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes
code=$(grep Revision /proc/cpuinfo | cut -f 2 -d \: | xargs)
echo $((16#${code}))
}
rpi_type() {
#!/bin/bash
set -e
nm_files="dhcp-eth0.nmconnection dhcp-eth1.nmconnection fallback-link-local-eth0.nmconnection fallback-link-local-eth1.nmconnection 99-revpi.conf"
download_dir=$(mktemp -d)
echo -n "This script will change the network configuration from dhcpcd to NetworkManager. Do you want to proceed? [yN] "
read choice
#!/bin/bash
if [[ $(id -u) != 0 ]]; then
echo "usage: sudo $(basename $0)"
exit 1
fi
pibridge_static_mac() {
interface=$1
#!/bin/bash
VENDOR_ID=2109
PRODUCT_ID=2817
# find all devices which match our product id
for f in $(grep --include='idProduct' -rlw "$PRODUCT_ID" /sys/bus/usb/devices/usb* 2>/dev/null); do
device=$(dirname $f)
# ensure that vendor id also matches
@nbuchwitz
nbuchwitz / copy_modbus_to_gateway.py
Created March 11, 2022 12:59
RevPi: Copy data from virtual modbus registers to gateway component
#!/usr/bin/env python3
import revpimodio2
def loop_function(ct):
# copy 5 input register from modbus to gateway
rpi.io.Gateway_Output_Word_1.value = rpi.io.Input_Word_1.value
rpi.io.Gateway_Output_Word_2.value = rpi.io.Input_Word_2.value
rpi.io.Gateway_Output_Word_3.value = rpi.io.Input_Word_3.value
rpi.io.Gateway_Output_Word_4.value = rpi.io.Input_Word_4.value
import os
import revpimodio2
class Application():
def __init__(self):
self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
self.rpi.handlesignalend(self.cleanup_revpi)
self.rpi.core.x2in.reg_event(self.event_shutdown, edge=revpimodio2.RISING)
#!/usr/bin/env python3
import sys
import json
import argparse
import os.path
DEFAULT_CONFIG_NEW = "/var/www/revpi/pictory/projects/_config.rsc"
DEFAULT_CONFIG_OLD = "/var/www/pictory/projects/_config.rsc"
import revpimodio2
def ev(name, value):
# payload is bytes, so we need to know the enconding (eg. ascii, utf-8, etc...)
print(name, value.decode('ascii'))
rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)
rpi.handlesignalend()
# define IO: change length of string in the frm argument
@nbuchwitz
nbuchwitz / dashboard.json
Last active January 10, 2022 21:54
esphome gas meter
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
- name: schedule downtime
uri:
url: "https://{{ icinga_host }}:{{ icinga_port | default(5665) }}/v1/actions/schedule-downtime"
user: "{{ icinga_user }}"
password: "{{ icinga_password }}"
force_basic_auth: True
validate_certs: False
method: POST
headers:
Accept: "application/json"