mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
ws started
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
||||
//#define OTA_UPDATES_ENABLED
|
||||
//#define MDNS_ENABLED
|
||||
//#define WEBSOCKET_ENABLED
|
||||
#define WEBSOCKET_ENABLED
|
||||
//#define LAYOUT_IN_RAM
|
||||
//#define UDP_ENABLED
|
||||
//#define SSDP_ENABLED
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WebServer.h>
|
||||
//#include <ESP8266WebServer.h>
|
||||
#include <ESP8266httpUpdate.h>
|
||||
#include "ESPAsyncTCP.h"
|
||||
#include "ESPAsyncWebServer.h"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
//===================Libraries===================================================================================================================================================
|
||||
#include "Consts.h"
|
||||
#include <Arduino.h>
|
||||
#include "CTBot.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <PubSubClient.h>
|
||||
@@ -10,13 +8,15 @@
|
||||
#include <TickerScheduler.h>
|
||||
#include <Wire.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "CTBot.h"
|
||||
#include "Clock.h"
|
||||
#include "Consts.h"
|
||||
#include "ESP32.h"
|
||||
#include "ESP8266.h"
|
||||
#include "GyverFilters.h"
|
||||
#include "MqttClient.h"
|
||||
#include "Upgrade.h"
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/SerialPrint.h"
|
||||
@@ -26,25 +26,20 @@
|
||||
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
extern AsyncWebSocket ws;
|
||||
//extern AsyncEventSource events;
|
||||
extern AsyncEventSource events;
|
||||
#endif
|
||||
|
||||
|
||||
extern TickerScheduler ts;
|
||||
extern WiFiClient espClient;
|
||||
extern PubSubClient mqtt;
|
||||
extern StringCommand sCmd;
|
||||
extern AsyncWebServer server;
|
||||
|
||||
|
||||
|
||||
//Global vars
|
||||
// Global vars
|
||||
extern boolean just_load;
|
||||
extern boolean telegramInitBeen;
|
||||
extern boolean savedFromWeb;
|
||||
|
||||
|
||||
|
||||
// Json
|
||||
extern String configSetupJson; //все настройки
|
||||
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
|
||||
@@ -70,14 +65,14 @@ extern int mqttConnectAttempts;
|
||||
extern bool changeBroker;
|
||||
extern int currentBroker;
|
||||
|
||||
//orders and events
|
||||
// orders and events
|
||||
extern String orderBuf;
|
||||
extern String eventBuf;
|
||||
extern String mysensorBuf;
|
||||
extern String itemsFile;
|
||||
extern String itemsLine;
|
||||
|
||||
//key lists and numbers
|
||||
// key lists and numbers
|
||||
//=========================================
|
||||
extern String impuls_KeyList;
|
||||
extern int impuls_EnterCounter;
|
||||
@@ -101,12 +96,9 @@ extern String logging_KeyList;
|
||||
extern int logging_EnterCounter;
|
||||
//=========================================
|
||||
|
||||
|
||||
|
||||
extern String itemName;
|
||||
extern String presetName;
|
||||
|
||||
|
||||
extern int scenario_line_status[40];
|
||||
extern int lastVersion;
|
||||
|
||||
@@ -122,11 +114,11 @@ extern void servo_();
|
||||
|
||||
extern void setLedStatus(LedStatus_t);
|
||||
|
||||
//Scenario
|
||||
// Scenario
|
||||
extern void eventGen2(String eventName, String eventValue);
|
||||
extern String add_set(String param_name);
|
||||
|
||||
//Timers
|
||||
// Timers
|
||||
extern void Timer_countdown_init();
|
||||
extern void timerStart_();
|
||||
extern void addTimer(String number, String time);
|
||||
@@ -146,9 +138,9 @@ extern void createChart(String widget_name, String page_name, String page_number
|
||||
extern void pushControl();
|
||||
|
||||
// UDP
|
||||
//extern void udpInit();
|
||||
//extern void do_udp_data_parse();
|
||||
//extern void do_mqtt_send_settings_to_udp();
|
||||
// extern void udpInit();
|
||||
// extern void do_udp_data_parse();
|
||||
// extern void do_mqtt_send_settings_to_udp();
|
||||
|
||||
extern void do_update();
|
||||
|
||||
@@ -159,4 +151,4 @@ extern void uptime_init();
|
||||
extern void web_init();
|
||||
|
||||
// Upgrade
|
||||
extern String serverIP;
|
||||
extern String serverIP;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "HttpServer.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "FSEditor.h"
|
||||
#include "HttpServer.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/WebUtils.h"
|
||||
#include "FSEditor.h"
|
||||
|
||||
AsyncWebSocket ws("/ws");
|
||||
AsyncEventSource events("/events");
|
||||
namespace HttpServer {
|
||||
|
||||
|
||||
/* Forward declaration */
|
||||
void initOta();
|
||||
void initMDNS();
|
||||
@@ -34,17 +34,17 @@ void init() {
|
||||
#endif
|
||||
|
||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||
SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request));
|
||||
SerialPrint("[E]", "WebServer", "not found:\n" + getRequestInfo(request));
|
||||
request->send(404);
|
||||
});
|
||||
|
||||
server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||
// TODO
|
||||
if (!index) {
|
||||
SerialPrint("I","WebServer","start upload " + filename);
|
||||
SerialPrint("I", "WebServer", "start upload " + filename);
|
||||
}
|
||||
if (final) {
|
||||
SerialPrint("I","WebServer","finish upload: " + prettyBytes(index + len));
|
||||
SerialPrint("I", "WebServer", "finish upload: " + prettyBytes(index + len));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,13 +69,11 @@ void init() {
|
||||
|
||||
server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
String cmdStr = request->getParam("command")->value();
|
||||
SerialPrint("I","WebServer","do: " + cmdStr);
|
||||
SerialPrint("I", "WebServer", "do: " + cmdStr);
|
||||
loopCmdAdd(cmdStr);
|
||||
request->send(200, "text/html", "OK");
|
||||
});
|
||||
|
||||
|
||||
|
||||
server.begin();
|
||||
|
||||
initOta();
|
||||
@@ -90,7 +88,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
|
||||
client->printf(json.c_str(), client->id());
|
||||
//client->ping();
|
||||
// client->ping();
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
|
||||
} else if (type == WS_EVT_ERROR) {
|
||||
@@ -101,7 +99,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
AwsFrameInfo *info = (AwsFrameInfo *)arg;
|
||||
String msg = "";
|
||||
if (info->final && info->index == 0 && info->len == len) {
|
||||
//the whole message is in a single frame and we got all of it's data
|
||||
// the whole message is in a single frame and we got all of it's data
|
||||
Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT) ? "text" : "binary", info->len);
|
||||
|
||||
if (info->opcode == WS_TEXT) {
|
||||
@@ -122,7 +120,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
else
|
||||
client->binary("{}");
|
||||
} else {
|
||||
//message is comprised of multiple frames or the frame is split into multiple packets
|
||||
// message is comprised of multiple frames or the frame is split into multiple packets
|
||||
if (info->index == 0) {
|
||||
if (info->num == 0)
|
||||
Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
|
||||
|
||||
@@ -79,13 +79,13 @@ void setup() {
|
||||
|
||||
getFSInfo();
|
||||
|
||||
//testsPerform();
|
||||
// testsPerform();
|
||||
|
||||
just_load = false;
|
||||
initialized = true;
|
||||
|
||||
const int capacity = JSON_OBJECT_SIZE(35);
|
||||
SerialPrint("I", F("Test"), String(capacity));
|
||||
// const int capacity = JSON_OBJECT_SIZE(35);
|
||||
// SerialPrint("I", F("Test"), String(capacity));
|
||||
|
||||
ts.add(
|
||||
MYTEST, 5000, [&](void*) {
|
||||
|
||||
Reference in New Issue
Block a user