mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Merge branch 'IoTManagerProject:ver4dev' into ver4dev
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"ratio": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,8 +2,8 @@
|
|||||||
"name": "IoTmanager",
|
"name": "IoTmanager",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
"routerssid": "rise",
|
"routerssid": "WLAN1-Y1GYEF",
|
||||||
"routerpass": "hostel3333",
|
"routerpass": "2egY69YTA8DDR7En",
|
||||||
"timezone": 1,
|
"timezone": 1,
|
||||||
"ntp": "pool.ntp.org",
|
"ntp": "pool.ntp.org",
|
||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ extern String paramsHeapJson;
|
|||||||
extern String orderBuf;
|
extern String orderBuf;
|
||||||
extern String eventBuf;
|
extern String eventBuf;
|
||||||
|
|
||||||
|
// wifi
|
||||||
|
extern String ssidListJson;
|
||||||
|
|
||||||
// Mqtt
|
// Mqtt
|
||||||
extern String mqttServer;
|
extern String mqttServer;
|
||||||
extern int mqttPort;
|
extern int mqttPort;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "Utils/WiFiUtils.h"
|
||||||
|
|
||||||
#ifdef STANDARD_WEB_SOCKETS
|
#ifdef STANDARD_WEB_SOCKETS
|
||||||
extern void standWebSocketsInit();
|
extern void standWebSocketsInit();
|
||||||
@@ -9,8 +10,10 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize);
|
void sendFileToWs(const char* filename, uint8_t num, size_t frameSize);
|
||||||
void publishStatusWs(const String& topic, const String& data);
|
void publishStatusWs(const String& topic, const String& data);
|
||||||
|
void sendStringToWs(const String& msg, uint8_t num, String name);
|
||||||
|
|
||||||
// void sendMark(const char* filename, const char* mark, uint8_t num);
|
// void sendMark(const char* filename, const char* mark, 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);
|
||||||
@@ -17,6 +17,7 @@ void globalVarsSync() {
|
|||||||
mqttRootDevice = mqttPrefix + "/" + chipId;
|
mqttRootDevice = mqttPrefix + "/" + chipId;
|
||||||
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
||||||
saveSettingsFlashJson();
|
saveSettingsFlashJson();
|
||||||
|
jsonWriteStr_(ssidListJson, "ssid", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSettingsFlashJson() {
|
void saveSettingsFlashJson() {
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ String paramsHeapJson = "{}"; //переменная в которой хр
|
|||||||
String orderBuf = "";
|
String orderBuf = "";
|
||||||
String eventBuf = "";
|
String eventBuf = "";
|
||||||
|
|
||||||
|
// wifi
|
||||||
|
String ssidListJson = "{}";
|
||||||
|
|
||||||
// Mqtt
|
// Mqtt
|
||||||
String mqttServer = "";
|
String mqttServer = "";
|
||||||
int mqttPort = 0;
|
int mqttPort = 0;
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ void setup() {
|
|||||||
//подключаемся к роутеру
|
//подключаемся к роутеру
|
||||||
routerConnect();
|
routerConnect();
|
||||||
|
|
||||||
|
//запустим один раз асинхронное сканирование сетей wifi для веба
|
||||||
|
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
||||||
|
|
||||||
//инициализация асинхронного веб сервера и веб сокетов
|
//инициализация асинхронного веб сервера и веб сокетов
|
||||||
#ifdef ASYNC_WEB_SERVER
|
#ifdef ASYNC_WEB_SERVER
|
||||||
asyncWebServerInit();
|
asyncWebServerInit();
|
||||||
|
|||||||
@@ -31,27 +31,36 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
// dashboard===================================================================
|
// dashboard===================================================================
|
||||||
if (headerStr == "/") {
|
if (headerStr == "/") {
|
||||||
sendFileToWs5("/layout.json", num, 1024);
|
sendFileToWs("/layout.json", num, 1024);
|
||||||
}
|
}
|
||||||
if (headerStr == "/tuoyal") {
|
if (headerStr == "/tuoyal") {
|
||||||
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
|
||||||
}
|
}
|
||||||
// configutation===============================================================
|
// configutation===============================================================
|
||||||
if (headerStr == "/config") {
|
if (headerStr == "/config") {
|
||||||
sendFileToWs5("/items.json", num, 1024);
|
sendFileToWs("/items.json", num, 1024);
|
||||||
sendFileToWs5("/widgets.json", num, 1024);
|
sendFileToWs("/widgets.json", num, 1024);
|
||||||
sendFileToWs5("/config.json", num, 1024);
|
sendFileToWs("/config.json", num, 1024);
|
||||||
sendFileToWs5("/settings.json", num, 1024);
|
sendFileToWs("/settings.json", num, 1024);
|
||||||
}
|
}
|
||||||
if (headerStr == "/gifnoc") {
|
if (headerStr == "/gifnoc") {
|
||||||
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
||||||
}
|
}
|
||||||
// connection===================================================================
|
// connection===================================================================
|
||||||
if (headerStr == "/connec") {
|
if (headerStr == "/connec") {
|
||||||
sendFileToWs5("/settings.json", num, 1024);
|
sendFileToWs("/settings.json", num, 1024);
|
||||||
|
if (RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")))) {
|
||||||
|
standWebSocket.sendTXT(num, ssidListJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (headerStr == "/scan") {
|
||||||
|
if (RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")))) {
|
||||||
|
standWebSocket.sendTXT(num, ssidListJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (headerStr == "/cennoc") {
|
if (headerStr == "/cennoc") {
|
||||||
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
||||||
|
settingsFlashJson = readFile(F("settings.json"), 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
@@ -109,7 +118,7 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//посылка данных из файла в бинарном виде
|
//посылка данных из файла в бинарном виде
|
||||||
void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize) {
|
void sendFileToWs(const char* filename, uint8_t num, size_t frameSize) {
|
||||||
standWebSocket.sendTXT(num, "/st" + String(filename));
|
standWebSocket.sendTXT(num, "/st" + String(filename));
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = FileFS.open(path, "r");
|
auto file = FileFS.open(path, "r");
|
||||||
@@ -129,6 +138,7 @@ void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize) {
|
|||||||
standWebSocket.sendTXT(num, "/end" + String(filename));
|
standWebSocket.sendTXT(num, "/end" + String(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//публикация статус сообщений
|
||||||
void publishStatusWs(const String& topic, const String& data) {
|
void publishStatusWs(const String& topic, const String& data) {
|
||||||
String path = mqttRootDevice + "/" + topic; //+ "/status";
|
String path = mqttRootDevice + "/" + topic; //+ "/status";
|
||||||
String json = "{}";
|
String json = "{}";
|
||||||
@@ -137,6 +147,16 @@ void publishStatusWs(const String& topic, const String& data) {
|
|||||||
standWebSocket.broadcastTXT(json);
|
standWebSocket.broadcastTXT(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//посылка данных из string
|
||||||
|
void sendStringToWs(const String& msg, uint8_t num, String name) {
|
||||||
|
standWebSocket.sendTXT(num, "/st" + String(name));
|
||||||
|
size_t size = msg.length();
|
||||||
|
char dataArray[size];
|
||||||
|
msg.toCharArray(dataArray, size);
|
||||||
|
standWebSocket.sendBIN(num, (uint8_t*)dataArray, size);
|
||||||
|
standWebSocket.sendTXT(num, "/end" + String(name));
|
||||||
|
}
|
||||||
|
|
||||||
// void sendMark(const char* filename, const char* mark, uint8_t num) {
|
// void sendMark(const char* filename, const char* mark, uint8_t num) {
|
||||||
// char outChar[strlen(filename) + strlen(mark) + 1];
|
// char outChar[strlen(filename) + strlen(mark) + 1];
|
||||||
// strcpy(outChar, mark);
|
// strcpy(outChar, mark);
|
||||||
|
|||||||
@@ -103,9 +103,12 @@ boolean RouterFind(String ssid) {
|
|||||||
if (WiFi.SSID(i) == ssid) {
|
if (WiFi.SSID(i) == ssid) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
SerialPrint("i", "WIFI", (res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
|
// SerialPrint("i", "WIFI", (res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
|
||||||
|
jsonWriteStr_(ssidListJson, String(i), WiFi.SSID(i));
|
||||||
|
// String(WiFi.RSSI(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user