Thank you for your donation!


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


Remote access to moode via web-api
#1
Hi,

I'm building a remote 'control' for Moode. That is, since my amp is inside closed furniture I want to be able to adjust the volume without having to reach for my phone, tablet or other device with a browser. Just a small enclosure near the couch with a knob to adjust the volume. I've build a prototype around an esp8266 with a rotary encoder. This will send html commands to moode.local according to this post: http://moodeaudio.org/forum/showthread.p...87#pid2487
It's not perfect yet, but it works. However, in the above post other commands are given, like 'currentsong' and 'status'. I cannot get those to work. When I'm logged in via ssh and
type:

Code:
curl http://localhost/command/?cmd=status

nothing happens. If I try the same with the 'play' or 'pause' commands moode reacts as expected.
I need that data because I would like to put a little display on the device showing at least the current volume, if playing or in pause and maybe also the current song. 
I've searched for MPD web-api, but so far nothing useful has come up. 
By the way, I'm using the latest Moode (5.01 I believe) on a Pi 3B+. 

Update (even before I posted!):
In my office I'm running an older version of Moode (version 4 Beta 12 for some reason). This appears to respond quite differently. Here the 'status' and 'currentsong' work as mentioned in the above post. 'vol.sh --help' gives me a full page of options, none of which appear to have anything to do with MPD. Setting the volume with curl... (in the terminal with ssh) works, as long as I replace all spaces with '%20'. However, just cmd=vol.sh which should return the current volume does nothing... (This works fine on my 5.01 setup btw)
Reply
#2
Uncomment the bolded line below in file /var/www/command/index.php

sendMpdCmd($sock, $_GET['cmd']);
$result = readMpdResp($sock);
closeMpdSock($sock);
//echo $result;
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
@arjena

Clever use of an esp8266. I'd been thinking about using an RPi0w for similar purpose---bulkier, more resource-dependent, but also containing a cpu rather than a microcontroller. Just because it could run a full-up moOde browser doesn't mean I have to provision it that wayWink

The eps8266 has SPI and I2C interfaces. Are you by any chance including a local LCD/OLED display as well as volume control?

Regards,
Kent
Reply
#4
@Tim: That's it, thanks. Now I get the expected echo. I see now other commands from the REST-API also seem to work. Great! 

@Kent: Thank you. A Pi seems a bit overkill for this purpose. Plus I'm better in programming microcontrollers than Pi's  Wink
I'm not there yet though, sending a new http request at every click of the encoder is not very practical. The http requests interferes with the rotary encoder code so it sometimes goes up when it should go down. So I'll have to find a way to 'buffer' the steps and send the total to Moode during idle time. Hence the desire to add a small (oled, 128x64px) display to get some feedback about what's happening. And because I love eye-candy of course. It's connected i2c to the esp. 
When the code is to my liking I will report back, hopefully with pictures. But this came up in between other projects so it might take a while.
Reply
#5
So it's nearly done. I went a bit overboard, adding a menu to choose WiFi network, language and even the possibility to use it on another player.
One thing I cannot seem to solve though is the fact that when in Airplay or Spotify mode, I have no control over the player whatsoever. This makes the remote less versatile as it could be. Is there any way to control the players volume when in Airplay (or Spotify) mode?

Cheers,

A
Reply
#6
The renderers including Bluetooth, Airplay, Spotify and Squeezelite receive volume commands from their respective clients. moOde's volume control knob sets volume for MPD and if the audio device has a Hardware volume controller then Hardware volume is also set.

I'm not sure I understand your usage scenario. When you use Airplay or Spotify what is the volume set to on the client player i.e., iTunes or Spotify app?
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#7
Hi Tim,

For the usage scenario see my first post. I have no physical access to either my amp or the pi running moOde. It's all tucked away in a closet. Now suppose the phone rings while playing (loud) music. You'll want to turn down the volume quickly. The remote for the amp is always somewhere between the cushions of the couch and the phone you used to start the music (through the web interface) is now at your ear because you answered the call. Opening the web interface before answering the call is not an option, that would take too long. Hence my new device. It's sitting next to my couch, I can press a button so the volume is turned down by 50%, make the call and turn it up after my call. Proven very handy already, even though it is not finished yet.
But this only works for music played directly from moOde. When using the Spotify or Airplay renderers I'm still in the same paradox, being that the volume is controlled by the very device I'm holding to my ear (Airplay stops the music when a call comes in, Spotify happily ignores that). Or even worse, by another device that might not even be in the room (two daughters and a wife).
So, that is why it would be very practical to be able to control moOde's volume even when the source is 'remote' like Airplay or Spotify. If that is not possible I'll have to accept that. In my new amp (ready sometime before 2048) the volume will be controlled by WiFi anyway, so that will solve the whole problem, but for now I'm stuck...
Reply
#8
By the way, concerning other people in the same household, I just had the situation where my daughter started a Spotify 'session' and went upstairs after ten minutes. I wanted to change the music but was greeted with the 'Spotify Active' screen and thus locked out of moOde. So I had to go upstairs, ask her to log out so I can log in again. I believe there should be a more elegant way to return control...
Reply
#9
@arjena

I see your problem. You're trying to mute the music instead of the real world Tongue

Tim, could a script to call an ALSA amixer do the trick? The sticky bit is getting the script to find which soundcard is in use. Being able to "undo" from whatever control device is at hand is another. I don't know how this affects "bit perfect" performance.

Regards,
Kent
Reply
#10
(05-20-2019, 11:58 AM)TheOldPresbyope Wrote: @arjena

I see your problem. You're trying to mute the music instead of the real world Tongue

Tim, could a script to call an ALSA amixer do the trick? The sticky bit is getting the script to find which soundcard is in use. Being able to "undo" from whatever control device is at hand is another. I don't know how this affects "bit perfect" performance.

Regards,
Kent

The OP's usage scenario has a coupe of parts including (1) moOde functions as a preamp with a master volume control when a renderer is active (2) that renderer sessions can be terminated directly from the Renderer Active Screen and (3) that preamp volume control is accessible from Web API.

Its doable but a substantial amount of work and so unless there are a lot more requests for something like this its not going to get any priority on the TODO list.

There is probably some type of script that could be written that would control ALSA hardware volume and provide something similar to a preamp volume control. The script /var/local/www/spspre.sh has code that shows how to set ALSA volume.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Forum Jump: