From dfad96df7b0debb7eaaeedcfc88ca6b2a4c925f4 Mon Sep 17 00:00:00 2001 From: Scott Simon Date: Wed, 1 Jul 2026 10:56:07 -0500 Subject: [PATCH] Add queue_next MQTT remote command to enqueue a track by persistent ID Sends ctrl-int/1/cue?command=add&query='dmap.persistentid:0x'&mode=3 to the DACP source, where is the hex track_id string taken directly from the MQTT payload after "queue_next ". Co-Authored-By: Claude Sonnet 5 --- mqtt.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mqtt.c b/mqtt.c index 3acb8865..b0753f58 100644 --- a/mqtt.c +++ b/mqtt.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -70,7 +71,8 @@ void on_message(__attribute__((unused)) struct mosquitto *mosq, char *commands[] = {"command", "beginff", "beginrew", "mutetoggle", "nextitem", "previtem", "pause", "playpause", "play", "stop", "playresume", "shuffle_songs", - "volumedown", "volumeup", "disconnect", NULL}; + "volumedown", "volumeup", "disconnect", "queue_next", + NULL}; int it = 0; @@ -81,7 +83,26 @@ void on_message(__attribute__((unused)) struct mosquitto *mosq, debug(2, "[MQTT]: Received Recognized Command: %s\n", commands[it]); if (strcmp(commands[it], "disconnect") == 0) { debug(2, "[MQTT]: Disconnect Command: %s\n", commands[it]); - stop_play(); // stop any current session and don't replace it + release_play_lock(NULL); // stop any current session and don't replace it + } else if (strcmp(commands[it], "queue_next") == 0) { + // payload is "queue_next ", where is the hex track_id + // string as published by shairport-sync itself (see the "mper"/"track_id" handling + // above), e.g. "queue_next 1A2B3C4D5E6F7" + char *track_id = payload + strlen(commands[it]); + while (*track_id == ' ' || *track_id == '\t') + track_id++; + size_t track_id_len = strlen(track_id); + while (track_id_len > 0 && isspace((unsigned char)track_id[track_id_len - 1])) + track_id[--track_id_len] = '\0'; + if (track_id_len == 0) { + warn("[MQTT]: queue_next command received with no track_id -- ignoring."); + } else { + char dacp_command[256]; + snprintf(dacp_command, sizeof(dacp_command), + "cue?command=add&query='dmap.persistentid:0x%s'&mode=3", track_id); + debug(2, "[MQTT]: Queue Next Command: %s\n", dacp_command); + send_simple_dacp_command(dacp_command); + } } else { debug(2, "[MQTT]: DACP Command: %s\n", commands[it]); #ifdef CONFIG_DACP_CLIENT