User Tools

Site Tools


music

This is an old revision of the document!


Playing music in the space

G1

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.1580232112.txt.gz · Last modified: 2020-01-28 17:21 by alfie