Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


MPD command missing ?
#1
Hi everybody

I'm trying to command my Moode Audio RPI with URL requests sent by a an Arduino DIY automation system, which uses Ethernet as HTTP client and HTTP server on port 80.
It can also use DNS to resolve names and contact a server or a website.

This is the MPD reference : https://www.musicpd.org/doc/html/protoco...aylistinfo

With Moode audio, this commands work fine:

http://moode/command/?cmd=next
http://moode/command/?cmd=previous
http://moode/command/?cmd=pause
http://moode/command/?cmd=play
http://moode/command/?cmd=stop
http://moode/command/?cmd=vol.sh%2085  // set volume to 85% - mind '%20' is 'space' char
http://moode/command/?cmd=play%2021     // play song n°22 in the queue ; mind that song n°1 is '0' not '1'


But other commands do not work at all:

http://moode/command/?cmd=playlistinfo
http://moode/command/?cmd=currentsong
...

I want to do a "full command line" if possible.


And if possible, I want to "navigate" in MP3 directory :
- get list of files in current dir
- get list of dir in current dir
- go inside dir
- go back to parent dir
- add files to queue
- clear queue
 
Also my Arduino system can use other port than 80 to connect to a server. 
But Arduino do not have enough power, ROM and RAM to handle complex secure connexions (like HTTPS or SSH)

Best regards.
Reply
#2
@electroremy

As stated in the setup.txt file,

Code:
////////////////////////////////////////////////////////
//
// Command API
//
// Below are a list of commands that can be submitted to
// moOde via http or ssh
//
////////////////////////////////////////////////////////

1. Base URL is http://moode/command/?cmd=
2. MPD commands that are listed in MPC help
3. Volume commands that are listed in /var/www/vol.sh --help
4. Library update via the command libupd-submit

Note well that MPD commands available via MPC (try "mpc help") are not the exactly same as the commands in the MPD Protocol (the documentation you reference). For example, there is no playlistinfo available.


You cited the MPD protocol section, so did you read the first sentence in it?

Quote:The MPD command protocol exchanges line-based text records between client and server over TCP. 

If you telnet to port 6600 you'll see how the protocol works. Just type a command and look at the response.

Regards,
Kent
Reply
#3
Hi,

Thank you ; so I have to use MPC commands as listed here : https://linux.die.net/man/1/mpc

And what about "bluetooth connection" ?

As I can connect a smartphone with bluetooth to play podcasts, Moode Audio will be "locked" - it's a logic behavoir

But if I send MPC command while Moode is already connected to bluetooth, what's appends ? Can I crash Moode Audio ?

Is it possible to get Moode Audio "state" ?

Regards,
Reply
#4
(03-07-2021, 02:13 PM)electroremy Wrote: Hi,

Thank you ; so I have to use MPC commands as listed here : https://linux.die.net/man/1/mpc

And what about "bluetooth connection" ?

As I can connect a smartphone with bluetooth to play podcasts, Moode Audio will be "locked" - it's a logic behavoir

But if I send MPC command while Moode is already connected to bluetooth, what's appends ? Can I crash Moode Audio ?

Is it possible to get Moode Audio "state" ?

Regards,

Since the versions of MPD and MPC used in moOde evolve over time, I suggest you ask the code directly what commands it accepts.


Code:
pi@moode:~ $ mpc help
Usage: mpc [options] <command> [<arguments>]
mpc version: 0.33

Options:
 -v, --verbose                  Give verbose output
 -q, --quiet                    Suppress status message
 --no-status                    synonym for --quiet
 -h, --host=<host>              Connect to server on <host>
 -P, --password=<password>      Connect to server using password <password>
 -p, --port=<port>              Connect to server port <port>
 -f, --format=<format>          Print status with format <format>
 -w, --wait                     Wait for operation to finish (e.g. database update)
 -r, --range=[<start>]:[<end>]  Operate on a range (e.g. when loading a playlist)

Commands:
 mpc                                                   Display status
 mpc add <uri>                                         Add a song to the queue
 mpc crop                                              Remove all but the currently playing song
 mpc current                                           Show the currently playing song
 mpc del <position>                                    Remove a song from the queue
 mpc play [<position>]                                 Start playing at <position>
 mpc next                                              Play the next song in the queue
...goes on for a total of 60+ commands...

MPC is a companion to MPD. Using moOde as a Bluetooth speaker bypasses MPD. If you make changes to the MPD status you won't see the effect until you stop using the Bluetooth connection.

Regards,
Kent
Reply
#5
@electroremy

Yes mpc is a command-line mpd client, the mpd binary is the daemon not the client.
Yes you can stream to bluetooth from your phone.

Moode is a Linux distribution that ships multiple audio playback/renderer programs with a custom web interface to browse, configure & control it all.
The programs that output audio on Moode such as mpd, bluez-alsa, librespot, upmpdcli etc. all output directly to the configured ALSA device driver which can take a single input at a time.

Moode's web UI blanks out the screen when the sound device is in use by something other than mpd to inform the user and prevent ugly errors.
If you try to play music in one program whilst another is using the ALSA device it will just fail until the ALSA device is not in use.
Reply
#6
Hi

I use telnet with some usefull commands :

Code:
telnet
open moode 6600
setvol x // set volume to x% 0 to 100
next
previous
stop
pause 
play
play x // play song with 'x' ID
currentsong // get info and also ID
playlistid x // get info about 'x' ID song

Note that commands are those listed in MPD doc not MPC, they are sometimes not the same that works with http://moode/command/?cmd=xxx
currentsong return name and also the ID
So, I can make several calls of 'playlistid x' with x = currentsong ID - 5 to currentsong ID + 5 to display a part of current playlist on a LCD screen
Indeed, ask Moode to give all playlist song give too much data, I have to get info song by song.
This allow me basic control of Moode audio, like a remote for Hifi CD player  Smile
But to change queue and load other songs or playlists, I have to go back to computer or smartphone interface.  Tongue
I find there are some function that use 'URI' (as listfiles {URI}) but I don't know how to write correct URI for files located in USB stick
Regards,
Reply
#7
@electroremy

Here's what the docs say about listfiles

Quote:Lists the contents of the directory URI, including files are not recognized by MPD. URI can be a path relative to the music directory or an URI understood by one of the storage plugins. The response contains at least one line for each directory entry with the prefix “file: ” or “directory: “, and may be followed by file attributes such as “Last-Modified” and “size”.

So, now the question is "what is the music directory?" In moOde's case, it is /var/lib/mpd/music. Here's what's in mine:

Code:
pi@moode:/var/lib/mpd/music $ ls
NAS  RADIO  SDCARD  UPNPminim  USB


Using the MPD protocol I can ask for a listing of a particular subdirectory on the particular USB thumbdrive which is plugged into this player:

Code:
telnet moode.local 6600
Trying 192.168.4.26...
Connected to moode.local.
Escape character is '^]'.
OK MPD 0.22.4
listfiles USB/MUSIC/JAZZ
directory: Bob Schwartz Quartet-Look for the Silver Lining
Last-Modified: 2019-08-21T21:09:30Z
directory: Bob Schwartz Quartet-Taint whatcha do
Last-Modified: 2019-08-21T21:09:54Z
directory: Miles Davis & Quincy Jones-Miles & Quincy Live at Montreux
Last-Modified: 2019-08-22T16:48:06Z
directory: Greg Harrison Jazz Band - Volume 2
Last-Modified: 2019-05-04T11:42:46Z
directory: Larry Coryell-The Eleventh House
Last-Modified: 2019-08-31T21:59:20Z
file: temp.tar
size: 353597440
Last-Modified: 2020-08-13T21:22:58Z
OK

Regards,
Kent
Reply
#8
Hi

I'm confused about the "curentsong" and "playlistid x" commands

Indeed, Moode Audio MPC telnet first send a "OK MPD 0.22.0" response.

I have to wait for the next data packet that contains the song info.

Moode Audio MPC telnet interface is very fast and responsive with commands that sends no data or just "OK"  Smile 
...but there is a delay between the 2nd data  Sad

Thus, to get 11 songs names, it takes 3 to 5 seconds...

There is a way to avoid this and force MPD to send all data in the first packet (in config files or elsewhere) ? 

This is the code to received data after sending a command :

Code:
    int len;
    int i;
    byte k;
    char c;
    Buffer_TMP_Stop = 0;
    unsigned long t = millis();
    for (k=0;k<2;k++) {
        len=0;
        t = millis();
        while(len==0){ 
            len = client2.available();
            if (millis()-t > 1000) break; 
        }
        if (len>0) {
            if (k==0) {
                for (i=0;i<len;i++) {
                    client2.read(); // We don't need the first packet data
                }
            } else {
                if (len>Buffer_TMP_Len) len = Buffer_TMP_Len;
                for (i=0;i<len;i++) {
                    Buffer_TMP[i]=client2.read(); // The data we expect is sending in a second time
                }
                Buffer_TMP_Stop = len;
            }
        } else {
            break;
        }
    }
    client2.stop();

Regards
Reply


Forum Jump: