diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h
index b1ecd6fa6..bd76cf0be 100644
--- a/sonoff/language/bg-BG.h
+++ b/sonoff/language/bg-BG.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Ключ" // Suffix "1"
#define D_SENSOR_BUTTON "Бутон" // Suffix "1"
diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h
index 2f51ccc93..0a3430e01 100644
--- a/sonoff/language/cs-CZ.h
+++ b/sonoff/language/cs-CZ.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Spínač" // Suffix "1"
#define D_SENSOR_BUTTON "Tlačítko" // Suffix "1"
diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h
index 888345d8a..32d6a8f2b 100644
--- a/sonoff/language/de-DE.h
+++ b/sonoff/language/de-DE.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRSend"
#define D_SENSOR_SWITCH "Switch " // Suffix "1"
#define D_SENSOR_BUTTON "Button " // Suffix "1"
diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h
index 3187eadf9..b2fa8feb6 100644
--- a/sonoff/language/el-GR.h
+++ b/sonoff/language/el-GR.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Διακόπτης" // Suffix "1"
#define D_SENSOR_BUTTON "Κουμπί" // Suffix "1"
diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h
index 558877db2..a622419fa 100644
--- a/sonoff/language/en-GB.h
+++ b/sonoff/language/en-GB.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h
index 986b9507f..398d0442f 100644
--- a/sonoff/language/es-AR.h
+++ b/sonoff/language/es-AR.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IR TX"
#define D_SENSOR_SWITCH "Llave" // Suffix "1"
#define D_SENSOR_BUTTON "Botón" // Suffix "1"
diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h
index 2a46f7b53..a4b7d2011 100644
--- a/sonoff/language/fr-FR.h
+++ b/sonoff/language/fr-FR.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "ÉmetIR"
#define D_SENSOR_SWITCH "Inter." // Suffix "1"
#define D_SENSOR_BUTTON "Bouton" // Suffix "1"
diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h
index c57278176..79fd88d8e 100644
--- a/sonoff/language/hu-HU.h
+++ b/sonoff/language/hu-HU.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRadó"
#define D_SENSOR_SWITCH "Kapcsoló" // Suffix "1"
#define D_SENSOR_BUTTON "Gomb" // Suffix "1"
diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h
index d07a33021..509105eb5 100644
--- a/sonoff/language/it-IT.h
+++ b/sonoff/language/it-IT.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h
index 05ec4666b..2761e45d3 100644
--- a/sonoff/language/nl-NL.h
+++ b/sonoff/language/nl-NL.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Speler"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h
index faaf8df6d..9fa16ac9f 100644
--- a/sonoff/language/pl-PL.h
+++ b/sonoff/language/pl-PL.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Przela" // Suffix "1"
#define D_SENSOR_BUTTON "Przyci" // Suffix "1"
diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h
index 318f69e45..46a21b998 100644
--- a/sonoff/language/pt-BR.h
+++ b/sonoff/language/pt-BR.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Interruptor" // Suffix "1"
#define D_SENSOR_BUTTON "Botão" // Suffix "1"
diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h
index d39ec6e50..d4cea0a48 100644
--- a/sonoff/language/pt-PT.h
+++ b/sonoff/language/pt-PT.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Interruptor" // Suffix "1"
#define D_SENSOR_BUTTON "Botão" // Suffix "1"
diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h
index 5fea0468e..e782e9409 100644
--- a/sonoff/language/ru-RU.h
+++ b/sonoff/language/ru-RU.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Свич" // Suffix "1"
#define D_SENSOR_BUTTON "Кнопка" // Suffix "1"
diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h
index b133d2c80..1f11d4a01 100755
--- a/sonoff/language/tr-TR.h
+++ b/sonoff/language/tr-TR.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h
index 9cf66773b..90cfb9f4a 100644
--- a/sonoff/language/uk-UK.h
+++ b/sonoff/language/uk-UK.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Перемикач" // Suffix "1"
#define D_SENSOR_BUTTON "Кнопка" // Suffix "1"
diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h
index 88f680f8e..24eb38f6f 100644
--- a/sonoff/language/zh-CN.h
+++ b/sonoff/language/zh-CN.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h
index abb92d359..c07023268 100644
--- a/sonoff/language/zh-TW.h
+++ b/sonoff/language/zh-TW.h
@@ -456,6 +456,7 @@
#define D_SENSOR_I2C_SCL "I2C SCL"
#define D_SENSOR_I2C_SDA "I2C SDA"
#define D_SENSOR_WS2812 "WS2812"
+#define D_SENSOR_DFR562 "MP3 Player"
#define D_SENSOR_IRSEND "IRsend"
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
#define D_SENSOR_BUTTON "Button" // Suffix "1"
diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h
index 3881f8c3e..2ab43286d 100644
--- a/sonoff/sonoff_template.h
+++ b/sonoff/sonoff_template.h
@@ -122,6 +122,7 @@ enum UserSelectablePins {
GPIO_CNTR4_NP,
GPIO_PZEM2_TX, // PZEM-003,014,016,017 Serial interface
GPIO_PZEM2_RX, // PZEM-003,014,016,017 Serial interface
+ GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player
GPIO_SENSOR_END };
// Programmer selectable GPIO functionality offset by user selectable GPIOs
@@ -172,7 +173,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_SWITCH "1n|" D_SENSOR_SWITCH "2n|" D_SENSOR_SWITCH "3n|" D_SENSOR_SWITCH "4n|" D_SENSOR_SWITCH "5n|" D_SENSOR_SWITCH "6n|" D_SENSOR_SWITCH "7n|" D_SENSOR_SWITCH "8n|"
D_SENSOR_BUTTON "1n|" D_SENSOR_BUTTON "2n|" D_SENSOR_BUTTON "3n|" D_SENSOR_BUTTON "4n|"
D_SENSOR_COUNTER "1n|" D_SENSOR_COUNTER "2n|" D_SENSOR_COUNTER "3n|" D_SENSOR_COUNTER "4n|"
- D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|";
+ D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|"
+ D_SENSOR_DFR562;
/********************************************************************************************/
@@ -1019,4 +1021,4 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
}
*/
-#endif // _SONOFF_TEMPLATE_H_
\ No newline at end of file
+#endif // _SONOFF_TEMPLATE_H_
diff --git a/sonoff/user_config.h b/sonoff/user_config.h
index 81928f1e7..b7a54408d 100644
--- a/sonoff/user_config.h
+++ b/sonoff/user_config.h
@@ -268,6 +268,9 @@
// -- Internal Analog input -----------------------
#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices
+// -- MP3 player ----------------------------------
+//#define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop
+
// -- One wire sensors ----------------------------
// WARNING: Select none for default one DS18B20 sensor or enable one of the following two options for multiple sensors
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
diff --git a/sonoff/xdrv_91_mp3.ino b/sonoff/xdrv_91_mp3.ino
new file mode 100644
index 000000000..82c778127
--- /dev/null
+++ b/sonoff/xdrv_91_mp3.ino
@@ -0,0 +1,117 @@
+/*
+ xdrv_91_mp3.ino - MP3 Player support for Sonoff-Tasmota
+ Player type: RB-DFR-562, DFPlayer Mini MP3 Player
+ Copyright (C) 2018 Theo Arends
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+*/
+
+#ifdef USE_MP3_PLAYER
+
+#include
+
+TasmotaSerial *MP3Player;
+
+#define D_CMND_MP3 "MP3"
+const char S_JSON_MP3_COMMAND_NVALUE[] PROGMEM = "{\"" D_CMND_MP3 "%s\":%d}";
+const char S_JSON_MP3_COMMAND[] PROGMEM = "{\"" D_CMND_MP3 "%s\"}";
+
+enum MP3_Commands { CMND_MP3_PLAY, CMND_MP3_STOP, CMND_MP3_VOLUME};
+const char kMP3_Commands[] PROGMEM = "Play" "|" "Stop" "|" "Volume";
+
+#define MP3_CMD_PLAY 3
+#define MP3_CMD_VOLUME 6
+#define MP3_CMD_STOP 0x0e
+
+uint16_t MP3_Checksum(uint8_t *array)
+{
+ uint16_t checksum = 0;
+ for (uint8_t i = 0; i < 6; i++) {
+ checksum += array[i];
+ }
+ checksum = checksum^0xffff;
+ return checksum+1;
+}
+
+// init player define serial tx port
+void InitMP3Player() {
+ MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3PLAYER]);
+
+ if (MP3Player->begin(9600)) {
+ //serial_bridge_active = 1;
+ MP3Player->flush();
+ }
+}
+
+void MP3_CMD(uint8_t mp3cmd,uint16_t val) {
+ uint8_t cmd[10] = {0x7e,0xff,6,0,0,0,0,0,0,0xef};
+ cmd[3] = mp3cmd;
+ cmd[5] = val>>8;
+ cmd[6] = val;
+ uint16_t chks = MP3_Checksum(&cmd[1]); // calculate out
+ cmd[7] = chks>>8;
+ cmd[8] = chks;
+ MP3Player->write(cmd, sizeof(cmd));
+}
+
+boolean MP3PlayerCmd() {
+ char command[CMDSZ];
+ boolean serviced = true;
+ uint8_t disp_len = strlen(D_CMND_MP3);
+
+ if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_MP3), disp_len)) { // Prefix
+ int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic + disp_len, kMP3_Commands);
+
+ if (CMND_MP3_PLAY == command_code) {
+ if (XdrvMailbox.data_len > 0) { // play
+ MP3_CMD(MP3_CMD_PLAY, XdrvMailbox.payload);
+ }
+ snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND_NVALUE, command, XdrvMailbox.payload);
+ }
+ else if (CMND_MP3_VOLUME == command_code) {
+ if (XdrvMailbox.data_len > 0) { // set volume
+ MP3_CMD(MP3_CMD_VOLUME, XdrvMailbox.payload * 30 / 100);
+ }
+ snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND_NVALUE, command, XdrvMailbox.payload);
+ }
+ else if (CMND_MP3_STOP == command_code) { // stop
+ MP3_CMD(MP3_CMD_STOP, 0);
+ snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND, command, XdrvMailbox.payload);
+ } else {
+ serviced = false; // Unknown command
+ }
+ }
+ return serviced;
+}
+
+/*********************************************************************************************\
+ * Interface
+\*********************************************************************************************/
+
+#define XDRV_91
+
+boolean Xdrv91(byte function)
+{
+ boolean result = false;
+
+ switch (function) {
+ case FUNC_PRE_INIT:
+ InitMP3Player();
+ break;
+ case FUNC_COMMAND:
+ result = MP3PlayerCmd();
+ break;
+ }
+ return result;
+}
+
+#endif // USE_MP3_PLAYER