mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
новая система отправки файла в сокеты
This commit is contained in:
@@ -1,4 +1,96 @@
|
||||
[
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "AnalogAdc",
|
||||
"id": "t1",
|
||||
"widget": "anydataDef",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"pin": 0,
|
||||
"int": 10
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "AnalogAdc",
|
||||
"id": "t2",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"pin": 0,
|
||||
"int": 15
|
||||
},
|
||||
{
|
||||
"type": "Variable",
|
||||
"subtype": "ButtonOut",
|
||||
"id": "btn1",
|
||||
"widget": "toggle",
|
||||
"page": "Кнопки",
|
||||
"descr": "Освещение",
|
||||
"gpio": 13,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Variable",
|
||||
"subtype": "PwmOut",
|
||||
"id": "pwm1",
|
||||
"widget": "range",
|
||||
"page": "Регуляторы",
|
||||
"descr": "Освещение",
|
||||
"gpio": 14,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "ButtonIn",
|
||||
"id": "btn",
|
||||
"widget": "toggle",
|
||||
"page": "Кнопки",
|
||||
"descr": "Освещение",
|
||||
"gpio": 12,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "OutputValue",
|
||||
"id": "txt",
|
||||
"widget": "anydataRed",
|
||||
"page": "Предупреждения",
|
||||
"descr": "Статус"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "InputValue",
|
||||
"id": "txt",
|
||||
"widget": "inputDgt",
|
||||
"page": "Лимиты",
|
||||
"descr": "Порог"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "t",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "p",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "h",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 10,
|
||||
"addr": "0x78"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "AnalogAdc",
|
||||
|
||||
74
data_svelte/test.json
Normal file
74
data_svelte/test.json
Normal file
@@ -0,0 +1,74 @@
|
||||
[
|
||||
{
|
||||
"type": "Variable",
|
||||
"subtype": "ButtonOut",
|
||||
"id": "btn1",
|
||||
"widget": "toggle",
|
||||
"page": "Кнопки",
|
||||
"descr": "Освещение",
|
||||
"gpio": 13,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Variable",
|
||||
"subtype": "PwmOut",
|
||||
"id": "pwm1",
|
||||
"widget": "range",
|
||||
"page": "Регуляторы",
|
||||
"descr": "Освещение",
|
||||
"gpio": 14,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "ButtonIn",
|
||||
"id": "btn",
|
||||
"widget": "toggle",
|
||||
"page": "Кнопки",
|
||||
"descr": "Освещение",
|
||||
"gpio": 12,
|
||||
"inv": false
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "OutputValue",
|
||||
"id": "txt",
|
||||
"widget": "anydataRed",
|
||||
"page": "Предупреждения",
|
||||
"descr": "Статус"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "InputValue",
|
||||
"id": "txt",
|
||||
"widget": "inputDgt",
|
||||
"page": "Лимиты",
|
||||
"descr": "Порог"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "t",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "p",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление"
|
||||
},
|
||||
{
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280",
|
||||
"id": "h",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 10,
|
||||
"addr": "0x78"
|
||||
}
|
||||
]
|
||||
@@ -21,3 +21,8 @@ extern void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t
|
||||
extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void sendFileToWs(const String& filename, uint8_t num);
|
||||
void sendFileToWs2(const String& filename, uint8_t num);
|
||||
void sendFileToWs3(const String& filename, uint8_t num);
|
||||
void sendFileToWs4(const String& filename, uint8_t num);
|
||||
@@ -44,11 +44,7 @@ void setup() {
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
//выводим остаток оперативной памяти после старта
|
||||
// 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
|
||||
// readFileBin("/config.json");
|
||||
|
||||
//создали задачу которая будет выполняться каждые 30 секунд
|
||||
ts.add(
|
||||
|
||||
@@ -215,12 +215,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
if (payloadStr.startsWith("/config")) {
|
||||
//если прилетел url страницы /config то отправим widgets.json и config.json
|
||||
|
||||
// не нравится мне это, нужно что бы класс строил очередь и отправлял вначале первый файл потом второй
|
||||
// очередь задавалась бы так: /widgets.json,/config.json,
|
||||
// хорошая идея на завтра)
|
||||
#ifdef QUEUE_FROM_STR
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
||||
// sendFileToWs2("/widgets.json", num);
|
||||
sendFileToWs4("/config.json", num);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -282,3 +279,78 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void sendFileToWs(const String& filename, uint8_t num) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
SerialPrint(F("E"), F("FS"), F("reed file error"));
|
||||
}
|
||||
|
||||
size_t fileSize = file.size();
|
||||
|
||||
uint8_t bufuint[fileSize];
|
||||
|
||||
SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
||||
|
||||
long st = millis();
|
||||
int i = 0;
|
||||
while (file.available()) {
|
||||
bufuint[i] = file.read();
|
||||
i++;
|
||||
yield();
|
||||
}
|
||||
long end = millis();
|
||||
SerialPrint(F("i"), F("WS"), "Time '" + String(end - st));
|
||||
|
||||
standWebSocket.sendTXT(num, bufuint, i);
|
||||
}
|
||||
|
||||
void sendFileToWs2(const String& filename, uint8_t num) {
|
||||
String file = readFile(filename, 5000);
|
||||
size_t fileSize = sizeof(file);
|
||||
SerialPrint(F("i"), F("WS"), String(fileSize));
|
||||
standWebSocket.sendTXT(num, file);
|
||||
}
|
||||
|
||||
void sendFileToWs3(const String& filename, uint8_t num) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
SerialPrint(F("E"), F("FS"), F("reed file error"));
|
||||
}
|
||||
|
||||
size_t fileSize = file.size();
|
||||
|
||||
SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
||||
|
||||
String ret;
|
||||
ret.reserve(file.size() - file.position());
|
||||
char temp[256 + 1];
|
||||
int countRead = file.readBytes(temp, sizeof(temp) - 1);
|
||||
while (countRead > 0) {
|
||||
temp[countRead] = 0;
|
||||
ret += temp;
|
||||
countRead = file.readBytes(temp, sizeof(temp) - 1);
|
||||
}
|
||||
|
||||
standWebSocket.sendTXT(num, ret);
|
||||
}
|
||||
|
||||
void sendFileToWs4(const String& filename, uint8_t num) {
|
||||
size_t ws_buffer = 1024;
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
SerialPrint(F("E"), F("FS"), F("reed file error"));
|
||||
}
|
||||
size_t fileSize = file.size();
|
||||
SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
||||
char temp[ws_buffer + 1];
|
||||
int countRead = file.readBytes(temp, sizeof(temp) - 1);
|
||||
while (countRead > 0) {
|
||||
temp[countRead] = 0;
|
||||
standWebSocket.sendTXT(num, temp, countRead);
|
||||
countRead = file.readBytes(temp, sizeof(temp) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ void SendJson::addFileToQueue(String path, uint8_t num) {
|
||||
SerialPrint(F("i"), F("WS"), "file added to Queue " + path);
|
||||
}
|
||||
|
||||
//опсылает массив json по объектно в сокеты
|
||||
void SendJson::loop() {
|
||||
if (!filesQueue->empty() && !sendingInProgress) {
|
||||
Serial.println("Queue not empty");
|
||||
|
||||
8
training/info.txt
Normal file
8
training/info.txt
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user