mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
final
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@
|
||||
|
||||
namespace HttpServer {
|
||||
|
||||
void initWS();
|
||||
void init();
|
||||
|
||||
} // namespace HttpServer
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#ifdef WS_enable
|
||||
AsyncWebSocket ws;
|
||||
//AsyncEventSource events;
|
||||
AsyncEventSource events;
|
||||
#endif
|
||||
|
||||
TickerScheduler ts(MYTEST + 1);
|
||||
@@ -12,8 +12,8 @@ StringCommand sCmd;
|
||||
AsyncWebServer server(80);
|
||||
|
||||
/*
|
||||
* Global vars
|
||||
*/
|
||||
* Global vars
|
||||
*/
|
||||
|
||||
boolean just_load = true;
|
||||
boolean telegramInitBeen = false;
|
||||
@@ -43,14 +43,14 @@ int mqttConnectAttempts = 0;
|
||||
bool changeBroker = false;
|
||||
int currentBroker = 1;
|
||||
|
||||
//orders and events
|
||||
// orders and events
|
||||
String orderBuf = "";
|
||||
String eventBuf = "";
|
||||
String mysensorBuf = "";
|
||||
String itemsFile = "";
|
||||
String itemsLine = "";
|
||||
|
||||
//key lists and numbers
|
||||
// key lists and numbers
|
||||
//=========================================
|
||||
String impuls_KeyList = "";
|
||||
int impuls_EnterCounter = -1;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "Utils\SerialPrint.h"
|
||||
|
||||
#include "Global.h"
|
||||
#include "HttpServer.h"
|
||||
|
||||
void SerialPrint(String errorLevel, String module, String msg) {
|
||||
//if (module == "MySensor") {
|
||||
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
|
||||
//}
|
||||
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
|
||||
|
||||
String tosend = "[" + errorLevel + "] [" + module + "] " + msg;
|
||||
|
||||
ws.textAll(tosend);
|
||||
}
|
||||
@@ -10,7 +10,6 @@ namespace HttpServer {
|
||||
/* Forward declaration */
|
||||
void initOta();
|
||||
void initMDNS();
|
||||
void initWS();
|
||||
|
||||
void init() {
|
||||
String login = jsonReadStr(configSetupJson, "weblogin");
|
||||
@@ -84,10 +83,11 @@ void init() {
|
||||
}
|
||||
|
||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||
#ifdef WS_enable
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
SerialPrint("I", F("WS"), F("CONNECTED"));
|
||||
Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
|
||||
client->printf(json.c_str(), client->id());
|
||||
// client->printf(json.c_str(), client->id());
|
||||
// client->ping();
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
|
||||
@@ -115,6 +115,13 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
}
|
||||
Serial.printf("%s\n", msg.c_str());
|
||||
|
||||
if (msg.startsWith("HELLO")) {
|
||||
SerialPrint("I", F("WS"), F("Full update"));
|
||||
// publishWidgetsWS();
|
||||
// publishStateWS();
|
||||
// choose_log_date_and_send(); // функцию выгрузки архива с графиком я не сделал. Забираю при выгрузке по MQTT
|
||||
}
|
||||
|
||||
if (info->opcode == WS_TEXT)
|
||||
client->text("{}");
|
||||
else
|
||||
@@ -198,7 +205,7 @@ void initOta() {
|
||||
}
|
||||
|
||||
void initWS() {
|
||||
#ifdef WS_enable
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
ws.onEvent(onWsEvent);
|
||||
server.addHandler(&ws);
|
||||
events.onConnect([](AsyncEventSourceClient *client) {
|
||||
@@ -206,7 +213,6 @@ void initWS() {
|
||||
});
|
||||
server.addHandler(&events);
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
} // namespace HttpServer
|
||||
29
src/main.cpp
29
src/main.cpp
@@ -9,6 +9,7 @@
|
||||
#include "Cmd.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Global.h"
|
||||
#include "HttpServer.h"
|
||||
#include "Init.h"
|
||||
#include "ItemsList.h"
|
||||
#include "MySensorsDataParse.h"
|
||||
@@ -66,6 +67,7 @@ void setup() {
|
||||
uptime_init();
|
||||
upgradeInit();
|
||||
HttpServer::init();
|
||||
HttpServer::initWS();
|
||||
web_init();
|
||||
initSt();
|
||||
busInit();
|
||||
@@ -89,32 +91,7 @@ void setup() {
|
||||
|
||||
ts.add(
|
||||
MYTEST, 5000, [&](void*) {
|
||||
Serial.println(configSetupJson.length());
|
||||
Serial.println(F("--------------------------------------"));
|
||||
|
||||
if (jsonWriteStr_(configSetupJson, "name", "test value")) {
|
||||
Serial.println("write sucsess");
|
||||
}
|
||||
|
||||
Serial.print("str test: ");
|
||||
String valueStr;
|
||||
if (jsonRead(configSetupJson, "name", valueStr)) {
|
||||
Serial.println(valueStr);
|
||||
}
|
||||
|
||||
Serial.print("int test: ");
|
||||
int valueInt;
|
||||
if (jsonRead(configSetupJson, "mqttPort", valueInt)) {
|
||||
Serial.println(valueInt);
|
||||
}
|
||||
|
||||
Serial.print("bool test: ");
|
||||
bool valueBool;
|
||||
if (jsonRead(configSetupJson, "telegonof", valueBool)) {
|
||||
Serial.println(valueBool);
|
||||
}
|
||||
|
||||
Serial.println(F("--------------------------------------"));
|
||||
// ws.textAll("test msg from esp");
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user