User Tools

Site Tools


music

Playing music in the space

G1

G1 has a Raspberry Pi hidden behind the Amp in the corner, with a USB DAC.

code for projector switchy on or off:

volumio@amppi:~$ cat serial-server.py 
#!/usr/bin/python3
import json
import paho.mqtt.client as mqtt
import logging
import serial
import subprocess
import os
logging.basicConfig(level=logging.DEBUG)
def on_connect(client, userdata, flags, rc):
    client.ser = serial.Serial("/dev/ttyUSB0")
       
    print("connected with result" + str(rc))
    client.subscribe("display/g1/projector/#")
def on_message(client, userdata, msg):
    lastmsg = str(msg.payload.decode("utf-8"))
    logging.debug(lastmsg)
    if msg.topic == "display/g1/projector/on":
        client.ser.write(b"~0000 1\r")
    if msg.topic == "display/g1/projector/off":
        client.ser.write(b"~0000 0\r")
    if msg.topic == "display/g1/projector/channel":
        if lastmsg == "hdmi":
            logging.debug("hdmi chosen")
            client.ser.write(b"~00140 22\r")
        if lastmsg == "vga":
            logging.debug("vga chosen")
            client.ser.write(b"~00140 26\r")
        if lastmsg == "svideo":
            logging.debug("svideo chosen")
            client.ser.write(b"~00140 25\r")
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("mqtt.hacklab")
client.loop_forever()
music.txt · Last modified: 2020-01-28 17:28 by alfie

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki