This commit is contained in:
e2002
2022-03-03 21:05:39 +03:00
parent ba71cdf587
commit 2fffe0d8bf
4 changed files with 69 additions and 10 deletions

View File

@@ -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);

46
yoRadio/mqttoptions.h Normal file
View File

@@ -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
*/

View File

@@ -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