fixed the / MQTT topic issue

master
MrDIY 6 years ago
parent 6c19ecbb52
commit 52e09c9ef3

@ -22,26 +22,26 @@
Commands, to:
- Play MP3 MQTT topic: "mrdiynotifier/play"
- Play MP3 MQTT topic: "/mrdiynotifier/play"
MQTT load: http://url-to-the-mp3-file/file.mp3
- Play Icecast Stream MQTT topic: "mrdiynotifier/stream"
- Play Icecast Stream MQTT topic: "/mrdiynotifier/stream"
MQTT load: http://url-to-the-icecast-stream/file.mp3
- Play Ringtone MQTT topic: "mrdiynotifier/tone"
- Play Ringtone MQTT topic: "/mrdiynotifier/tone"
MQTT load: RTTTL formated text, example: Soap:d=8,o=5,b=125:g,a,c6,p,a,4c6,4p,a,g,e,c,4p,4g,a
- Say Text MQTT topic: "mrdiynotifier/say"
- Say Text MQTT topic: "/mrdiynotifier/say"
MQTT load: Text to be read, example: Hello There. How. Are. You?
- Change Volume MQTT topic: "mrdiynotifier/volume"
- Change Volume MQTT topic: "/mrdiynotifier/volume"
MQTT load: a double between 0.00 and 1.00, example: 0.7
- Stop Playing MQTT topic: "mrdiynotifier/stop"
- Stop Playing MQTT topic: "/mrdiynotifier/stop"
To get status:
- The notifier sends status update on this MQTT topic: "mrdiynotifier/status"
- The notifier sends status update on this MQTT topic: "/mrdiynotifier/status"
"playing" either paying an mp3, streaming, playing a ringtone or saying a text
"idle" waiting for a command
@ -259,7 +259,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
Serial.println(newMsg);
#endif
// got a new URL to play ------------------------------------------------
if ( !strcmp(topic, "mrdiynotifier/play")) {
if ( !strcmp(topic, "/mrdiynotifier/play")) {
stopPlaying();
file_http = new AudioFileSourceHTTPStream();
if ( file_http->open(newMsg)) {
@ -275,7 +275,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
}
// got a new URL to play ------------------------------------------------
if ( !strcmp(topic, "mrdiynotifier/stream")) {
if ( !strcmp(topic, "/mrdiynotifier/stream")) {
stopPlaying();
file_icy = new AudioFileSourceICYStream();
if ( file_icy->open(newMsg)) {
@ -291,7 +291,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
}
// got a tone request --------------------------------------------------
if ( !strcmp(topic, "mrdiynotifier/tone")) {
if ( !strcmp(topic, "/mrdiynotifier/tone")) {
stopPlaying();
broadcastStatus("playing");
file_progmem = new AudioFileSourcePROGMEM( newMsg, sizeof(newMsg) );
@ -301,7 +301,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
}
//got a TTS request ----------------------------------------------------
if ( !strcmp(topic, "mrdiynotifier/say")) {
if ( !strcmp(topic, "/mrdiynotifier/say")) {
stopPlaying();
broadcastStatus("playing");
ESP8266SAM *sam = new ESP8266SAM;
@ -312,7 +312,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
}
// got a volume request, expecting double [0.0,1.0] ---------------------
if ( !strcmp(topic, "mrdiynotifier/volume")) {
if ( !strcmp(topic, "/mrdiynotifier/volume")) {
volume_level = atof(newMsg);
if ( volume_level < 0.0 ) volume_level = 0;
if ( volume_level > 1.0 ) volume_level = 0.7;
@ -320,7 +320,7 @@ void onMqttMessage(char* topic, byte* payload, unsigned int length) {
}
// got a stop request --------------------------------------------------
if ( !strcmp(topic, "mrdiynotifier/stop")) {
if ( !strcmp(topic, "/mrdiynotifier/stop")) {
stopPlaying();
}
}
@ -331,7 +331,7 @@ void broadcastStatus(String msg) {
if ( playing_status != msg) {
char charBuf[msg.length() + 1];
msg.toCharArray(charBuf, msg.length() + 1);
mqttClient.publish("mrdiynotifier/status", charBuf);
mqttClient.publish("/mrdiynotifier/status", charBuf);
playing_status = msg;
#ifdef DEBUG_FLAG
Serial.println();
@ -346,13 +346,13 @@ void mqttReconnect() {
if (!mqttClient.connected()) {
if (mqttClient.connect("MrDIY Notifier", mqttUserName, mqttUserPassword)) {
broadcastStatus("connected");
mqttClient.subscribe("mrdiynotifier/play");
mqttClient.subscribe("mrdiynotifier/stream");
mqttClient.subscribe("mrdiynotifier/tone");
mqttClient.subscribe("mrdiynotifier/beep");
mqttClient.subscribe("mrdiynotifier/say");
mqttClient.subscribe("mrdiynotifier/stop");
mqttClient.subscribe("mrdiynotifier/volume");
mqttClient.subscribe("/mrdiynotifier/play");
mqttClient.subscribe("/mrdiynotifier/stream");
mqttClient.subscribe("/mrdiynotifier/tone");
mqttClient.subscribe("/mrdiynotifier/beep");
mqttClient.subscribe("/mrdiynotifier/say");
mqttClient.subscribe("/mrdiynotifier/stop");
mqttClient.subscribe("/mrdiynotifier/volume");
#ifdef DEBUG_FLAG
Serial.println();
Serial.print(F("Connected to MQTT: "));

Loading…
Cancel
Save