raspberry
This commit is contained in:
1 parent
84dfdf5210
commit
be436085b3
55 files changed
+2195
No files matched your search
@@ -0,0 +1,46 @@
|
||||
|
||||
# Please take the time to finish this file as described in
|
||||
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
|
||||
# and make it available to others by sending it to
|
||||
# <lirc@bartelmus.de>
|
||||
#
|
||||
# This config file was automatically generated
|
||||
# using lirc-0.10.1(default) on Sat Jun 1 16:13:39 2024
|
||||
# Command line used: --disable-namespace -f -d /dev/lirc0
|
||||
# Kernel version (uname -r): 6.6.31+rpt-rpi-v8
|
||||
#
|
||||
# Remote name (as of config file): Teufel
|
||||
# Brand of remote device, the thing you hold in your hand:
|
||||
# Remote device model nr:
|
||||
# Remote device info url:
|
||||
# Does remote device has a bundled capture device e. g., a
|
||||
# usb dongle? :
|
||||
# For bundled USB devices: usb vendor id, product id
|
||||
# and device string (use dmesg or lsusb):
|
||||
# Type of device controlled
|
||||
# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
|
||||
# Device(s) controlled by this remote:
|
||||
|
||||
begin remote
|
||||
|
||||
name Teufel
|
||||
flags RAW_CODES|CONST_LENGTH
|
||||
eps 30
|
||||
aeps 100
|
||||
|
||||
gap 107901
|
||||
|
||||
begin raw_codes
|
||||
|
||||
name PowerOn
|
||||
9051 2199 600
|
||||
|
||||
name Optical1
|
||||
9050 2199 601
|
||||
|
||||
name aux
|
||||
9048 2200 599
|
||||
|
||||
end raw_codes
|
||||
|
||||
end remote
|
||||
@@ -0,0 +1,8 @@
|
||||
[[protocols]]
|
||||
name = "TeufelRemote"
|
||||
protocol = "nec"
|
||||
variant = "nec"
|
||||
[protocols.scancodes]
|
||||
0x10a = "PowerOn"
|
||||
0x106 = "Optical1"
|
||||
0x102 = "aux"
|
||||
@@ -0,0 +1,16 @@
|
||||
Screen Down:
|
||||
rpi-rf_send -g 27 -t 3 -p 136 83716
|
||||
Screen Up:
|
||||
rpi-rf_send -g 27 -t 3 -p 136 83713
|
||||
Screen Middle
|
||||
rpi-rf_send -g 27 -t 3 -p 136 83714
|
||||
|
||||
Relais ON
|
||||
rpi-rf_send -g 27 -t 2 958927872 -p 691
|
||||
Relais OFF
|
||||
rpi-rf_send -g 27 -t 2 891819008 -p 691
|
||||
|
||||
IR
|
||||
irsend LIST remote_led ""
|
||||
irsend LIST Teufel_devinput ""
|
||||
irsend LIST beamer_devinput ""
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
#import the GPIO and time package
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
led_pin_board=16
|
||||
led_pin_bcm="GPIO23"
|
||||
GPIO.setup(led_pin_board, GPIO.OUT)
|
||||
# loop through 50 times, on/off for 1 second
|
||||
for i in range(50):
|
||||
print("Flash")
|
||||
GPIO.output(led_pin_board,True)
|
||||
time.sleep(1)
|
||||
GPIO.output(led_pin_board,False)
|
||||
time.sleep(1)
|
||||
GPIO.cleanup()
|
||||
@@ -0,0 +1,8 @@
|
||||
[[protocols]]
|
||||
name = "led_remote"
|
||||
protocol = "nec"
|
||||
variant = "nec"
|
||||
[protocols.scancodes]
|
||||
0x40 = "PowerOn"
|
||||
0x41 = "PowerOff"
|
||||
0x58 = "Red"
|
||||
@@ -0,0 +1,199 @@
|
||||
import paho.mqtt.client as mqtt
|
||||
from rpi_rf import RFDevice
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
import time
|
||||
|
||||
MQTT_BROKER_HOST = "homeassistant"
|
||||
MQTT_BROKER_PORT = 1883
|
||||
MQTT_USERNAME = "MQTTBrokerUser"
|
||||
MQTT_PASSWORD = "mqtt1510##"
|
||||
MQTT_TOPIC = "serverhost_torrent_sensor/topic" # Set the desired topic
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S',
|
||||
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s',)
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, reason_code, properties):
|
||||
logging.info(f"Connected with result code {reason_code}")
|
||||
# Subscribing in on_connect() means that if we lose the connection and
|
||||
# reconnect then subscriptions will be renewed.
|
||||
client.subscribe("home/livingroom/raspi/screen")
|
||||
client.subscribe("home/livingroom/raspi/beamer")
|
||||
client.subscribe("home/livingroom/raspi/teufelaudio")
|
||||
|
||||
msg_info = client.publish("home/livingroom/raspi/available", "online", qos=1, retain=True)
|
||||
# Our application produce some messages
|
||||
|
||||
# The callback for when a PUBLISH message is received from the server.
|
||||
def on_message(client, userdata, msg):
|
||||
timeout=5
|
||||
if "screen down" in str(msg.payload):
|
||||
logging.info("Lowering Screen")
|
||||
logging.debug(msg.payload)
|
||||
# Lower Screen via RFdevice
|
||||
code=83716
|
||||
protocol=3
|
||||
pulselength=136
|
||||
length=None
|
||||
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||
time.sleep(0.2)
|
||||
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||
if "screen up" in str(msg.payload):
|
||||
logging.info("Raising Screen")
|
||||
logging.debug(msg.payload)
|
||||
# Lower Screen via RFdevice
|
||||
code=83713
|
||||
protocol=3
|
||||
pulselength=136
|
||||
length=None
|
||||
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||
time.sleep(0.2)
|
||||
rfdevice.tx_code(code, protocol, pulselength, length)
|
||||
|
||||
if "teufel power" in str(msg.payload):
|
||||
logging.info("Send ON/OFF to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf power"
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
if "teufel opt1" in str(msg.payload) or "teufel aux" in str(msg.payload):
|
||||
time.sleep(10)
|
||||
if "teufel opt1" in str(msg.payload):
|
||||
logging.info("Send Opt1 to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf opt1"
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
if "teufel aux" in str(msg.payload):
|
||||
logging.info("Send aux to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf aux"
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
if "teufel Mute" in str(msg.payload):
|
||||
logging.info("Send Mute to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf Mute"
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
|
||||
if "teufel VolUp" in str(msg.payload):
|
||||
logging.info("Send VolUp to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf VolUp"
|
||||
for i in range(5):
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
time.sleep(1)
|
||||
|
||||
if "teufel VolDown" in str(msg.payload):
|
||||
logging.info("Send VolDown to Teufel Audio")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once teufel_nf VolDown"
|
||||
for i in range(5):
|
||||
try:
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
except Exception as e:
|
||||
print("Command returned %s, %s"%(returned_output,e))
|
||||
returned_output = subprocess.check_output("systemctl mqttService restart", shell=True,timeout=timeout)
|
||||
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
time.sleep(1)
|
||||
|
||||
if "beamer off" in str(msg.payload):
|
||||
logging.info("Send Off to Beamer")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once beamer_optoma poweroff"
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
time.sleep(1)
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
if "beamer on" in str(msg.payload):
|
||||
logging.info("Send On to Beamer")
|
||||
logging.debug(msg.payload)
|
||||
cmd="irsend send_once beamer_optoma poweron"
|
||||
returned_output = subprocess.check_output(cmd, shell=True,timeout=timeout)
|
||||
logging.info("Ret: " + str(returned_output))
|
||||
def on_subscribe(client, userdata, mid, reason_code_list, properties):
|
||||
# Since we subscribed only for a single channel, reason_code_list contains
|
||||
# a single entry
|
||||
if reason_code_list[0].is_failure:
|
||||
logging.debug(f"Broker rejected you subscription: {reason_code_list[0]}")
|
||||
else:
|
||||
logging.info(f"Broker granted the following QoS: {reason_code_list[0].value}")
|
||||
|
||||
def on_unsubscribe(client, userdata, mid, reason_code_list, properties):
|
||||
# Be careful, the reason_code_list is only present in MQTTv5.
|
||||
# In MQTTv3 it will always be empty
|
||||
if len(reason_code_list) == 0 or not reason_code_list[0].is_failure:
|
||||
logging.debug("unsubscribe succeeded (if SUBACK is received in MQTTv3 it success)")
|
||||
else:
|
||||
logging.info(f"Broker replied with failure: {reason_code_list[0]}")
|
||||
client.disconnect()
|
||||
|
||||
## RX Init
|
||||
print("Starting")
|
||||
gpio_port_board=27
|
||||
rfdevice = RFDevice(gpio_port_board)
|
||||
rfdevice.enable_tx()
|
||||
rfdevice.tx_repeat = 10
|
||||
|
||||
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||
|
||||
mqttc.on_connect = on_connect
|
||||
mqttc.on_message = on_message
|
||||
|
||||
mqttc.on_subscribe = on_subscribe
|
||||
mqttc.on_unsubscribe = on_unsubscribe
|
||||
unacked_publish = set()
|
||||
|
||||
# Set username and password for authentication
|
||||
mqttc.username_pw_set(username=MQTT_USERNAME, password=MQTT_PASSWORD)
|
||||
|
||||
# Connect to the MQTT broker
|
||||
mqttc.connect(MQTT_BROKER_HOST, MQTT_BROKER_PORT, 60)
|
||||
|
||||
mqttc.loop_start()
|
||||
|
||||
|
||||
msg_info2 = mqttc.publish("sensor/test", "6", qos=1)
|
||||
unacked_publish.add(msg_info2.mid)
|
||||
|
||||
# Wait for all message to be published
|
||||
while len(unacked_publish):
|
||||
time.sleep(0.1)
|
||||
|
||||
# Due to race-condition described above, the following way to wait for all publish is safer
|
||||
msg_info2.wait_for_publish()
|
||||
|
||||
mqttc.disconnect()
|
||||
mqttc.loop_stop()
|
||||
|
||||
rfdevice.cleanup()
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Raspberry MQTT Service
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/home/lucas/paho-mqtt/bin/python /home/lucas/scripts/raspberry/python/mqtt_client.py
|
||||
WorkingDirectory=/home/lucas/scripts/raspberry/python/
|
||||
StandardOutput=inherit
|
||||
StandardError=inherit
|
||||
Restart=always
|
||||
User=lucas
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
|
||||
from rpi_rf import RFDevice
|
||||
|
||||
rfdevice = None
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def exithandler(signal, frame):
|
||||
rfdevice.cleanup()
|
||||
sys.exit(0)
|
||||
|
||||
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
|
||||
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
|
||||
|
||||
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
|
||||
parser.add_argument('-g', dest='gpio', type=int, default=27,
|
||||
help="GPIO pin (Default: 27)")
|
||||
args = parser.parse_args()
|
||||
|
||||
signal.signal(signal.SIGINT, exithandler)
|
||||
rfdevice = RFDevice(args.gpio)
|
||||
rfdevice.enable_rx()
|
||||
timestamp = None
|
||||
logging.info("Listening for codes on GPIO " + str(args.gpio))
|
||||
while True:
|
||||
if rfdevice.rx_code_timestamp != timestamp:
|
||||
timestamp = rfdevice.rx_code_timestamp
|
||||
logging.info(str(rfdevice.rx_code) +
|
||||
" [pulselength " + str(rfdevice.rx_pulselength) +
|
||||
", protocol " + str(rfdevice.rx_proto) + "]")
|
||||
time.sleep(0.01)
|
||||
rfdevice.cleanup()
|
||||
@@ -0,0 +1,29 @@
|
||||
from RPi import GPIO
|
||||
import time, argparse
|
||||
import numpy as np
|
||||
parser = argparse.ArgumentParser(description='Analyze RF signal for Nexa codes')
|
||||
parser.add_argument('-g', dest='gpio', type=int, default=27, help='GPIO pin (Default: 27)')
|
||||
parser.add_argument('-s', dest='secs', type=int, default=3, help='Seconds to record (Default: 3)')
|
||||
parser.add_argument('--raw', dest='raw', action='store_true', default=False, help='Output raw samples')
|
||||
parser.add_argument('-f', dest='file',default="data.npy", help='Data file (Default: data.npy)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
times = []
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(args.gpio, GPIO.IN)
|
||||
GPIO.add_event_detect(args.gpio, GPIO.BOTH,
|
||||
callback=lambda ch: times.append(time.perf_counter_ns()//1000))
|
||||
|
||||
time.sleep(args.secs)
|
||||
GPIO.remove_event_detect(args.gpio)
|
||||
GPIO.cleanup()
|
||||
|
||||
# Calculate difference between consecutive times
|
||||
diff = [b-a for a,b in zip(times, times[1:])]
|
||||
|
||||
|
||||
np.save(args.file, diff)
|
||||
if args.raw: # Print a raw dump
|
||||
for d in diff: print(d, end='\n' if d>5e3 else ' ')
|
||||
@@ -0,0 +1,84 @@
|
||||
"""
|
||||
Script Name: ir-keytable-record.py
|
||||
Purpose: Script to capture remote control key presses and generate a TOML file.
|
||||
Author: Vince Ricosti
|
||||
Url: https://raw.githubusercontent.com/vricosti/infrared-resources/main/ir-keytable-record.py
|
||||
Usage:
|
||||
Run the script with -h or --help to see usage options.
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import time
|
||||
import signal
|
||||
import argparse
|
||||
|
||||
def get_ir_keytable_output(sysdev):
|
||||
cmd = ["stdbuf", "-oL", "ir-keytable", "-s", sysdev, "-t"]
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, universal_newlines=True)
|
||||
|
||||
lines = []
|
||||
for line in iter(process.stdout.readline, ''):
|
||||
lines.append(line)
|
||||
if "lirc protocol" in line:
|
||||
break
|
||||
|
||||
process.send_signal(signal.SIGINT)
|
||||
process.communicate()
|
||||
|
||||
return ''.join(lines)
|
||||
|
||||
def extract_protocol_and_scancode(output):
|
||||
# Extract lines containing "lirc protocol"
|
||||
match = re.search(r"lirc protocol\(([^)]+)\): scancode = (0x[\da-fA-F]+)", output)
|
||||
if match:
|
||||
protocol, scancode = match.groups()
|
||||
return protocol, scancode
|
||||
return None, None
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description='Script to capture remote control key presses and generate a TOML file.')
|
||||
parser.add_argument('-s', '--sysdev', default='rc0', help='RC device to control. Defaults to rc0 if not specified.')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
sysdev = args.sysdev
|
||||
|
||||
filename = input("Please enter the file name: ").strip()
|
||||
filename_no_ext, ext = os.path.splitext(filename)
|
||||
if not ext:
|
||||
filename = f"{filename}.toml"
|
||||
|
||||
keys_dict = {}
|
||||
global_protocol = None
|
||||
|
||||
while True:
|
||||
key_name = input("Enter the key name (in upper case) or a space to stop: ").strip()
|
||||
if key_name == '':
|
||||
break
|
||||
|
||||
#print("Please press the button on your remote for key:", key_name)
|
||||
output = get_ir_keytable_output(sysdev)
|
||||
protocol, scancode = extract_protocol_and_scancode(output)
|
||||
if protocol and scancode:
|
||||
print(f'{scancode} = "{key_name}" #protocol ="{protocol}"')
|
||||
keys_dict[key_name] = scancode
|
||||
if not global_protocol:
|
||||
global_protocol = protocol
|
||||
if global_protocol == 'rc5x_20':
|
||||
global_protocol = 'rc5'
|
||||
|
||||
with open(filename, 'w') as f:
|
||||
f.write("[[protocols]]\n")
|
||||
f.write(f'name = "{filename_no_ext}"\n')
|
||||
f.write(f'protocol = "{global_protocol}"\n')
|
||||
f.write(f'variant = "{global_protocol}"\n')
|
||||
f.write("[protocols.scancodes]\n")
|
||||
for key_name, scancode in keys_dict.items():
|
||||
f.write(f'{scancode} = "{key_name}"\n')
|
||||
|
||||
print(f"File '{filename}' has been written.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,22 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
# for GPIO numbering, choose BCM
|
||||
#GPIO.setmode(GPIO.BCM)
|
||||
|
||||
# or, for pin numbering, choose BOARD
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
|
||||
GPIO.setmode(GPIO.BOARD) # sets numbering system of GPIO pins
|
||||
channel1 = 15 # Replace MY_BOARD_PIN_ID with your actual pin number
|
||||
channel2 = 16 # Replace MY_BOARD_PIN_ID with your actual pin number
|
||||
|
||||
GPIO.setup(channel1, GPIO.IN) # set the GPIO pin as an input
|
||||
GPIO.setup(channel2, GPIO.IN) # set the GPIO pin as an input
|
||||
|
||||
# then some code where you read the input as many times as needed:
|
||||
while(True):
|
||||
value1 = GPIO.input(channel1)
|
||||
value2 = GPIO.input(channel2)
|
||||
print("1:%d\n"%value1)
|
||||
print("2:%d\n"%value2)
|
||||
time.sleep(0.5)
|
||||
Reference in new issue
Block a user