Compare commits

...

10 Commits

Author SHA1 Message Date
12291d46ce Add ESP32-pair/ben_cuelight.py 2026-03-01 21:15:28 +11:00
c846467feb Merge pull request 'beta -> main' (#3) from beta into main
Reviewed-on: #3
2025-11-21 17:12:13 +11:00
347bc54818 Renoved the ß 2025-11-21 12:20:03 +11:00
Ben Nicholson
1f932b223b added gitignore 2025-11-19 21:47:35 +11:00
Ben Nicholson
b3ade2db86 Added logging info 2025-11-19 21:44:47 +11:00
Ben Nicholson
0654c19fac Fixed spelling mistake 2025-11-19 21:42:51 +11:00
Ben Nicholson
9cbbfc12bc Now works in a service on boot. 2025-11-19 21:41:22 +11:00
8785c81248 Merge pull request 'Merging Beta into Main' (#1) from beta into main
Reviewed-on: #1
2025-11-19 11:22:42 +11:00
1d7e56f837 Change GPIO Both to Rising
Change how the GPI detection workes, so it only does things on the rising edge
2025-11-19 11:19:57 +11:00
Ben Nicholson
d0fd9a0c94 change from push and release operation to just push 2025-11-15 07:40:54 +11:00
6 changed files with 228 additions and 20 deletions

74
.gitignore vendored Normal file
View File

@@ -0,0 +1,74 @@
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk

106
ESP32-pair/ben_cuelight.py Normal file
View File

@@ -0,0 +1,106 @@
# upload with `mpremote ben_cuelight.py :main.py` when connected with serial
import espnow
from machine import Pin, Timer
import network
import time
import ubinascii
# io0 = Pin(0, Pin.IN)
led = Pin(23, Pin.OUT)
led.value(1)
# turn off after 5s
Timer(0).init(mode=Timer.ONE_SHOT, period=5000, callback=lambda _: led.value(0))
print("Ben Cuelight Starting...")
# ESPNow https://docs.micropython.org/en/latest/library/espnow.html
sta = network.WLAN(network.WLAN.IF_STA)
sta.active(True)
def nice_mac(bys): return ubinascii.hexlify(bys, ":").decode()
my_mac = sta.config("mac")
MOS_X4_MAC = b"\x00\x70\x07\x7C\xDB\xC8"
ETH_01_MAC = b"\x14\x08\x08\x9E\xA1\x94"
print("MAC Address", nice_mac(my_mac))
e = espnow.ESPNow()
e.active(True)
print("ESPNow active")
def wait_change(pin):
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
while active < 20:
if pin.value() != cur_value:
active += 1
else:
active = 0
time.sleep(0.001)
def mos_x4():
print("I am: MOS_X4")
mos1 = Pin(16, Pin.OUT) # flash
mos2 = Pin(17, Pin.OUT)
mos3 = Pin(26, Pin.OUT)
mos4 = Pin(27, Pin.OUT) # mute-state
flash = mos1
mute = mos4
mute.value(0)
flash.value(0)
timer = Timer(1)
while True:
host, msg = e.recv()
if msg and host == ETH_01_MAC:
if msg[0] == 1:
# on
print("on")
mute.value(1)
timer.init(mode=Timer.PERIODIC, period=1000, callback=lambda _: flash.toggle())
elif msg[0] == 0:
# off
print("off")
mute.value(0)
flash.value(0)
timer.deinit()
else:
# ????
print("??", msg, msg[0])
...
def eth_01():
print("I am: ETH_01")
peer = MOS_X4_MAC
e.add_peer(peer)
button = Pin(12, Pin.IN, Pin.PULL_UP)
remote_state_on = False
while True:
wait_change(button)
if button.value() == 0:
remote_state_on = not remote_state_on
print("Setting remote to:", "on" if remote_state_on else "off")
e.send(peer, bytes([1 if remote_state_on else 0]))
if my_mac == MOS_X4_MAC:
mos_x4()
elif my_mac == ETH_01_MAC:
eth_01()
else:
print("Unknown device!!!", my_mac)

View File

@@ -8,3 +8,16 @@
- Python 3
- Python 3 Requets
- Python 3 RPi.GPIO
## Install instructions
- Downloand script into /usr/local/bin/
- Download rrcs-trigger file and place into /usr/local/bin/
- Download rrcs-trigger.service and place it into /etc/systemd/system/
- Run the follwoing commands to enable the service on boot. ```sudo systemctl enable rrcs-trigger.service``` and ```sudo systemctl start rrcs-trigger.service```
- Run the following command to see how its booting up. ```watch systemctl status rrcs-triggers.service```
- Modify the script to have your RRCS Server IP address and port.
## Logging
- All logs are printed to journalctl, this includes when the button is pressed.

33
ras_pi_RRCS_BusyLight.py Normal file → Executable file
View File

@@ -1,16 +1,18 @@
#!/usr/bin/python3
import os
os.environ['RPI_LGPIO_REVISION'] = "800012"
import time
import requests
import RPi.GPIO as GPIO
import socket
RED = "\033[91m"
GREEN = "\033[92m"
RESET = "\033[0m"
BenBusyRRCSdataRising = '''<?xml version="1.0"?>
PressVirtKey1OnBench = '''<?xml version="1.0"?>
<methodCall>
<methodName>PressKeyEx</methodName>
<params>
@@ -28,7 +30,7 @@ BenBusyRRCSdataRising = '''<?xml version="1.0"?>
</methodCall>
'''
BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
ReleasePressVirtKey1OnBench = '''<?xml version="1.0"?>
<methodCall>
<methodName>PressKeyEx</methodName>
<params>
@@ -49,26 +51,19 @@ BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
def button_callback(channel):
if GPIO.input(channel):
print(f"{RED}Button pressed{RESET}")
r = requests.post(
'http://10.75.120.229:8193',
headers={'content-type': 'text/xml'},
data=BenBusyRRCSdataRising
)
else:
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=PressVirtKey1OnBench)
time.sleep(0.05)
print(f"{GREEN}Button released{RESET}")
r = requests.post(
'http://10.75.120.229:8193',
headers={'content-type': 'text/xml'},
data=BenBusyRRCSdataFalling
)
print(r.text)
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=ReleasePressVirtKey1OnBench)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# One event detector, both edges:
GPIO.add_event_detect(12, GPIO.BOTH, callback=button_callback, bouncetime=200)
GPIO.add_event_detect(12, GPIO.RISING, callback=button_callback, bouncetime=200)
input("Press enter to quit\n\n")
print("RRCS-Trigger ready for input")
[sockA, sockB] = socket.socketpair()
junk = sockA.recv(1) # will never return since sockA will never receive any data
print("This should never get printed")
GPIO.cleanup()

2
rrcs-trigger Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
exec /usr/bin/python3 /usr/local/bin/ras_pi_RRCS_BusyLight.py

18
rrcs-trigger.service Executable file
View File

@@ -0,0 +1,18 @@
[Unit]
Description=Runs the ras_pi_RRCS_BusyLight.py script at boot
After=network.target
#StartLimitIntervalSec=5
[Service]
Type=simple
Restart=always
RestartSec=5
User=root
ExecStart=/usr/local/bin/rrcs-trigger /usr/local/bin/ras_pi_RRCS_BusyLight.py
WorkingDirectory=/tmp
StandardOutput=journal
StandardError=journal
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target