diff --git a/src/modules/virtual/Logging/Loging.cpp b/src/modules/virtual/Logging/Loging.cpp index 5677d056..2da2df5e 100644 --- a/src/modules/virtual/Logging/Loging.cpp +++ b/src/modules/virtual/Logging/Loging.cpp @@ -85,7 +85,7 @@ class Loging : public IoTItem { if (isItemExist(id)) { //выбираем только те файлы которые входят в выбранные сутки if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) { - Serial.print(", matched!"); + Serial.println("matched!"); createOneSingleJson(json_array, "/logs/" + fname); } } else { @@ -93,10 +93,10 @@ class Loging : public IoTItem { removeFile(directory + "/" + fname); } } - Serial.println("final: "); - Serial.println(json_array); json_array = "{\"status\":[" + json_array + "]}"; json_array.replace("},]}", "}]}"); + Serial.println("final: "); + Serial.println(json_array); publishChart(id, json_array); } @@ -147,3 +147,10 @@ void *getAPI_Loging(String subtype, String param) { return nullptr; } } + +class fileDB { + private: + public: + fileDB() { + } +}; \ No newline at end of file diff --git a/training/IarduinoRTC.cpp b/training/IarduinoRTC.cpp deleted file mode 100644 index 3145e364..00000000 --- a/training/IarduinoRTC.cpp +++ /dev/null @@ -1,106 +0,0 @@ -//#include "Global.h" -//#include "classes/IoTItem.h" -// -//#include -//#include "iarduino_RTC_DS1302.h" // Подключаем файл iarduino_RTC_DS1302.h -//#include "iarduino_RTC_DS1307.h" // Подключаем файл iarduino_RTC_DS1307.h -//#include "iarduino_RTC_DS3231.h" // Подключаем файл iarduino_RTC_DS3231.h -//#include "iarduino_RTC_RX8025.h" -// -// class IarduinoRTC : public IoTItem { -// private: -// int _chipNum, _rst, _clk, _dat, _ticker; -// String _defFormat; -// iarduino_RTC_BASE* RTCDriver; -// -// public: -// IarduinoRTC(String parameters) : IoTItem(parameters) { -// jsonRead(parameters, "chipNum", _chipNum); -// jsonRead(parameters, "rst", _rst); -// jsonRead(parameters, "clk", _clk); -// jsonRead(parameters, "dat", _dat); -// jsonRead(parameters, "defFormat", _defFormat); -// jsonRead(parameters, "ticker", _ticker); -// -// switch (_chipNum) { -// case 0: -// RTCDriver = new iarduino_RTC_NTP(); -// break; -// case 1: -// RTCDriver = new iarduino_RTC_DS1302(_rst, _clk, _dat); -// break; -// case 2: -// RTCDriver = new iarduino_RTC_DS1307(); -// break; -// case 3: -// RTCDriver = new iarduino_RTC_DS3231(); -// break; -// case 4: -// RTCDriver = new iarduino_RTC_RX8025(); -// break; -// } -// if (RTCDriver) RTCDriver->begin(); -// } -// -// void doByInterval() { -// value.isDecimal = false; -// value.valS = watch->gettime(_defFormat.c_str()); -// if (_ticker) regEvent(value.valS, "time ticker"); -// } -// -// IoTValue execute(String command, std::vector& param) { -// IoTValue tmpValue; -// if (command == "getTime") { -// if (param.size()) { -// tmpValue.isDecimal = false; -// tmpValue.valS = watch->gettime(param[0].valS.c_str()); -// return tmpValue; -// } -// } else if (command == "saveSysTime") { -// tm localTimeVar; -// time_t timeNowVar; -// time(&timeNowVar); -// localTimeVar = *localtime(&timeNowVar); -// watch->settime(localTimeVar.tm_sec, localTimeVar.tm_min, localTimeVar.tm_hour, localTimeVar.tm_mday, localTimeVar.tm_mon + 1, localTimeVar.tm_year - 100, localTimeVar.tm_wday); -// } else if (command == "setTime") { -// if (param.size()) { -// watch->settime(param[0].valD, param[1].valD, param[2].valD, param[3].valD, param[4].valD, param[5].valD, param[6].valD); -// } -// } else if (command == "setUnixTime") { -// if (param.size()) { -// watch->settimeUnix(param[0].valD); -// } -// } else if (command == "getHours") { -// tmpValue.valD = watch->Hours; // Часы 0-23 -// return tmpValue; -// } else if (command == "getMinutes") { -// tmpValue.valD = watch->minutes; // Минуты 0-59 -// return tmpValue; -// } else if (command == "getSeconds") { -// tmpValue.valD = watch->seconds; // Секунды 0-59 -// return tmpValue; -// } else if (command == "getMonth") { -// tmpValue.valD = watch->month; // Месяц 1-12 -// return tmpValue; -// } else if (command == "getDay") { -// tmpValue.valD = watch->day; // День месяца 1-31 -// return tmpValue; -// } -// -// return {}; -// } -// -// iarduino_RTC_BASE* getRtcDriver() { -// return RTCDriver; -// } -// -// ~IarduinoRTC(){}; -//}; -// -// void* getAPI_IarduinoRTC(String subtype, String param) { -// if (subtype == F("IarduinoRTC")) { -// return new IarduinoRTC(param); -// } else { -// return nullptr; -// } -//} diff --git a/training/IoTRTC.cpp b/training/IoTRTC.cpp deleted file mode 100644 index 40f35c7b..00000000 --- a/training/IoTRTC.cpp +++ /dev/null @@ -1,45 +0,0 @@ -//#include "classes/IoTRTC.h" -// -// IoTRTC::~IoTRTC() { -// -//} -// -// -// iarduino_RTC_NTP::iarduino_RTC_NTP() { -// -//} -// -// void iarduino_RTC_NTP::begin(void) { -// -//} -// -// uint8_t iarduino_RTC_NTP::funcReadTimeIndex(uint8_t i) { -// static tm localTimeVar; -// if (i == 0) { -// Serial.println(F("Read time from system.")); -// time_t timeNowVar; -// time(&timeNowVar); -// localTimeVar = *localtime(&timeNowVar); -// } -// -// switch (i) -// { -// case 0: return funcConvertNumToCode(localTimeVar.tm_sec); -// case 1: return funcConvertNumToCode(localTimeVar.tm_min); -// case 2: return funcConvertNumToCode(localTimeVar.tm_hour); -// case 3: return funcConvertNumToCode(localTimeVar.tm_mday); -// case 4: return funcConvertNumToCode(localTimeVar.tm_mon+1); -// case 5: return funcConvertNumToCode(localTimeVar.tm_year-100); -// case 6: return funcConvertNumToCode(localTimeVar.tm_wday); -// } -// -// return 0; -//} -// -// void iarduino_RTC_NTP::funcWriteTimeIndex(uint8_t i, uint8_t j) { -// -//} -// -// iarduino_RTC_NTP::~iarduino_RTC_NTP() { -// -//} diff --git a/training/IoTRTC.h b/training/IoTRTC.h deleted file mode 100644 index 15640aac..00000000 --- a/training/IoTRTC.h +++ /dev/null @@ -1,22 +0,0 @@ -//#pragma once -//#include -//#include -// -// class iarduino_RTC_NTP: public iarduino_RTC_BASE { -// public: -// iarduino_RTC_NTP(); -// ~iarduino_RTC_NTP(); -// void begin(void); -// uint8_t funcReadTimeIndex(uint8_t i); -// void funcWriteTimeIndex(uint8_t i, uint8_t j); -// uint8_t funcConvertNumToCode (uint8_t i) {return ((i/10) << 4) + (i%10);} -//}; -// -// class IoTRTC : public iarduino_RTC { -// public: -// IoTRTC(uint8_t i, uint8_t j=SS, uint8_t k=SCK, uint8_t n=MOSI) : iarduino_RTC(i, j, k, n) { -// if (i == 0) objClass = new iarduino_RTC_NTP(); -// }; -// -// ~IoTRTC(); -//}; \ No newline at end of file diff --git a/training/QueueFromChar.cpp b/training/QueueFromChar.cpp new file mode 100644 index 00000000..3d7a4bc3 --- /dev/null +++ b/training/QueueFromChar.cpp @@ -0,0 +1,46 @@ +#ifdef QUEUE_FROM_CHAR +#include "classes/QueueFromChar.h" + +QueueFromChar::QueueFromChar() { + commandList = NULL; + commandCount = 0; +} +QueueFromChar::~QueueFromChar() {} + +//добавление команды в буфер +void QueueFromChar::addCommand(const char* command) { + commandList = (CharBufferStruct*)realloc(commandList, (commandCount + 1) * sizeof(CharBufferStruct)); + strncpy(commandList[commandCount].command, command, MAX_COMMAND_LENGTH); + Serial.println("command added: " + String(command) + " " + String(commandCount)); + commandCount++; +} + +//распечатаем все добавленные команды +void QueueFromChar::printCommands() { + if (commandCount > 0 && commandList != NULL) { + for (int i = 0; i < commandCount; i++) { + Serial.println(commandList[i].command); + } + } +} + +//заберем последнюю из положенных в буфер команд +String QueueFromChar::getLastCommand() { + String ret = "empty"; + if (commandList != NULL) { + int cnt = commandCount - 1; + ret = commandList[cnt].command; + if (cnt > 0) { + delete commandList[cnt].command; + } else if (cnt == 0) { + commandList = NULL; + } + Serial.println("command deleted: " + ret + " " + String(cnt)); + commandCount--; + } + return ret; +} + +// QueueFromChar* myBuf; + +#endif diff --git a/training/QueueFromChar.h b/training/QueueFromChar.h new file mode 100644 index 00000000..c16b799e --- /dev/null +++ b/training/QueueFromChar.h @@ -0,0 +1,42 @@ +#pragma once +#include "Global.h" +#ifdef QUEUE_FROM_CHAR + +#define MAX_COMMAND_LENGTH 16 +#define BUFFER 128 + +class QueueFromChar; + +class QueueFromChar { + public: + QueueFromChar(); + ~QueueFromChar(); + + void addCommand(const char* command); + + void printCommands(); + + String getLastCommand(); + + private: + struct CharBufferStruct { + char command[MAX_COMMAND_LENGTH + 1]; + }; + CharBufferStruct* commandList; + int commandCount = 0; +}; + +// extern QueueFromChar* myBuf; + +//========проверка очереди===================== +// myBuf = new QueueFromChar; +// myBuf->addCommand("zero"); +// myBuf->addCommand("one"); +// myBuf->addCommand("two"); +// myBuf->printCommands(); +// myBuf->getLastCommand(); +// myBuf->getLastCommand(); +// myBuf->getLastCommand(); +// myBuf->printCommands(); + +#endif diff --git a/training/QueueFromInstance.cpp b/training/QueueFromInstance.cpp new file mode 100644 index 00000000..69321913 --- /dev/null +++ b/training/QueueFromInstance.cpp @@ -0,0 +1,30 @@ +#ifdef QUEUE_FROM_INST +#include "classes/QueueFromInstance.h" + +QueueFromInstance::QueueFromInstance() {} +QueueFromInstance::~QueueFromInstance() {} + +//добавим элемент в конец очереди +void QueueFromInstance::push(QueueInstance instance) { + queue1.push(instance); +} + +//удалим элемент из начала очереди +void QueueFromInstance::pop() { + if (!queue1.empty()) { + queue1.pop(); + } +} + +//вернуть элемент из начала очереди и удалить его +QueueInstance QueueFromInstance::front() { + QueueInstance instance(""); + if (!queue1.empty()) { + instance = queue1.front(); + queue1.pop(); + } + return instance; +} + +// QueueFromInstance* myQueue; +#endif diff --git a/training/QueueFromInstance.h b/training/QueueFromInstance.h new file mode 100644 index 00000000..0a509bf8 --- /dev/null +++ b/training/QueueFromInstance.h @@ -0,0 +1,26 @@ +#pragma once +#include "Global.h" +#ifdef QUEUE_FROM_INST +#include "classes/QueueInst.h" +#include +#include + +using namespace std; + +class QueueFromInstance; + +class QueueFromInstance { + public: + QueueFromInstance(); + ~QueueFromInstance(); + + void push(QueueInstance instance); + void pop(); + QueueInstance front(); + + private: + queue queue1; +}; + +// extern QueueFromInstance* myQueue; +#endif \ No newline at end of file diff --git a/training/QueueFromStruct.cpp b/training/QueueFromStruct.cpp new file mode 100644 index 00000000..52c5fb4c --- /dev/null +++ b/training/QueueFromStruct.cpp @@ -0,0 +1,32 @@ +#include "classes/QueueFromStruct.h" +#ifdef QUEUE_FROM_STR +QueueFromStruct::QueueFromStruct() {} +QueueFromStruct::~QueueFromStruct() {} + +//добавим элемент в конец очереди +void QueueFromStruct::push(QueueItems word) { + queue1.push(word); +} + +//удалим элемент из начала очереди +void QueueFromStruct::pop() { + if (!queue1.empty()) { + queue1.pop(); + } +} + +//вернуть элемент из начала очереди и удалить его +QueueItems QueueFromStruct::front() { + if (!queue1.empty()) { + tmpItem = queue1.front(); + queue1.pop(); + } + return tmpItem; +} + +bool QueueFromStruct::empty() { + return queue1.empty(); +} + +QueueFromStruct* filesQueue; +#endif diff --git a/training/QueueFromStruct.h b/training/QueueFromStruct.h new file mode 100644 index 00000000..d51de82f --- /dev/null +++ b/training/QueueFromStruct.h @@ -0,0 +1,46 @@ +#pragma once +#include "Global.h" +#ifdef QUEUE_FROM_STR +#include +//#include долбанный стрим сука + +using namespace std; + +struct QueueItems { + String myword; + uint8_t num; +}; + +class QueueFromStruct; + +class QueueFromStruct { + public: + QueueFromStruct(); + ~QueueFromStruct(); + + void push(QueueItems word); + void pop(); + QueueItems front(); + bool empty(); + + private: + queue queue1; + QueueItems tmpItem; +}; + +extern QueueFromStruct* filesQueue; + +//=======проверка очереди из структур================= +// myQueueStruct = new QueueFromStruct; +// QueueItems myItem; +// myItem.myword = "word1"; +// myQueueStruct->push(myItem); +// myItem.myword = "word2"; +// myQueueStruct->push(myItem); +// myItem.myword = "word3"; +// myQueueStruct->push(myItem); +// Serial.println(myQueueStruct->front().myword); +// Serial.println(myQueueStruct->front().myword); +// Serial.println(myQueueStruct->front().myword); + +#endif diff --git a/training/QueueInst.cpp b/training/QueueInst.cpp new file mode 100644 index 00000000..7439f3a5 --- /dev/null +++ b/training/QueueInst.cpp @@ -0,0 +1,24 @@ +#ifdef QUEUE_FROM_INST +#include "queue/QueueInst.h" + +QueueInstance::QueueInstance(String text) { + _text = text; +} +QueueInstance::~QueueInstance() {} + +String QueueInstance::get() { + return _text; +} + +//========проверка очереди из экземпляров====== + +// myQueue = new QueueFromInstance; + +// myQueue->push(QueueInstance("text1")); +// myQueue->push(QueueInstance("text2")); +// myQueue->push(QueueInstance("text3")); + +// Serial.println(myQueue->front().get()); +// Serial.println(myQueue->front().get()); +// Serial.println(myQueue->front().get()); +#endif \ No newline at end of file diff --git a/training/QueueInst.h b/training/QueueInst.h new file mode 100644 index 00000000..9731980c --- /dev/null +++ b/training/QueueInst.h @@ -0,0 +1,21 @@ +#pragma once +#include "Global.h" +#ifdef QUEUE_FROM_INST +#include +#include + +using namespace std; + +class QueueInstance; + +class QueueInstance { + public: + QueueInstance(String text); + ~QueueInstance(); + + String get(); + + private: + String _text; +}; +#endif diff --git a/training/SendJson.cpp b/training/SendJson.cpp new file mode 100644 index 00000000..9a7af2fb --- /dev/null +++ b/training/SendJson.cpp @@ -0,0 +1,44 @@ +#include "classes/SendJson.h" +#ifdef QUEUE_FROM_STR + +SendJson::SendJson() { + filesQueue = new QueueFromStruct; +} +SendJson::~SendJson() {} + +void SendJson::addFileToQueue(String path, uint8_t num) { + myItem.myword = path; + myItem.num = num; + filesQueue->push(myItem); + SerialPrint(F("i"), F("WS"), "file added to Queue " + path); +} + +//опсылает массив json по объектно в сокеты +void SendJson::loop() { + if (!filesQueue->empty() && !sendingInProgress) { + Serial.println("Queue not empty"); + myItem = filesQueue->front(); + _path = myItem.myword; + _num = myItem.num; + file = seekFile(_path); + SerialPrint(F("i"), F("WS"), "seek File to WS " + _path); + sendingInProgress = true; + } + if (file.available()) { + String jsonArrayElement = _path + file.readStringUntil('}') + "}"; + sendWs(jsonArrayElement); + } else { + sendingInProgress = false; + } +} + +void SendJson::sendWs(String& jsonArrayElement) { + standWebSocket.sendTXT(_num, jsonArrayElement); +} + +void SendJson::sendMqtt(String& jsonArrayElement) { + // mqtt send to do +} + +SendJson* sendJsonFiles; +#endif \ No newline at end of file diff --git a/training/SendJson.h b/training/SendJson.h new file mode 100644 index 00000000..0fabea32 --- /dev/null +++ b/training/SendJson.h @@ -0,0 +1,31 @@ +#pragma once +#include "Global.h" +#ifdef QUEUE_FROM_STR +#include "classes/QueueFromStruct.h" + +class SendJson; + +class SendJson { + public: + SendJson(); + ~SendJson(); + + void addFileToQueue(String path, uint8_t num); + + void loop(); + + void sendWs(String& jsonArrayElement); + + void sendMqtt(String& jsonArrayElement); + + QueueItems myItem; + + private: + File file; + String _path; + uint8_t _num; + bool sendingInProgress = false; +}; + +extern SendJson* sendJsonFiles; +#endif diff --git a/training/info.txt b/training/info.txt new file mode 100644 index 00000000..b7cb2d9e --- /dev/null +++ b/training/info.txt @@ -0,0 +1,8 @@ +здесь пишу статистику по остатку оперативной памяти после глобальных изменений + +22.12.21 пустой код без wifi остаток = 50.28 kB +22.12.21 запустил wifi остаток = 48.59 kB +22.12.21 добавил асинхронный веб сервер = 38.36 kB +22.12.21 добавил web sockets = 37.63 kB + +20.01.22 стандартный сервер mqtt в работе = 41.00 kb \ No newline at end of file