diff --git a/README.md b/README.md index 98dabce..1b45e5b 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,9 @@ download _http://\/data/playlist.csv_ and _http://\/data **play x** - play station x --- ## Version history +#### v0.4.322 +- fixed garbage in MQTT payload + #### v0.4.320 - MQTT support diff --git a/yoRadio/mqtt.cpp b/yoRadio/mqtt.cpp index 432d932..d95cc1e 100644 --- a/yoRadio/mqtt.cpp +++ b/yoRadio/mqtt.cpp @@ -67,41 +67,51 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) { } void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { - if (strlen(payload) == 0) return; - if (strcmp(payload, "prev") == 0) { + if (len == 0) return; + char buf[20]; + strlcpy(buf, payload, len+1); + if (strcmp(buf, "prev") == 0) { player.prev(); return; } - if (strcmp(payload, "next") == 0) { + if (strcmp(buf, "next") == 0) { player.next(); return; } - if (strcmp(payload, "toggle") == 0) { + if (strcmp(buf, "toggle") == 0) { player.toggle(); return; } - if (strcmp(payload, "stop") == 0) { + if (strcmp(buf, "stop") == 0) { player.mode = STOPPED; telnet.info(); return; } - if (strcmp(payload, "start") == 0 || strcmp(payload, "play") == 0) { + if (strcmp(buf, "start") == 0 || strcmp(buf, "play") == 0) { player.play(config.store.lastStation); return; } - if (strcmp(payload, "boot") == 0 || strcmp(payload, "reboot") == 0) { + if (strcmp(buf, "boot") == 0 || strcmp(buf, "reboot") == 0) { ESP.restart(); return; } + if (strcmp(buf, "volm") == 0) { + player.stepVol(false); + return; + } + if (strcmp(buf, "volp") == 0) { + player.stepVol(true); + return; + } int volume; - if ( sscanf(payload, "vol %d", &volume) == 1) { + if ( sscanf(buf, "vol %d", &volume) == 1) { if (volume < 0) volume = 0; if (volume > 254) volume = 254; player.setVol(volume, false); return; } uint16_t sb; - if (sscanf(payload, "play %d", &sb) == 1 ) { + if (sscanf(buf, "play %d", &sb) == 1 ) { if (sb < 1) sb = 1; if (sb >= config.store.countStation) sb = config.store.countStation; player.play(sb); diff --git a/yoRadio/mqttoptions.h b/yoRadio/mqttoptions.h new file mode 100644 index 0000000..ace5b9a --- /dev/null +++ b/yoRadio/mqttoptions.h @@ -0,0 +1,46 @@ +#include "options.h" + +#define MQTT_HOST "192.168.7.3" +#define MQTT_PORT 1883 +#define MQTT_USER "" +#define MQTT_PASS "" + +/* + * HWID's: + * 0: with yellow-blue SSD1306 + * 1: white SSD1306 without controls + * 2: ST7735 with encoder + * 3: Nokia 5110 dev board + * 4: VS1053 dev + * 5: VS1053 UNO3 Shield + */ +#if HWID==0 +#define MQTT_ROOT_TOPIC "yoradio/tv/" +#elif HWID==1 +#define MQTT_ROOT_TOPIC "yoradio/work/" +#elif HWID==2 +#define MQTT_ROOT_TOPIC "yoradio/st7735/" +#elif HWID==3 +#define MQTT_ROOT_TOPIC "yoradio/nokia5110/" +#elif HWID==4 +#define MQTT_ROOT_TOPIC "yoradio/vs1053dev/" +#elif HWID==5 +#define MQTT_ROOT_TOPIC "yoradio/kitchen/" +#endif +/* +Topics: +MQTT_ROOT_TOPIC/command // Commands +MQTT_ROOT_TOPIC/status // Player status +MQTT_ROOT_TOPIC/playlist // Playlist URL +MQTT_ROOT_TOPIC/volume // Current volume + +Commands: +prev // prev station +next // next station +toggle // start/stop playing +stop // stop playing +start, play // start playing +boot, reboot // reboot +vol x // set volume +play x // play station x +*/ diff --git a/yoRadio/options.h b/yoRadio/options.h index 12bd0aa..2f31b0b 100644 --- a/yoRadio/options.h +++ b/yoRadio/options.h @@ -1,7 +1,7 @@ #ifndef options_h #define options_h -#define VERSION "0.4.320" +#define VERSION "0.4.322" #if __has_include("myoptions.h") #include "myoptions.h" // <- write your variable values here