Thank you for your donation!


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


Solved: HTTP API Commands for USB Numpad Controller - Need Help with Station Loading
#1
Hi All,
 
TLDR:
I've got a Targus USB numpad and want to program the buttons for specific shortcuts - eg: 0-9 internet radio stations, enter = play/pause etc etc. My aim is to have this in the kitchen with one press of the keyboard to start and stop and choose stations (see screenshot below). I have a python script running which can see the number pad and I can stop playback with a key press, but that's it for now so I'm trying to get the other functions to work. 

## What I'm Trying to Achieve
I have a Raspberry Pi 4 running moOde with a Targus USB numpad, and I want to:
- Press numpad keys 1-9 to play specific radio stations
- Use +/- for next/previous track
- Use Enter for play/pause
- Use other keys for stop, mute, etc.


 The `mpc` commands work, but equivalent `curl` HTTP API calls don't work. Need help with the correct API syntax for loading radio stations.

Radio stations play perfectly from web interface - I can click on any station and it plays immediately

## The Problem 
I cannot load radio stations using HTTP API commands. I've tried many variations, but none work (so far):

# All of these fail with various errors:
curl "http://localhost/command/?cmd=add&parm=17"
curl "http://localhost/command/?cmd=add&parm=BBC%20Radio%201%20(320K)"
curl "http://localhost/command/?cmd=load&parm=17"
curl "http://localhost/radio?ch=17"
curl -X POST "http://localhost/queue.php?cmd=play_item&parm=BBC%20Radio%201%20(320K)"

## My Setup Details
moOde Version:** Latest (Pi shows moOde is running correctly)
Hardware:** Raspberry Pi 4, Targus USB numpad, external amp (no volume control needed)
Radio Stations:** I have BBC Radio 1, 2, 3, 4, 6 Music, Resonance FM, etc. set up as favourites in moOde
Current Playing:** Resonance 104.4FM plays fine, shows in `mpc status`

## What I've Discovered
1. **Radio stations are in the database:**
   ```sql
   SELECT id, name FROM cfg_radio WHERE type='r' ORDER BY id;
   ```
   Shows stations like: 17|BBC Radio 1, 19|BBC Radio 2, etc.

2. **Playlist files exist:**
   ```bash
   find /var/lib/mpd/music -name "*BBC*" -type f
   ```
   Shows files like `/var/lib/mpd/music/RADIO/BBC Radio 1 (320K).pls`

3. **When web interface loads a station, mpc playlist shows:**
   ```
   BBC Radio 1 (320K)
   BBC Radio 4 FM (320K)  
   BBC Radio 6 music (320K)
   ```

4. **Browser network inspector shows web interface uses:**
   - `queue.php?cmd=get_playqueue` (GET)
   - Various POST requests to queue management

## Questions for the Community
1. **What is the correct HTTP API syntax to load a radio station?** I can see stations with database ID 17 (BBC Radio 1), but how do I load it via curl?

2. **Should I be using station database IDs, station names, or .pls file paths?** I've tried all three approaches.

3. **Is there a different API endpoint for radio stations vs. music files?** The `/command/?cmd=add` seems to fail specifically for radio stations.

4. **Are there any moOde-specific commands for radio station loading?** I see the web interface uses queue.php but I don't think this is documented - apologies if i've missed it.

## What I've Tried
- Multiple variations of `/command/?cmd=add` with different parameters
- Station database IDs (17, 19, 21, etc.)
- URL-encoded station names ("BBC%20Radio%201%20(320K)")
- File paths ("RADIO/BBC%20Radio%201%20(320K).pls")
- Different API endpoints (/radio?ch=X, /queue.php, etc.)
- POST vs GET requests

## Code Context
I'm using Python with evdev to detect numpad keypresses and requests library to send HTTP commands to moOde.

Any help with the correct API syntax would be greatly appreciated! The goal is to have a simple numpad where pressing "1" loads BBC Radio 1, "2" loads BBC Radio 2, etc. See screenshot below.

Thanks in advance for any guidance and sorry for the long post!

   
Reply
#2
The REST API is documented in the Setup Guide (I just added the syntax for HTTP and CURL)
https://github.com/moode-player/docs/blo...1-rest-api

CURL syntax is:
Code:
curl -G -S -s --data-urlencode "cmd=REST_API_COMMAND" http://moode/command/

Example for playing a Radio Station on host "trx"
Code:
# Command
curl -G -S -s --data-urlencode "cmd=play_item RADIO/Soma FM - Fluid.pls" http://trx/command/

# Returns
{"info":"OK"}
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
(06-11-2025, 10:30 AM)Tim Curtis Wrote: The REST API is documented in the Setup Guide (I just added the syntax for HTTP and CURL)
https://github.com/moode-player/docs/blo...1-rest-api

CURL syntax is:
Code:
curl -G -S -s --data-urlencode "cmd=REST_API_COMMAND" http://moode/command/

Example for playing a Radio Station on host "trx"
Code:
# Command
curl -G -S -s --data-urlencode "cmd=play_item RADIO/Soma FM - Fluid.pls" http://trx/command/

# Returns
{"info":"OK"}

Thank you very much for your help, this has really got me closer to a solution. If anyone else is looking at doing this in the future, be aware that the Targus number pad should be avoided due to it's non-standard HID implementation (it's just a generic controller). I will try with a different one hopefully with better USB HID implementation and report back. Thanks again Tim
Reply
#4
@numpad
I've got a gpio 8 button / rotary encoder setup that makes python called to mpc playlist, may give you ideas.  On my wishlist is code to long presses to double the number of radio station presets ie 8 --> 16, but what I've tried so far isn't reliable. 

https://github.com/lakeuk/moode-audio-extensions
Reply
#5
(06-15-2025, 02:08 PM)lakeuk Wrote: @numpad
I've got a gpio 8 button / rotary encoder setup that makes python called to mpc playlist, may give you ideas.  On my wishlist is code to long presses to double the number of radio station presets ie 8 --> 16, but what I've tried so far isn't reliable. 

https://github.com/lakeuk/moode-audio-extensions

Hi @lakeuk

Thanks for your message, your progress looks good and I think an epaper display would be nice for my project Smile

I've made good progress with my project and by utilising a Kensington Numpad which adheres to the standard USB-HID commands (which the targus did not) and have got all the station presents and functions working, mute, vol up and down. The only one I can't get working yet is safe-shutdown, but you seemed to have solved that! Hopefully I can get it to work too, i'm encountering permission issues with the commands, 

I will tidy my code and publish on GitHub and post a link here, 

Edit - here's a link: https://github.com/mlake1/moode-numpad-controller

Very much work in progress!

Cheers,
Reply


Forum Jump: