Entrance themes

From NURDspace
Revision as of 18:35, 24 March 2019 by Invict (talk | contribs)
Entrance themes
WWEEntrance.jpg
Participants Dennis
Skills Programming
Status Finished
Niche
Purpose Fun
Tool
Location SlabPi
Cost
Tool category

Entrance themes

WWEEntrance.jpg {{#if:{{{Tool}}} | [[Tool Owner::{{{ProjectParticipants}}} | }} {{#if:{{{Tool}}} | [[Tool Cost::{{{Cost}}} | }}

What

We have a script running on SlabPi that plays entrance theme audio when a member enters the space.

It checks if a member is entering on MQTT ,it pauses MPC, plays a song from the folder "themes" that was mounted from Egg with mpg123 and resumes MPC. It needs paho installed. More info about installing paho here: Shutdown Script


The script


#!/usr/bin/env python
#Invict & Niz 2019
import time
import paho.mqtt.client as paho
import json
import os
from mpd import MPDClient
broker="arbiter.vm.nurd.space"
#define callback
def on_message(client, userdata, message):
    parsed_json = json.loads(message.payload.decode("utf-8"))
    print("received message =",str(message.payload.decode("utf-8")))
    print(parsed_json['name'])
    mclient = MPDClient()               # create client object
    mclient.timeout = 10                # network timeout in seconds$
    mclient.idletimeout = None          # timeout for fetching the r$
    mclient.connect("slabpi.dhcp.nurd.space", 6600)  # connect to lo$
    print(mclient.mpd_version)          # print the MPD version
    mclient.pause(1)
    os.system('mpg123 /mnt/mp3/themes/' + parsed_json["name"] + '.mp$
    mclient.pause(0)
    mclient.disconnect()

client= paho.Client("themesong")
######Bind function to callback
client.on_message=on_message
#####
print("connecting to broker ",broker)
client.connect(broker)#connect
print("subscribing ")
client.subscribe("space/door/front")#subscribe
client.loop_forever()