Entrance themes: Difference between revisions

From NURDspace
No edit summary
No edit summary
Line 18: Line 18:


<pre><nowiki>
<pre><nowiki>
#!/usr/bin/env python
#!/usr/bin/env python
#Invict & Niz 2019
#Invict & Niz 2019
Line 33: Line 32:
     print(parsed_json['name'])
     print(parsed_json['name'])
     mclient = MPDClient()              # create client object
     mclient = MPDClient()              # create client object
     mclient.timeout = 10                # network timeout in seconds$
     mclient.timeout = 10                # network timeout in seconds (floats allowed), default: None
     mclient.idletimeout = None          # timeout for fetching the r$
     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 lo$
     mclient.connect("slabpi.dhcp.nurd.space", 6600)  # connect to localhost:6600
     print(mclient.mpd_version)          # print the MPD version
     print(mclient.mpd_version)          # print the MPD version
     mclient.pause(1)
     mclient.pause(1)
     os.system('mpg123 /mnt/mp3/themes/' + parsed_json["name"] + '.mp$
     os.system('mpg123 /mnt/mp3/themes/' + parsed_json["name"] + '.mp3')
     mclient.pause(0)
     mclient.pause(0)
     mclient.disconnect()
     mclient.disconnect()
Line 51: Line 50:
client.subscribe("space/door/front")#subscribe
client.subscribe("space/door/front")#subscribe
client.loop_forever()
client.loop_forever()
</nowiki></pre>
</nowiki></pre>

Revision as of 18:47, 24 March 2019

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 (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()