версия с решенными вопросами api взаимодействия веба

This commit is contained in:
Dmitry Borisenko
2022-01-30 17:44:45 +01:00
parent 5c6b50f40a
commit b9d8443724
4 changed files with 310 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,280 @@
[
{
"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",
"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",
"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",
"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",

View File

@@ -221,8 +221,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
}
if (headerStr == "/config") {
sendFileToWs5("/widgets.json", num, 1024);
sendFileToWs5("/config.json", num, 1024);
sendFileToWs5("/widgets.json", num, 128);
sendFileToWs5("/config.json", num, 128);
}
if (headerStr == "/gifnoc") {
@@ -285,7 +285,7 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
//посылка данных из файла в бинарном виде
void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize) {
sendMark(filename, "/st", num);
standWebSocket.sendTXT(num, "/st" + String(filename));
String path = filepath(filename);
auto file = FileFS.open(path, "r");
if (!file) {
@@ -294,14 +294,14 @@ void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize) {
}
size_t fileSize = file.size();
SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize));
uint8_t payload[frameSize + 1];
int countRead = file.read(payload, sizeof(payload) - 1);
uint8_t payload[frameSize];
int countRead = file.read(payload, sizeof(payload));
while (countRead > 0) {
payload[countRead] = 0;
standWebSocket.sendBIN(num, payload, countRead);
countRead = file.read(payload, sizeof(payload) - 1);
countRead = file.read(payload, sizeof(payload));
}
sendMark(filename, "/end", num);
file.close();
standWebSocket.sendTXT(num, "/end" + String(filename));
}
void sendMark(const char* filename, const char* mark, uint8_t num) {

View File

@@ -23,6 +23,31 @@ void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, size_t l
file.close();
}
//данная функция читает из файла страницами указанного размера
// void readFileUint8tByFrames(const String& filename, size_t frameSize) {
// String path = filepath(filename);
// auto file = FileFS.open(path, "r");
// if (!file) {
// Serial.println(F("failed read file Uint8tByFrames"));
// return;
// }
// size_t length = file.size();
// size_t read{0};
// while (length > read) {
// size_t size = length - read;
// if (size > frameSize) size = frameSize;
// uint8_t p[size];
// size_t res = file.read(p, size);
// //
// if (size != res) {
// break;
// }
// read += res;
// yield();
// }
// file.close();
//}
void writeFileUint8tByByte(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth) {
String path = filepath(filename);
auto file = FileFS.open(path, "w");