в процессе

This commit is contained in:
Dmitry Borisenko
2022-01-24 00:57:22 +01:00
parent 9f05eccb26
commit eca80d7dba
4 changed files with 211 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -173,6 +173,190 @@
"page": "Сенсоры", "page": "Сенсоры",
"descr": "Давление" "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", "type": "Reading",
"subtype": "Bme280", "subtype": "Bme280",

View File

@@ -25,4 +25,5 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
void sendFileToWs(const String& filename, uint8_t num); void sendFileToWs(const String& filename, uint8_t num);
void sendFileToWs2(const String& filename, uint8_t num); void sendFileToWs2(const String& filename, uint8_t num);
void sendFileToWs3(const String& filename, uint8_t num); void sendFileToWs3(const String& filename, uint8_t num);
void sendFileToWs4(const String& filename, uint8_t num); void sendFileToWs4(const String& filename, uint8_t num);
void sendFileToWs5(const String& filename, uint8_t num);

View File

@@ -14,7 +14,7 @@ void standWebServerInit() {
}); });
HTTP.on("/config.json", HTTP_GET, []() { HTTP.on("/config.json", HTTP_GET, []() {
HTTP.send(200, "application/json", readFile(F("config.json"), 5096)); HTTP.send(200, "application/json", readFile(F("config.json"), 10000));
}); });
HTTP.on("/restart", HTTP_GET, []() { HTTP.on("/restart", HTTP_GET, []() {
@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
if (payloadStr.startsWith("/config")) { if (payloadStr.startsWith("/config")) {
//если прилетел url страницы /config то отправим widgets.json и config.json //если прилетел url страницы /config то отправим widgets.json и config.json
sendFileToWs4("/widgets.json", num); sendFileToWs5("/widgets.json", num);
sendFileToWs4("/config.json", num); sendFileToWs5("/config.json", num);
} }
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
@@ -356,3 +356,24 @@ void sendFileToWs4(const String& filename, uint8_t num) {
} }
standWebSocket.sendTXT(num, "/end" + filename); standWebSocket.sendTXT(num, "/end" + filename);
} }
void sendFileToWs5(const String& filename, uint8_t num) {
standWebSocket.sendTXT(num, "/st" + filename);
// standWebSocket.createHeader();
size_t ws_buffer = 512;
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));
uint8_t payload[ws_buffer + 1];
int countRead = file.read(payload, sizeof(payload) - 1);
while (countRead > 0) {
payload[countRead] = 0;
standWebSocket.sendBIN(num, payload, countRead); //, true);
countRead = file.read(payload, sizeof(payload) - 1);
}
standWebSocket.sendTXT(num, "/end" + filename);
}