mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Добавляем SD карту, пока встроенную в ESP32
This commit is contained in:
@@ -6,9 +6,10 @@ 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_EspCam(String subtype, String params);
|
||||
void* getAPI_IoTServo(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_Ads1115(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_ButtonIn(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_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_Ads1115(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
|
||||
70
src/modules/exec/SDcard/SDcard.cpp
Normal file
70
src/modules/exec/SDcard/SDcard.cpp
Normal 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> ¶m) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
14
src/modules/exec/SDcard/items.json
Normal file
14
src/modules/exec/SDcard/items.json
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"name": "SD карта",
|
||||
"num": 30,
|
||||
"type": "Writing",
|
||||
"subtype": "SDcard",
|
||||
"id": "sd",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "",
|
||||
|
||||
"int": 60
|
||||
}
|
||||
]
|
||||
9
src/modules/exec/SDcard/platformio.ini
Normal file
9
src/modules/exec/SDcard/platformio.ini
Normal file
@@ -0,0 +1,9 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
|
||||
|
||||
[iotm]
|
||||
exclude = false
|
||||
Reference in New Issue
Block a user