diff --git a/data_svelte/items.json b/data_svelte/items.json index 8395e9f4..506f7d58 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -92,8 +92,21 @@ "pin": 2 }, { - "name": "7. Таймер", + "name": "7. MP3 плеер", "num": 7, + "type": "Reading", + "subtype": "Mp3", + "id": "mp3", + "widget": "", + "page": "", + "descr": "", + "int": 1, + "pins": "14,12", + "volume": 20 + }, + { + "name": "8. Таймер", + "num": 8, "type": "Writing", "subtype": "Timer", "id": "timer", @@ -110,8 +123,8 @@ "header": "Сенсоры" }, { - "name": "8. Датчик напряжения ADS1115", - "num": 8, + "name": "9. Датчик напряжения ADS1115", + "num": 9, "type": "Reading", "subtype": "Ads1115", "id": "Ads3", @@ -127,8 +140,8 @@ "int": 10 }, { - "name": "9. Cенсор температуры AHT20", - "num": 9, + "name": "10. Cенсор температуры AHT20", + "num": 10, "type": "Reading", "subtype": "Aht20t", "id": "Temp20", @@ -140,8 +153,8 @@ "round": 1 }, { - "name": "10. Cенсор влажности AHT20", - "num": 10, + "name": "11. Cенсор влажности AHT20", + "num": 11, "type": "Reading", "subtype": "Aht20h", "id": "Hum20", @@ -153,8 +166,8 @@ "round": 1 }, { - "name": "11. Аналоговый сенсор", - "num": 11, + "name": "12. Аналоговый сенсор", + "num": 12, "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -169,8 +182,8 @@ "int": 15 }, { - "name": "12. Cенсор температуры Bme280", - "num": 12, + "name": "13. Cенсор температуры Bme280", + "num": 13, "type": "Reading", "subtype": "Bme280t", "id": "tmp3", @@ -182,8 +195,8 @@ "round": 1 }, { - "name": "13. Cенсор давления Bme280", - "num": 13, + "name": "14. Cенсор давления Bme280", + "num": 14, "type": "Reading", "subtype": "Bme280p", "id": "Press3", @@ -195,8 +208,8 @@ "round": 1 }, { - "name": "14. Cенсор влажности Bme280", - "num": 14, + "name": "15. Cенсор влажности Bme280", + "num": 15, "type": "Reading", "subtype": "Bme280h", "id": "Hum3", @@ -208,8 +221,8 @@ "round": 1 }, { - "name": "15. Cенсор температуры Bmp280", - "num": 15, + "name": "16. Cенсор температуры Bmp280", + "num": 16, "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -221,8 +234,8 @@ "round": 1 }, { - "name": "16. Cенсор давления Bmp280", - "num": 16, + "name": "17. Cенсор давления Bmp280", + "num": 17, "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -234,8 +247,8 @@ "round": 1 }, { - "name": "17. Cенсор температуры dht11", - "num": 17, + "name": "18. Cенсор температуры dht11", + "num": 18, "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -247,8 +260,8 @@ "senstype": "dht11" }, { - "name": "18. Cенсор влажности dht11", - "num": 18, + "name": "19. Cенсор влажности dht11", + "num": 19, "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -260,8 +273,8 @@ "senstype": "dht11" }, { - "name": "19. Cенсор температуры ds18b20", - "num": 19, + "name": "20. Cенсор температуры ds18b20", + "num": 20, "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -275,8 +288,8 @@ "round": 1 }, { - "name": "20. Cенсор температуры GY21", - "num": 20, + "name": "21. Cенсор температуры GY21", + "num": 21, "type": "Reading", "subtype": "GY21t", "id": "tmp4", @@ -287,8 +300,8 @@ "int": 15 }, { - "name": "21. Cенсор влажности GY21", - "num": 21, + "name": "22. Cенсор влажности GY21", + "num": 22, "type": "Reading", "subtype": "GY21h", "id": "Hum4", @@ -299,8 +312,8 @@ "int": 15 }, { - "name": "22. Cенсор температуры HDC1080", - "num": 22, + "name": "23. Cенсор температуры HDC1080", + "num": 23, "type": "Reading", "subtype": "Hdc1080t", "id": "Temp1080", @@ -312,8 +325,8 @@ "round": 1 }, { - "name": "23. Cенсор влажности HDC1080", - "num": 23, + "name": "24. Cенсор влажности HDC1080", + "num": 24, "type": "Reading", "subtype": "Hdc1080h", "id": "Hum1080", @@ -325,8 +338,8 @@ "round": 1 }, { - "name": "24. Cенсор температуры MAX6675", - "num": 24, + "name": "25. Cенсор температуры MAX6675", + "num": 25, "type": "Reading", "subtype": "Max6675t", "id": "maxtmp", @@ -339,8 +352,8 @@ "CLK": 14 }, { - "name": "25. Датчик CO2 MHZ-19 UART", - "num": 25, + "name": "26. Датчик CO2 MHZ-19 UART", + "num": 26, "type": "Reading", "subtype": "Mhz19uart", "id": "co2uart", @@ -358,8 +371,8 @@ "ABC": 1 }, { - "name": "26. Датчик CO2 MHZ-19 PWM", - "num": 26, + "name": "27. Датчик CO2 MHZ-19 PWM", + "num": 27, "type": "Reading", "subtype": "Mhz19pwm", "id": "co2pwm", @@ -373,8 +386,8 @@ "int": 300 }, { - "name": "27. Cенсор температуры от MHZ-19 UART", - "num": 27, + "name": "28. Cенсор температуры от MHZ-19 UART", + "num": 28, "type": "Reading", "subtype": "Mhz19temp", "id": "Mhz19temp", @@ -390,8 +403,8 @@ "int": 30 }, { - "name": "28. Рабочий диапазон от MHZ-19 UART", - "num": 28, + "name": "29. Рабочий диапазон от MHZ-19 UART", + "num": 29, "type": "Reading", "subtype": "Mhz19range", "id": "Mhz19range", @@ -408,8 +421,8 @@ "int": 30 }, { - "name": "29. Автокалибровка от MHZ-19 UART", - "num": 29, + "name": "30. Автокалибровка от MHZ-19 UART", + "num": 30, "type": "Reading", "subtype": "Mhz19ABC", "id": "Mhz19ABC", @@ -423,8 +436,8 @@ "int": 30 }, { - "name": "30. Датчик пыли SDS011 PM25", - "num": 30, + "name": "31. Датчик пыли SDS011 PM25", + "num": 31, "type": "Reading", "subtype": "Sds011_25", "id": "pmuart25", @@ -441,8 +454,8 @@ "period": 300 }, { - "name": "31. Датчик пыли SDS011 PM10", - "num": 31, + "name": "32. Датчик пыли SDS011 PM10", + "num": 32, "type": "Reading", "subtype": "Sds011_10", "id": "pmuart10", @@ -459,8 +472,8 @@ "period": 300 }, { - "name": "32. Cенсор температуры Sht20", - "num": 32, + "name": "33. Cенсор температуры Sht20", + "num": 33, "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -471,8 +484,8 @@ "round": 1 }, { - "name": "33. Cенсор влажности Sht20", - "num": 33, + "name": "34. Cенсор влажности Sht20", + "num": 34, "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -486,8 +499,8 @@ "header": "Экраны" }, { - "name": "34. LCD экран 2004", - "num": 34, + "name": "35. LCD экран 2004", + "num": 35, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -501,8 +514,8 @@ "id2show": "id датчика" }, { - "name": "35. LCD экран 1602", - "num": 35, + "name": "36. LCD экран 1602", + "num": 36, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", diff --git a/platformio.ini b/platformio.ini index d8dffba9..9f4eed77 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,6 +39,7 @@ lib_deps_external = [env:esp8266_4mb_fromitems] lib_deps = adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit ADS1X15 @ ^2.3.0 Adafruit AHTX0 adafruit/Adafruit BME280 Library @@ -55,6 +56,7 @@ lib_deps = [env:esp32_4mb_fromitems] lib_deps = adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit ADS1X15 @ ^2.3.0 Adafruit AHTX0 adafruit/Adafruit BME280 Library diff --git a/src/modules/API.cpp b/src/modules/API.cpp index a62eb43f..8df7cbce 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -6,6 +6,7 @@ void* getAPI_SysExt(String subtype, String params); void* getAPI_Variable(String subtype, String params); void* getAPI_ButtonIn(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params); +void* getAPI_Mp3(String subtype, String params); void* getAPI_Timer(String subtype, String params); void* getAPI_Ads1115(String subtype, String params); void* getAPI_Aht20(String subtype, String params); @@ -30,6 +31,7 @@ if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; diff --git a/src/modules/exec/Mp3/Mp3.cpp b/src/modules/exec/Mp3/Mp3.cpp new file mode 100644 index 00000000..a878c537 --- /dev/null +++ b/src/modules/exec/Mp3/Mp3.cpp @@ -0,0 +1,120 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include "SoftwareSerial.h" // Подключаем библиотеку SoftwareSerial +#include "DFRobotDFPlayerMini.h" // Подключаем библиотеку DFPlayerMini_Fast + + +class Mp3 : public IoTItem { + private: + SoftwareSerial* mySerial; + DFRobotDFPlayerMini* myMP3; + + public: + Mp3(String parameters): IoTItem(parameters) { + String tmpstr; + int volumetmp; + jsonRead(parameters, "pins", tmpstr); + int pinRx = selectFromMarkerToMarker(tmpstr, ",", 0).toInt(); + int pinTx = selectFromMarkerToMarker(tmpstr, ",", 1).toInt(); + mySerial = new SoftwareSerial(pinRx, pinTx); + + jsonRead(parameters, "volume", volumetmp); + + if (mySerial) myMP3 = new DFRobotDFPlayerMini(); + if (myMP3) { + myMP3->begin(*mySerial); + myMP3->volume(volumetmp); + } + + value.isDecimal = false; // значение объекта всегда будет строка + } + + void doByInterval() { + if (myMP3 && myMP3->available()) { + switch (myMP3->readType()) { + case TimeOut: + value.valS = F("Time Out!"); + break; + case WrongStack: + value.valS = F("Stack Wrong!"); + break; + case DFPlayerCardInserted: + value.valS = F("Card Inserted!"); + break; + case DFPlayerCardRemoved: + value.valS = F("Card Removed!"); + break; + case DFPlayerCardOnline: + value.valS = F("Card Online!"); + break; + case DFPlayerPlayFinished: + value.valS = F("Play Finished!"); + break; + case DFPlayerError: + switch (myMP3->read()) { + case Busy: + value.valS = F("Card not found"); + break; + case Sleeping: + value.valS = F("Sleeping"); + break; + case SerialWrongStack: + value.valS = F("Get Wrong Stack"); + break; + case CheckSumNotMatch: + value.valS = F("Check Sum Not Match"); + break; + case FileIndexOut: + value.valS = F("File Index Out of Bound"); + break; + case FileMismatch: + value.valS = F("Cannot Find File"); + break; + case Advertise: + value.valS = F("In Advertise"); + break; + default: + break; + } + break; + default: + break; + } + } + } + + IoTValue execute(String command, std::vector ¶m) { + // реакция на вызов команды модуля из сценария + // String command - имя команды после ID. (ID.Команда()) + // param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22 + + if (myMP3) { + if (command == "enableLoop") { + myMP3->enableLoop(); + } else if (command == "disableLoop") { + myMP3->disableLoop(); + } else if (command == "volume") { + if (param.size()) { + myMP3->volume(param[0].valD); + } + } else if (command == "playFolder") { + if (param.size()) { + myMP3->playFolder(param[0].valD, param[1].valD); + } + } + } + + return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки + } + + ~Mp3() {}; +}; + +void* getAPI_Mp3(String subtype, String param) { + if (subtype == F("Mp3")) { + return new Mp3(param); + } else { + return nullptr; + } +} diff --git a/src/modules/exec/Mp3/items.json b/src/modules/exec/Mp3/items.json new file mode 100644 index 00000000..4065d308 --- /dev/null +++ b/src/modules/exec/Mp3/items.json @@ -0,0 +1,16 @@ +[ + { + "name": "MP3 плеер", + "num": 30, + "type": "Reading", + "subtype": "Mp3", + "id": "mp3", + "widget": "", + "page": "", + "descr": "", + + "int": 1, + "pins": "14,12", + "volume": 20 + } +] \ No newline at end of file diff --git a/src/modules/exec/Mp3/platformio.ini b/src/modules/exec/Mp3/platformio.ini new file mode 100644 index 00000000..1a2dc6e2 --- /dev/null +++ b/src/modules/exec/Mp3/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + dfrobot/DFRobotDFPlayerMini @ ^1.0.5 + +[env:esp32_4mb] +lib_deps = + dfrobot/DFRobotDFPlayerMini @ ^1.0.5