добавил класс стрима массива в сокеты

This commit is contained in:
Dmitry Borisenko
2021-12-24 00:44:11 +01:00
parent d73657d39a
commit 756363397b
12 changed files with 665 additions and 0 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

559
data_svelte/config.json Normal file
View File

@@ -0,0 +1,559 @@
[
{
"type": "binary",
"subtype": "button-out",
"id": "btn1",
"gpio": 1,
"inv": false
},
{
"type": "sensor1",
"subtype": "bme280",
"units": "temp",
"id": "tmp1",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor2",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor3",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor4",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor5",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor6",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor7",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor8",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor9",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor10",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor11",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor12",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor13",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor14",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor15",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor16",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor17",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor18",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor19",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor20",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor21",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor22",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor23",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor24",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor25",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor26",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor27",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor28",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor29",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor30",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor31",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor32",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor33",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor34",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor35",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor36",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor37",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor38",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor39",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor40",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor41",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor42",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor43",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor44",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor45",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor46",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor47",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor48",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor49",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor50",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor51",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor52",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor53",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor54",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
},
{
"type": "sensor55",
"subtype": "bme280",
"units": "temp",
"id": "tmp2",
"addr": "0x48",
"int": 10,
"c": 1,
"s": 0
}
]

BIN
data_svelte/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

17
data_svelte/index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<title>Svelte app</title>
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='/build/bundle.css'>
<script defer src='/build/bundle.js'></script>
</head>
<body>
</body>
</html>

11
data_svelte/settings.json Normal file
View File

@@ -0,0 +1,11 @@
{
"name": "IoTmanager",
"apssid": "IoTmanager",
"appass": "",
"routerssid": "rise",
"routerpass": "hostel3333",
"timezone": 1,
"ntp": "pool.ntp.org",
"weblogin": "admin",
"webpass": "admin"
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "Global.h"
#include "Web.h"
#ifdef STANDARD_WEB_SERVER
extern void standWebServerInit();

21
include/Web.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include "Global.h"
class StreamJsonArray;
class StreamJsonArray {
public:
StreamJsonArray();
~StreamJsonArray();
void sendFile(String path, uint8_t num);
void loop();
private:
File file;
String _path;
uint8_t _num;
};
extern StreamJsonArray* myStreamJsonArray;

View File

@@ -5,3 +5,4 @@
#include "Utils/WiFiUtils.h"
#include "AsyncWebServer.h"
#include "StandWebServer.h"
#include "Web.h"

View File

@@ -205,6 +205,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
case WStype_TEXT: {
Serial.printf("[%u] get Text: %s\n", num, payload);
String payloadStr;
payloadStr.reserve(length + 1);
for (size_t i = 0; i < length; i++) {
payloadStr += (char)payload[i];
}
if (payloadStr.startsWith("/config")) {
if (myStreamJsonArray) myStreamJsonArray->sendFile("/config.json", num);
}
// send message to client
// standWebSocket.sendTXT(num, "message here");

25
src/Web.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include "Web.h"
StreamJsonArray::StreamJsonArray() {}
StreamJsonArray::~StreamJsonArray() {}
void StreamJsonArray::sendFile(String path, uint8_t num) {
_path = path;
_num = num;
file = seekFile(path);
// file.find("[");
}
void StreamJsonArray::loop() {
// if (ws.availableForWriteAll()) {
if (file.available()) {
String jsonArrayElement = file.readStringUntil('}') + "}";
// Serial.println(jsonArrayElement);
standWebSocket.sendTXT(_num, jsonArrayElement);
// ws.textAll(jsonArrayElement);
}
//}
}
StreamJsonArray* myStreamJsonArray;

View File

@@ -31,6 +31,8 @@ void setup() {
//подключаемся к роутеру
routerConnect();
myStreamJsonArray = new StreamJsonArray;
//выводим остаток оперативной памяти после старта
// 22.12.21 пустой код без wifi остаток = 50.28 kB
// 22.12.21 запустил wifi остаток = 48.59 kB
@@ -49,6 +51,8 @@ void loop() {
//обновление задач таскера
ts.update();
if (myStreamJsonArray) myStreamJsonArray->loop();
#ifdef STANDARD_WEB_SERVER
HTTP.handleClient();
#endif