No edit summary |
mNo edit summary |
||
Line 12: | Line 12: | ||
We have a script running on [[SlabPi]] that plays entrance theme audio when a member enters the space. | 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 | It checks if a member is entering on [[MQTT]], it pauses MPD, plays a song from the folder "themes" that was mounted from [[Egg]] with mpg123 and resumes MPD. | ||
It needs paho installed. More info about installing paho here: [[Shutdown Script]] | It needs paho installed. More info about installing paho here: [[Shutdown Script]] | ||
Revision as of 18:01, 2 May 2019
Entrance themes | |
---|---|
Participants | Dennis |
Skills | Programming |
Status | Finished |
Niche | |
Purpose | Fun |
Tool | No |
Location | SlabPi |
Cost | |
Tool category |
WWEEntrance.jpg {{#if:No | [[Tool Owner::{{{ProjectParticipants}}} | }} {{#if:No | [[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 MPD, plays a song from the folder "themes" that was mounted from Egg with mpg123 and resumes MPD. 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 (floats allowed), default: None mclient.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None mclient.connect("slabpi.dhcp.nurd.space", 6600) # connect to localhost:6600 print(mclient.mpd_version) # print the MPD version mclient.pause(1) os.system('mpg123 /mnt/mp3/themes/' + parsed_json["name"] + '.mp3') 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()
Todo
- Debug. Script was running but theme songs did not work anymore. It is possible that MQTT got disconnected, but we do not have logging yet, so it could be something else :p
- Check if mpd is playing.
- Check mpd volume, adjust the themesong to same volume.