06-11-2025, 09:39 AM
(This post was last modified: 06-12-2025, 10:08 AM by Tim Curtis.
Edit Reason: mark solved
)
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!
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!