# Getting event from MusicBox (Rapesberry pi)

**URL:** <https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612>\
**Category:** Pi MusicBox (archive)\
**Created:** [May 5, 2017, 9:12am UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612 "2017-05-05T09:12:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucio\_Santinelli](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/lucio_santinelli/32/586_2.png) [@Lucio\_Santinelli](https://discourse.mopidy.com/u/Lucio_Santinelli)\
**Post date:** [May 5, 2017, 9:12am UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/1 "2017-05-05T09:12:15Z")

</div>

Hi,  
i’m trying to write a simple script in python to catch the events from the MusicBox in a Rapesberry pi zero (like track\_playback\_started and so on).  
As far as i know i need to implement an Actor for monitoring Mopidy.Core.Corelistener events. But I’m failing.  
Anyone achieved that?  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ismailof](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/ismailof/32/750_2.png) [@ismailof](https://discourse.mopidy.com/u/ismailof)\
**Post date:** [May 5, 2017, 1:11pm UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/2 "2017-05-05T13:11:07Z")

</div>

Hi! You can try to use [https://github.com/ismailof/mopidy-json-client](https://github.com/ismailof/mopidy-json-client), which uses the websocket interface, and can be used to catch the mopidy events from a different script/process than mopidy itself (which I think is what you want to achieve)

There is barely no documentation (my apologies), but you can ask if you find any trouble.

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [May 5, 2017, 1:39pm UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/3 "2017-05-05T13:39:54Z")

</div>

Or use the [python-mpd2](http://pythonhosted.org/python-mpd2/topics/getting-started.html) library. Something like:

```auto
from mpd import MPDClient
from select import select

client = MPDClient()
client.connect("localhost", 6600)
client.send_idle('player')
while True:
    if select([client], [], [], 0)[0]:
        client.fetch_idle()
        client.currentsong()
        client.send_idle('player')

```

---

<div class="post-metadata">

**Author:** ![Lucio\_Santinelli](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/lucio_santinelli/32/586_2.png) [@Lucio\_Santinelli](https://discourse.mopidy.com/u/Lucio_Santinelli)\
**Post date:** [May 5, 2017, 3:15pm UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/5 "2017-05-05T15:15:13Z")

</div>

Hi,  
i tried your solution but i’m not sure to understand it 100%  
How can i print in the shell the current song name?  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![Lucio\_Santinelli](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/lucio_santinelli/32/586_2.png) [@Lucio\_Santinelli](https://discourse.mopidy.com/u/Lucio_Santinelli)\
**Post date:** [May 5, 2017, 3:18pm UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/6 "2017-05-05T15:18:09Z")

</div>

I saw your solution, but unfortunately i couldn’t understand how to start the listener for events (I’m new to python language) since there’s no start method (as i espected).  
Can you help me to build a very simple Listener for any events?  
Thank a lot

---

<div class="post-metadata">

**Author:** ![ismailof](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/ismailof/32/750_2.png) [@ismailof](https://discourse.mopidy.com/u/ismailof)\
**Post date:** [May 5, 2017, 5:38pm UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/7 "2017-05-05T17:38:54Z")

</div>

The easiest way, I think, is using the `bind_event` method, where you provide the event name and the callback function for that event.

I was going to provide some example lines here, but since I wanted to try it first, I finally made a full example script. Please check: [https://github.com/ismailof/mopidy-json-client/blob/master/examples/now\_playing.py](https://github.com/ismailof/mopidy-json-client/blob/master/examples/now_playing.py)

Unluckily, there is no event loop in the code to make the program await only for events. It seems like a good addition, and I will look on how to implement it. By now, in my scripts I am using an infinite loop which can be stopped with ‘Ctrl-C’ (I know it’s ugly)

---

<div class="post-metadata">

**Author:** ![Lucio\_Santinelli](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/lucio_santinelli/32/586_2.png) [@Lucio\_Santinelli](https://discourse.mopidy.com/u/Lucio_Santinelli)\
**Post date:** [May 8, 2017, 9:33am UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/8 "2017-05-08T09:33:19Z")

</div>

That’s exactly what i was looking for.  
I tested all up on my raspberry p zero and worked like a charm!  
Thank so much 🙂

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [February 19, 2026, 11:47am UTC](https://discourse.mopidy.com/t/getting-event-from-musicbox-rapesberry-pi/1612/9 "2026-02-19T11:47:19Z")

</div>


