Добавляем SD карту, пока встроенную в ESP32

This commit is contained in:
2022-06-02 23:14:26 +03:00
parent 4ce71dfcfd
commit 4ca8115154
6 changed files with 189 additions and 84 deletions

View File

@@ -92,8 +92,22 @@
"pin": 2 "pin": 2
}, },
{ {
"name": "7. Сервопривод", "name": "7. Camera OV2640 (ESPcam)",
"num": 7, "num": 7,
"type": "Reading",
"subtype": "EspCam",
"id": "EspCam",
"widget": "",
"page": "",
"descr": "",
"int": 60,
"useLed": 0,
"ticker": 0,
"webTicker": 0
},
{
"name": "8. Сервопривод",
"num": 8,
"type": "Writing", "type": "Writing",
"subtype": "IoTServo", "subtype": "IoTServo",
"id": "servo", "id": "servo",
@@ -106,8 +120,8 @@
"amap": "0, 4096, 0, 180" "amap": "0, 4096, 0, 180"
}, },
{ {
"name": "8. MP3 плеер", "name": "9. MP3 плеер",
"num": 8, "num": 9,
"type": "Reading", "type": "Reading",
"subtype": "Mp3", "subtype": "Mp3",
"id": "mp3", "id": "mp3",
@@ -119,23 +133,19 @@
"volume": 20 "volume": 20
}, },
{ {
"name": "9. Телеграм-Бот", "name": "10. SD карта",
"num": 9, "num": 10,
"type": "Writing", "type": "Writing",
"subtype": "Telegram", "subtype": "SDcard",
"id": "tg", "id": "sd",
"widget": "", "widget": "",
"page": "", "page": "",
"descr": "", "descr": "",
"int": 10, "int": 60
"token": "",
"autos": 1,
"receiveMsg": 0,
"chatID": ""
}, },
{ {
"name": "10. Таймер", "name": "11. Таймер",
"num": 10, "num": 11,
"type": "Writing", "type": "Writing",
"subtype": "Timer", "subtype": "Timer",
"id": "timer", "id": "timer",
@@ -152,8 +162,8 @@
"header": "Сенсоры" "header": "Сенсоры"
}, },
{ {
"name": "11. Датчик напряжения ADS1115", "name": "12. Датчик напряжения ADS1115",
"num": 11, "num": 12,
"type": "Reading", "type": "Reading",
"subtype": "Ads1115", "subtype": "Ads1115",
"id": "Ads3", "id": "Ads3",
@@ -169,8 +179,8 @@
"int": 10 "int": 10
}, },
{ {
"name": "12. Cенсор температуры AHT20", "name": "13. Cенсор температуры AHT20",
"num": 12, "num": 13,
"type": "Reading", "type": "Reading",
"subtype": "Aht20t", "subtype": "Aht20t",
"id": "Temp20", "id": "Temp20",
@@ -182,8 +192,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "13. Cенсор влажности AHT20", "name": "14. Cенсор влажности AHT20",
"num": 13, "num": 14,
"type": "Reading", "type": "Reading",
"subtype": "Aht20h", "subtype": "Aht20h",
"id": "Hum20", "id": "Hum20",
@@ -195,8 +205,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "14. Аналоговый сенсор", "name": "15. Аналоговый сенсор",
"num": 14, "num": 15,
"type": "Reading", "type": "Reading",
"subtype": "AnalogAdc", "subtype": "AnalogAdc",
"id": "t", "id": "t",
@@ -208,11 +218,12 @@
"multiply": 1, "multiply": 1,
"round": 1, "round": 1,
"pin": 0, "pin": 0,
"int": 15 "int": 15,
"avgSteps": 1
}, },
{ {
"name": "15. Cенсор температуры Bme280", "name": "16. Cенсор температуры Bme280",
"num": 15, "num": 16,
"type": "Reading", "type": "Reading",
"subtype": "Bme280t", "subtype": "Bme280t",
"id": "tmp3", "id": "tmp3",
@@ -224,8 +235,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "16. Cенсор давления Bme280", "name": "17. Cенсор давления Bme280",
"num": 16, "num": 17,
"type": "Reading", "type": "Reading",
"subtype": "Bme280p", "subtype": "Bme280p",
"id": "Press3", "id": "Press3",
@@ -237,8 +248,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "17. Cенсор влажности Bme280", "name": "18. Cенсор влажности Bme280",
"num": 17, "num": 18,
"type": "Reading", "type": "Reading",
"subtype": "Bme280h", "subtype": "Bme280h",
"id": "Hum3", "id": "Hum3",
@@ -250,8 +261,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "18. Cенсор температуры Bmp280", "name": "19. Cенсор температуры Bmp280",
"num": 18, "num": 19,
"type": "Reading", "type": "Reading",
"subtype": "Bmp280t", "subtype": "Bmp280t",
"id": "tmp3", "id": "tmp3",
@@ -263,8 +274,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "19. Cенсор давления Bmp280", "name": "20. Cенсор давления Bmp280",
"num": 19, "num": 20,
"type": "Reading", "type": "Reading",
"subtype": "Bmp280p", "subtype": "Bmp280p",
"id": "Press3", "id": "Press3",
@@ -276,8 +287,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "20. Cенсор температуры dht11", "name": "21. Cенсор температуры dht11",
"num": 20, "num": 21,
"type": "Reading", "type": "Reading",
"subtype": "Dht1122t", "subtype": "Dht1122t",
"id": "tmp3", "id": "tmp3",
@@ -289,8 +300,8 @@
"senstype": "dht11" "senstype": "dht11"
}, },
{ {
"name": "21. Cенсор влажности dht11", "name": "22. Cенсор влажности dht11",
"num": 21, "num": 22,
"type": "Reading", "type": "Reading",
"subtype": "Dht1122h", "subtype": "Dht1122h",
"id": "Hum3", "id": "Hum3",
@@ -302,8 +313,8 @@
"senstype": "dht11" "senstype": "dht11"
}, },
{ {
"name": "22. Cенсор температуры ds18b20", "name": "23. Cенсор температуры ds18b20",
"num": 22, "num": 23,
"type": "Reading", "type": "Reading",
"subtype": "Ds18b20", "subtype": "Ds18b20",
"id": "dstmp", "id": "dstmp",
@@ -317,8 +328,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "23. Датчик тока", "name": "24. Датчик тока",
"num": 23, "num": 24,
"type": "Reading", "type": "Reading",
"subtype": "I", "subtype": "I",
"id": "current", "id": "current",
@@ -332,8 +343,8 @@
"multiply": 1 "multiply": 1
}, },
{ {
"name": "24. Датчик напряжения", "name": "25. Датчик напряжения",
"num": 24, "num": 25,
"type": "Reading", "type": "Reading",
"subtype": "U", "subtype": "U",
"id": "voltage", "id": "voltage",
@@ -347,8 +358,8 @@
"multiply": 1 "multiply": 1
}, },
{ {
"name": "25. Cенсор температуры GY21", "name": "26. Cенсор температуры GY21",
"num": 25, "num": 26,
"type": "Reading", "type": "Reading",
"subtype": "GY21t", "subtype": "GY21t",
"id": "tmp4", "id": "tmp4",
@@ -359,8 +370,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "26. Cенсор влажности GY21", "name": "27. Cенсор влажности GY21",
"num": 26, "num": 27,
"type": "Reading", "type": "Reading",
"subtype": "GY21h", "subtype": "GY21h",
"id": "Hum4", "id": "Hum4",
@@ -371,8 +382,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "27. Cенсор температуры HDC1080", "name": "28. Cенсор температуры HDC1080",
"num": 27, "num": 28,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080t", "subtype": "Hdc1080t",
"id": "Temp1080", "id": "Temp1080",
@@ -384,8 +395,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "28. Cенсор влажности HDC1080", "name": "29. Cенсор влажности HDC1080",
"num": 28, "num": 29,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080h", "subtype": "Hdc1080h",
"id": "Hum1080", "id": "Hum1080",
@@ -397,8 +408,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "29. Cенсор температуры MAX6675", "name": "30. Cенсор температуры MAX6675",
"num": 29, "num": 30,
"type": "Reading", "type": "Reading",
"subtype": "Max6675t", "subtype": "Max6675t",
"id": "maxtmp", "id": "maxtmp",
@@ -411,8 +422,8 @@
"CLK": 14 "CLK": 14
}, },
{ {
"name": "30. Датчик CO2 MHZ-19 UART", "name": "31. Датчик CO2 MHZ-19 UART",
"num": 30, "num": 31,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19uart", "subtype": "Mhz19uart",
"id": "co2uart", "id": "co2uart",
@@ -430,8 +441,8 @@
"ABC": 1 "ABC": 1
}, },
{ {
"name": "31. Датчик CO2 MHZ-19 PWM", "name": "32. Датчик CO2 MHZ-19 PWM",
"num": 31, "num": 32,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19pwm", "subtype": "Mhz19pwm",
"id": "co2pwm", "id": "co2pwm",
@@ -445,8 +456,8 @@
"int": 300 "int": 300
}, },
{ {
"name": "32. Cенсор температуры от MHZ-19 UART", "name": "33. Cенсор температуры от MHZ-19 UART",
"num": 32, "num": 33,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19temp", "subtype": "Mhz19temp",
"id": "Mhz19temp", "id": "Mhz19temp",
@@ -462,8 +473,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "33. Рабочий диапазон от MHZ-19 UART", "name": "34. Рабочий диапазон от MHZ-19 UART",
"num": 33, "num": 34,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19range", "subtype": "Mhz19range",
"id": "Mhz19range", "id": "Mhz19range",
@@ -480,8 +491,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "34. Автокалибровка от MHZ-19 UART", "name": "35. Автокалибровка от MHZ-19 UART",
"num": 34, "num": 35,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19ABC", "subtype": "Mhz19ABC",
"id": "Mhz19ABC", "id": "Mhz19ABC",
@@ -495,8 +506,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "35. Датчик пыли SDS011 PM25", "name": "36. Датчик пыли SDS011 PM25",
"num": 35, "num": 36,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_25", "subtype": "Sds011_25",
"id": "pmuart25", "id": "pmuart25",
@@ -513,8 +524,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "36. Датчик пыли SDS011 PM10", "name": "37. Датчик пыли SDS011 PM10",
"num": 36, "num": 37,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_10", "subtype": "Sds011_10",
"id": "pmuart10", "id": "pmuart10",
@@ -531,8 +542,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "37. Cенсор температуры Sht20", "name": "38. Cенсор температуры Sht20",
"num": 37, "num": 38,
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -543,8 +554,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "38. Cенсор влажности Sht20", "name": "39. Cенсор влажности Sht20",
"num": 38, "num": 39,
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -555,8 +566,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "39. Сонар HC-SR04", "name": "40. Сонар HC-SR04",
"num": 39, "num": 40,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -571,8 +582,8 @@
"header": "Экраны" "header": "Экраны"
}, },
{ {
"name": "40. LCD экран 2004", "name": "41. LCD экран 2004",
"num": 40, "num": 41,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -586,8 +597,8 @@
"id2show": "id датчика" "id2show": "id датчика"
}, },
{ {
"name": "41. LCD экран 1602", "name": "42. LCD экран 1602",
"num": 41, "num": 42,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",

View File

@@ -34,7 +34,7 @@ build_src_filter = +<*>
exclude = 1 exclude = 1
[platformio] [platformio]
default_envs = esp8266_4mb default_envs = esp32_4mb
data_dir = data_svelte data_dir = data_svelte
[common_env_data] [common_env_data]
@@ -47,7 +47,6 @@ lib_deps_external =
lib_deps = lib_deps =
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
dfrobot/DFRobotDFPlayerMini @ ^1.0.5 dfrobot/DFRobotDFPlayerMini @ ^1.0.5
witnessmenow/UniversalTelegramBot @ ^1.3.0
adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit ADS1X15 @ ^2.3.0
Adafruit AHTX0 Adafruit AHTX0
adafruit/Adafruit BME280 Library adafruit/Adafruit BME280 Library
@@ -62,14 +61,14 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4 marcoschwartz/LiquidCrystal_I2C@^1.1.4
build_src_filter = build_src_filter =
-<modules/exec/EspCam> -<modules/exec/Telegram>
[env:esp32_4mb_fromitems] [env:esp32_4mb_fromitems]
lib_deps = lib_deps =
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
espressif/esp32-camera @ ^2.0.0
https://github.com/RoboticsBrno/ServoESP32 https://github.com/RoboticsBrno/ServoESP32
dfrobot/DFRobotDFPlayerMini @ ^1.0.5 dfrobot/DFRobotDFPlayerMini @ ^1.0.5
witnessmenow/UniversalTelegramBot @ ^1.3.0
adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit ADS1X15 @ ^2.3.0
Adafruit AHTX0 Adafruit AHTX0
adafruit/Adafruit BME280 Library adafruit/Adafruit BME280 Library
@@ -84,5 +83,5 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4 marcoschwartz/LiquidCrystal_I2C@^1.1.4
build_src_filter = build_src_filter =
-<modules/exec/EspCam> -<modules/exec/Telegram>

View File

@@ -6,9 +6,10 @@ void* getAPI_SysExt(String subtype, String params);
void* getAPI_Variable(String subtype, String params); void* getAPI_Variable(String subtype, String params);
void* getAPI_ButtonIn(String subtype, String params); void* getAPI_ButtonIn(String subtype, String params);
void* getAPI_ButtonOut(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_EspCam(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params); void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mp3(String subtype, String params); void* getAPI_Mp3(String subtype, String params);
void* getAPI_Telegram(String subtype, String params); void* getAPI_SDcard(String subtype, String params);
void* getAPI_Timer(String subtype, String params); void* getAPI_Timer(String subtype, String params);
void* getAPI_Ads1115(String subtype, String params); void* getAPI_Ads1115(String subtype, String params);
void* getAPI_Aht20(String subtype, String params); void* getAPI_Aht20(String subtype, String params);
@@ -35,9 +36,10 @@ if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Variable(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_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_EspCam(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Telegram(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_SDcard(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(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_Ads1115(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -0,0 +1,70 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include "FS.h" // SD Card ESP32
#include "SD_MMC.h" // SD Card ESP32
class SDcard : public IoTItem {
private:
public:
SDcard(String parameters): IoTItem(parameters) {
// jsonRead(parameters, "useLed", _useLed); // используем = 1 или нет = 0 подсветку (вспышку)
// jsonRead(parameters, "ticker", _ticker); // тикать = 1 - сообщаем всем, что сделали снимок и он готов
// jsonRead(parameters, "webTicker", _webTicker); // сообщать всем, что через веб попросили отдать картинку с камеры
Serial.println("Starting SD Card");
if(!SD_MMC.begin()){
Serial.println("SD Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD Card attached");
return;
}
}
void savePicture(String path, IoTValue srcValue) {
if (srcValue.extBinInfoSize) {
fs::FS &fs = SD_MMC;
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
}
else {
file.write(srcValue.extBinInfo, srcValue.extBinInfoSize); // payload (image), payload length
Serial.printf("Picture file name: %s | bufsize: %d\n", path.c_str(), srcValue.extBinInfoSize);
}
file.close();
}
}
void doByInterval() {
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (command == "saveBin") {
if (param.size() == 2) {
savePicture (param[0].valS, param[1]);
}
}
return {};
}
~SDcard() {
};
};
void* getAPI_SDcard(String subtype, String param) {
if (subtype == F("SDcard")) {
return new SDcard(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,14 @@
[
{
"name": "SD карта",
"num": 30,
"type": "Writing",
"subtype": "SDcard",
"id": "sd",
"widget": "",
"page": "",
"descr": "",
"int": 60
}
]

View File

@@ -0,0 +1,9 @@
[env:esp8266_4mb]
lib_deps =
[env:esp32_4mb]
lib_deps =
[iotm]
exclude = false