Entrance themes

From NURDspace

Jump to: navigation, search
Entrance themes
WWEEntrance.jpg
Participants Dennis, Invict
Skills Programming
Status Finished
Niche
Purpose Fun
Tool No
Location SlabPi
Cost
Tool category

Entrance themes

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 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 (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
 
Our site is hosted by Site4U
Site4U
Part of our connectivity is made available by BIT
To BIT's joboffers