mqtt_fix
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
TimerHandle_t mqttReconnectTimer;
|
TimerHandle_t mqttReconnectTimer;
|
||||||
|
char topic[140], status[BUFLEN*3], vol[5], buf[20];
|
||||||
|
|
||||||
void connectToMqtt() {
|
void connectToMqtt() {
|
||||||
mqttClient.connect();
|
mqttClient.connect();
|
||||||
@@ -25,9 +26,9 @@ void mqttInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
char buf[140];
|
memset(topic, 0, 140);
|
||||||
sprintf(buf, "%s%s", MQTT_ROOT_TOPIC, "command");
|
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "command");
|
||||||
mqttClient.subscribe(buf, 2);
|
mqttClient.subscribe(topic, 2);
|
||||||
mqttPublishStatus();
|
mqttPublishStatus();
|
||||||
mqttPublishVolume();
|
mqttPublishVolume();
|
||||||
mqttPublishPlaylist();
|
mqttPublishPlaylist();
|
||||||
@@ -35,7 +36,8 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
|
|
||||||
void mqttPublishStatus() {
|
void mqttPublishStatus() {
|
||||||
if(mqttClient.connected()){
|
if(mqttClient.connected()){
|
||||||
char topic[140], status[BUFLEN*3];
|
memset(topic, 0, 140);
|
||||||
|
memset(status, 0, BUFLEN*3);
|
||||||
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "status");
|
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "status");
|
||||||
sprintf(status, "{\"status\": %d, \"station\": %d, \"name\": \"%s\", \"title\": \"%s\"}", player.mode==PLAYING?1:0, config.store.lastStation, config.station.name, config.station.title);
|
sprintf(status, "{\"status\": %d, \"station\": %d, \"name\": \"%s\", \"title\": \"%s\"}", player.mode==PLAYING?1:0, config.store.lastStation, config.station.name, config.station.title);
|
||||||
mqttClient.publish(topic, 0, true, status);
|
mqttClient.publish(topic, 0, true, status);
|
||||||
@@ -44,16 +46,18 @@ void mqttPublishStatus() {
|
|||||||
|
|
||||||
void mqttPublishPlaylist() {
|
void mqttPublishPlaylist() {
|
||||||
if(mqttClient.connected()){
|
if(mqttClient.connected()){
|
||||||
char topic[140], playlist[140];
|
memset(topic, 0, 140);
|
||||||
|
memset(status, 0, BUFLEN*3);
|
||||||
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "playlist");
|
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "playlist");
|
||||||
sprintf(playlist, "http://%s%s", WiFi.localIP().toString().c_str(), PLAYLIST_PATH);
|
sprintf(status, "http://%s%s", WiFi.localIP().toString().c_str(), PLAYLIST_PATH);
|
||||||
mqttClient.publish(topic, 0, true, playlist);
|
mqttClient.publish(topic, 0, true, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqttPublishVolume(){
|
void mqttPublishVolume(){
|
||||||
if(mqttClient.connected()){
|
if(mqttClient.connected()){
|
||||||
char topic[140], vol[5];
|
memset(topic, 0, 140);
|
||||||
|
memset(vol, 0, 5);
|
||||||
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "volume");
|
sprintf(topic, "%s%s", MQTT_ROOT_TOPIC, "volume");
|
||||||
sprintf(vol, "%d", config.store.volume);
|
sprintf(vol, "%d", config.store.volume);
|
||||||
mqttClient.publish(topic, 0, true, vol);
|
mqttClient.publish(topic, 0, true, vol);
|
||||||
@@ -68,7 +72,7 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
if (len == 0) return;
|
if (len == 0) return;
|
||||||
char buf[20];
|
memset(buf, 0, 20);
|
||||||
strlcpy(buf, payload, len+1);
|
strlcpy(buf, payload, len+1);
|
||||||
if (strcmp(buf, "prev") == 0) {
|
if (strcmp(buf, "prev") == 0) {
|
||||||
player.prev();
|
player.prev();
|
||||||
@@ -88,7 +92,6 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(buf, "start") == 0 || strcmp(buf, "play") == 0) {
|
if (strcmp(buf, "start") == 0 || strcmp(buf, "play") == 0) {
|
||||||
//player.play(config.store.lastStation);
|
|
||||||
player.request.station = config.store.lastStation;
|
player.request.station = config.store.lastStation;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -111,12 +114,10 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
player.setVol(volume, false);
|
player.setVol(volume, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//uint16_t sb;
|
|
||||||
int sb;
|
int sb;
|
||||||
if (sscanf(buf, "play %d", &sb) == 1 ) {
|
if (sscanf(buf, "play %d", &sb) == 1 ) {
|
||||||
if (sb < 1) sb = 1;
|
if (sb < 1) sb = 1;
|
||||||
if (sb >= config.store.countStation) sb = config.store.countStation;
|
if (sb >= config.store.countStation) sb = config.store.countStation;
|
||||||
//player.play(sb);
|
|
||||||
player.request.station = (uint16_t)sb;
|
player.request.station = (uint16_t)sb;
|
||||||
player.request.doSave = true;
|
player.request.doSave = true;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef options_h
|
#ifndef options_h
|
||||||
#define options_h
|
#define options_h
|
||||||
|
|
||||||
#define YOVERSION "0.8.834"
|
#define YOVERSION "0.8.840"
|
||||||
|
|
||||||
/*******************************************************
|
/*******************************************************
|
||||||
DO NOT EDIT THIS FILE.
|
DO NOT EDIT THIS FILE.
|
||||||
|
|||||||
Reference in New Issue
Block a user