adafruit / pi_video_looper

Application to turn your Raspberry Pi into a dedicated looping video playback device, good for art installations, information displays, or just playing cat videos all day.
GNU General Public License v2.0
443 stars 240 forks source link

esp8266/esp32 'remote control' #218

Open Paulie420 opened 4 months ago

Paulie420 commented 4 months ago

I've been working on Python code for awhile that is similar to this project. (Kinda wish I knew that a year ago!)

My use case isn't for events - it's for breathing new life into vintage televisions. That being said, I want to refurbish vintage remote controllers to control the video_looper.

I'm currently using an esp8266 and MQTT, however I thought about IR and RF too. I'd really like your opinion on how you would send data from an esp8266 to the Pi, and if you would be interested in adding this feature set into pi_video_looper. If not, I'd appreciate your input as I'm not certain MQTT (over WiFi) is the best choice for the broadest audience.

If this isn't a fit for a feature of pi_video_looper, I'll fork and add it myself - my code set literally contains many parts of yours, and pi_video_looper has now helped me immensely by showing the error of my ways in my project - thanks Tony!

pelicanmedia commented 3 months ago

I have only dabbled with MQTT (following instructions) on small personal projects for home automation. But I have been tinkering with using it for work purposes too.

ie installing Mosquitto Broker on the Pi (or another Pi) and having a Python script on the video_looper Pi monitor the topic and change the state of the GPIO depending on the payload. Then configure video_looper to action when those GPIO pins are triggered.

Just something (A)I quickly knocked up for a single GPIO pin:

import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO

# MQTT settings
MQTT_BROKER = "localhost" # Or alternative MQTT Broker IP address
MQTT_PORT = 1883
MQTT_TOPIC = "gpio/control"

# GPIO settings
GPIO_PIN = 18 # Example GPIO pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PIN, GPIO.OUT)

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe(MQTT_TOPIC)

def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    if msg.payload.decode() == "ON":
        GPIO.output(GPIO_PIN, GPIO.HIGH)
    elif msg.payload.decode() == "OFF":
        GPIO.output(GPIO_PIN, GPIO.LOW)

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.loop_forever()