Skip to content

Instantly share code, notes, and snippets.

View nbuchwitz's full-sized avatar
👋
hi there

Nicolai nbuchwitz

👋
hi there
View GitHub Profile
@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
#!/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
#!/bin/bash
if [[ $(id -u) != 0 ]]; then
echo "usage: sudo $(basename $0)"
exit 1
fi
pibridge_static_mac() {
interface=$1
#!/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
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() {
#!/usr/bin/env python3
import argparse
import random
import subprocess
import sys
import can
verbose = False