mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-05-26 04:39:22 +03:00
First working platformio version
This commit is contained in:
11
src/Cmd.cpp
11
src/Cmd.cpp
@@ -1,11 +1,6 @@
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
|
||||
#include "Scenario.h"
|
||||
#include "TimeUtils.h"
|
||||
#include "Widgets.h"
|
||||
#include "main.h"
|
||||
#include "push_pushingbox.h"
|
||||
#include "set.h"
|
||||
|
||||
void CMD_init() {
|
||||
sCmd.addCommand("button", button);
|
||||
@@ -74,8 +69,8 @@ void CMD_init() {
|
||||
sCmd.addCommand("inputTime", inputTime);
|
||||
sCmd.addCommand("timeSet", timeSet);
|
||||
|
||||
sCmd.addCommand("timerStart", timerStart);
|
||||
sCmd.addCommand("timerStop", timerStop);
|
||||
sCmd.addCommand("timerStart", timerStart_);
|
||||
sCmd.addCommand("timerStop", timerStop_);
|
||||
|
||||
sCmd.addCommand("text", text);
|
||||
sCmd.addCommand("textSet", textSet);
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
|
||||
#include <FS.h>
|
||||
#include <SPIFFS.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void File_system_init() {
|
||||
Serial.begin(115200);
|
||||
|
||||
11
src/Init.cpp
11
src/Init.cpp
@@ -1,11 +1,4 @@
|
||||
#include "Init.h"
|
||||
|
||||
#include "Logging.h"
|
||||
#include "Scenario.h"
|
||||
#include "Timers.h"
|
||||
#include "Widgets.h"
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void All_init() {
|
||||
server.on("/init", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
@@ -73,7 +66,7 @@ void Device_init() {
|
||||
|
||||
int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
|
||||
|
||||
for (int i = 0; i <= array_sz; i++) {
|
||||
for (int i = 0; i < array_sz; i++) {
|
||||
sensors_reading_map[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#include "Logging.h"
|
||||
#include "Global.h"
|
||||
|
||||
#include "Mqtt.h"
|
||||
#include "TimeUtils.h"
|
||||
#include "Widgets.h"
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
void sendLogData(String file, String topic);
|
||||
|
||||
#ifdef logging_enable
|
||||
//===============================================Логирование============================================================
|
||||
@@ -105,7 +101,8 @@ void choose_log_date_and_send() {
|
||||
String all_line = logging_value_names_list;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
sendLogData("log." + tmp + ".txt", tmp + "_ch");
|
||||
sendLogData("log." + tmp + ".txt", tmp + "_ch"
|
||||
);
|
||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||
}
|
||||
all_line = "";
|
||||
|
||||
15
src/Mqtt.cpp
15
src/Mqtt.cpp
@@ -1,10 +1,11 @@
|
||||
#include "Mqtt.h"
|
||||
#include "Global.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
void callback(char* topic, byte* payload, unsigned int length);
|
||||
String stateMQTT();
|
||||
void sendAllData();
|
||||
void sendAllWigets();
|
||||
void sendSTATUS(String topik, String state);
|
||||
void outcoming_date();
|
||||
|
||||
//===============================================ИНИЦИАЛИЗАЦИЯ================================================
|
||||
void MQTT_init() {
|
||||
@@ -217,7 +218,7 @@ void sendAllWigets() {
|
||||
}
|
||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String widget_to_send = configFile.readStringUntil("\r\n");
|
||||
String widget_to_send = configFile.readStringUntil('\n');
|
||||
Serial.println("[V] " + widget_to_send);
|
||||
sendMQTT("config", widget_to_send);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "Scenario.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void handleScenario() {
|
||||
if (jsonReadStr(configSetup, "scenario") == "1") {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "Sensors.h"
|
||||
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void sensors_init() {
|
||||
ts.add(
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "TimeUtils.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void Time_Init() {
|
||||
server.on("/time", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#include "Timers.h"
|
||||
|
||||
#include "Scenario.h"
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void Timer_countdown_init() {
|
||||
ts.add(
|
||||
@@ -33,7 +29,7 @@ void Timer_countdown_init() {
|
||||
nullptr, true);
|
||||
}
|
||||
|
||||
void timerStart() {
|
||||
void timerStart_() {
|
||||
String number = sCmd.next();
|
||||
String period_of_time = sCmd.next();
|
||||
String type = sCmd.next();
|
||||
@@ -64,7 +60,7 @@ void addTimer(String number, String time) {
|
||||
//Serial.println("ura");
|
||||
}
|
||||
|
||||
void timerStop() {
|
||||
void timerStop_() {
|
||||
String number = sCmd.next();
|
||||
delTimer(number);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "Upgrade.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
static const char* UPGRADE_URL PROGMEM = "http://91.204.228.124:1100/update/";
|
||||
|
||||
@@ -20,11 +17,11 @@ void initUpgrade() {
|
||||
String last_version = WiFi.status() == WL_CONNECTED ? getURL(getUpgradeUrl()) : "";
|
||||
jsonWriteStr(configSetup, "last_version", last_version);
|
||||
|
||||
Serial.printf("[i] Last firmware version: %s\n", last_version);
|
||||
Serial.printf("[i] Last firmware version: %s\n", last_version.c_str());
|
||||
|
||||
server.on("/check", HTTP_GET, [last_version](AsyncWebServerRequest* request) {
|
||||
upgrade_url = true;
|
||||
Serial.printf("[i] Last firmware version: %s\n", last_version);
|
||||
Serial.printf("[i] Last firmware version: %s\n", last_version.c_str());
|
||||
String tmp = "{}";
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
if (mb_4_of_memory) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void Web_server_init() {
|
||||
#ifdef OTA_enable
|
||||
|
||||
@@ -1,53 +1,64 @@
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void WIFI_init() {
|
||||
boolean RouterFind(String ssid);
|
||||
|
||||
void WIFI_init()
|
||||
{
|
||||
// --------------------Получаем ssid password со страницы
|
||||
server.on("/ssid", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (request->hasArg("ssid")) {
|
||||
server.on("/ssid", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
if (request->hasArg("ssid"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "ssid", request->getParam("ssid")->value());
|
||||
}
|
||||
if (request->hasArg("password")) {
|
||||
if (request->hasArg("password"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "password", request->getParam("password")->value());
|
||||
}
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
});
|
||||
// --------------------Получаем ssidAP passwordAP со страницы
|
||||
server.on("/ssidap", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (request->hasArg("ssidAP")) {
|
||||
server.on("/ssidap", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
if (request->hasArg("ssidAP"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "ssidAP", request->getParam("ssidAP")->value());
|
||||
}
|
||||
if (request->hasArg("passwordAP")) {
|
||||
if (request->hasArg("passwordAP"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "passwordAP", request->getParam("passwordAP")->value());
|
||||
}
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
});
|
||||
|
||||
// --------------------Получаем логин и пароль для web со страницы
|
||||
server.on("/web", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (request->hasArg("web_login")) {
|
||||
server.on("/web", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
if (request->hasArg("web_login"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "web_login", request->getParam("web_login")->value());
|
||||
}
|
||||
if (request->hasArg("web_pass")) {
|
||||
if (request->hasArg("web_pass"))
|
||||
{
|
||||
jsonWriteStr(configSetup, "web_pass", request->getParam("web_pass")->value());
|
||||
}
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
saveConfig(); // Функция сохранения данных во Flash
|
||||
//Web_server_init();
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
});
|
||||
|
||||
server.on("/restart", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (request->hasArg("device")) {
|
||||
if (request->getParam("device")->value() == "ok") ESP.restart();
|
||||
server.on("/restart", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
if (request->hasArg("device"))
|
||||
{
|
||||
if (request->getParam("device")->value() == "ok")
|
||||
ESP.restart();
|
||||
}
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||
});
|
||||
ROUTER_Connecting();
|
||||
}
|
||||
|
||||
void ROUTER_Connecting() {
|
||||
void ROUTER_Connecting()
|
||||
{
|
||||
led_blink("slow");
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
@@ -57,17 +68,22 @@ void ROUTER_Connecting() {
|
||||
String _password = jsonReadStr(configSetup, "password");
|
||||
//WiFi.persistent(false);
|
||||
|
||||
if (_ssid == "" && _password == "") {
|
||||
if (_ssid == "" && _password == "")
|
||||
{
|
||||
WiFi.begin();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.begin(_ssid.c_str(), _password.c_str());
|
||||
Serial.print("ssid: ");
|
||||
Serial.println(_ssid);
|
||||
}
|
||||
// Делаем проверку подключения до тех пор пока счетчик tries
|
||||
// не станет равен нулю или не получим подключение
|
||||
while (--tries && WiFi.status() != WL_CONNECTED) {
|
||||
if (WiFi.status() == WL_CONNECT_FAILED) {
|
||||
while (--tries && WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECT_FAILED)
|
||||
{
|
||||
Serial.println("[E] password is not correct");
|
||||
tries = 1;
|
||||
jsonWriteInt(optionJson, "pass_status", 1);
|
||||
@@ -77,9 +93,12 @@ void ROUTER_Connecting() {
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
StartAPMode();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("[V] WiFi connected");
|
||||
Serial.print("[V] IP address: http://");
|
||||
Serial.print(WiFi.localIP());
|
||||
@@ -90,7 +109,8 @@ void ROUTER_Connecting() {
|
||||
}
|
||||
}
|
||||
|
||||
bool StartAPMode() {
|
||||
bool StartAPMode()
|
||||
{
|
||||
Serial.println("WiFi up AP");
|
||||
WiFi.disconnect();
|
||||
|
||||
@@ -105,11 +125,13 @@ bool StartAPMode() {
|
||||
Serial.println(myIP);
|
||||
jsonWriteStr(configJson, "ip", myIP.toString());
|
||||
|
||||
if (jsonReadInt(optionJson, "pass_status") != 1) {
|
||||
if (jsonReadInt(optionJson, "pass_status") != 1)
|
||||
{
|
||||
ts.add(
|
||||
ROUTER_SEARCHING, 10 * 1000, [&](void*) {
|
||||
ROUTER_SEARCHING, 10 * 1000, [&](void *) {
|
||||
Serial.println("->try find router");
|
||||
if (RouterFind(jsonReadStr(configSetup, "ssid"))) {
|
||||
if (RouterFind(jsonReadStr(configSetup, "ssid")))
|
||||
{
|
||||
ts.remove(ROUTER_SEARCHING);
|
||||
WiFi.scanDelete();
|
||||
ROUTER_Connecting();
|
||||
@@ -121,43 +143,52 @@ bool StartAPMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean RouterFind(String ssid) {
|
||||
boolean RouterFind(String ssid)
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
int n = WiFi.scanComplete();
|
||||
Serial.println("n = " + String(n));
|
||||
if (n == -2) { //Сканирование не было запущено, запускаем
|
||||
if (n == -2)
|
||||
{ //Сканирование не было запущено, запускаем
|
||||
Serial.println("[WIFI][i] scanning has not been triggered, starting scanning");
|
||||
WiFi.scanNetworks(true, false); //async, show_hidden
|
||||
return false;
|
||||
WiFi.scanNetworks(true, false); //async, show_hidde
|
||||
}
|
||||
if (n == -1) { //Сканирование все еще выполняется
|
||||
else if (n == -1)
|
||||
{ //Сканирование все еще выполняется
|
||||
Serial.println("[WIFI][i] scanning still in progress");
|
||||
return false;
|
||||
}
|
||||
if (n == 0) { //ни одна сеть не найдена
|
||||
else if (n == 0)
|
||||
{ //ни одна сеть не найдена
|
||||
Serial.println("[WIFI][i] no any wifi sations, starting scanning");
|
||||
WiFi.scanNetworks(true, false);
|
||||
return false;
|
||||
}
|
||||
if (n > 0) {
|
||||
for (int i = 0; i <= n; i++) {
|
||||
if (WiFi.SSID(i) == ssid) {
|
||||
else if (n > 0)
|
||||
{
|
||||
for (int i = 0; i <= n; i++)
|
||||
{
|
||||
if (WiFi.SSID(i) == ssid)
|
||||
{
|
||||
WiFi.scanDelete();
|
||||
return true;
|
||||
} else {
|
||||
res = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(i);
|
||||
Serial.print(")");
|
||||
//Serial.print(ssid);
|
||||
//Serial.print("<=>");
|
||||
if (i == n) {
|
||||
if (i == n)
|
||||
{
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.println("; ");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.println("; ");
|
||||
}
|
||||
}
|
||||
}
|
||||
WiFi.scanDelete();
|
||||
return false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "Widgets.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void createWidget(String widget_name, String page_name, String page_number, String file, String topic) {
|
||||
String widget;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "i2c_bus.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void do_i2c_scanning() {
|
||||
if (i2c_scanning) {
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#include "Cmd.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Sensors.h"
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
void setup() {
|
||||
File_system_init();
|
||||
|
||||
39
src/main.cpp
39
src/main.cpp
@@ -1,6 +1,4 @@
|
||||
#include "main.h"
|
||||
|
||||
#include "set.h"
|
||||
#include "Global.h"
|
||||
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
@@ -61,6 +59,9 @@ void saveConfig() {
|
||||
writeFile("config.json", configSetup);
|
||||
}
|
||||
|
||||
//============================================================================================================
|
||||
//=============================================STRING===================================================
|
||||
|
||||
// --------Выделяем строку от конца строки до маркера-----------------------------------------------------------
|
||||
String selectToMarkerLast(String str, String found) {
|
||||
int p = str.lastIndexOf(found);
|
||||
@@ -121,25 +122,24 @@ int count(String str, String found) {
|
||||
return i; // Достигли пустой строки и ничего не нашли
|
||||
}
|
||||
|
||||
|
||||
boolean isDigitStr(String str) {
|
||||
if (str.length() == 1) {
|
||||
return Digit(str);
|
||||
}
|
||||
if (str.length() > 1) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (!Digit(String(str.charAt(i)))) return false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (!isDigit(str.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
boolean Digit(String str) {
|
||||
if (str == "0" || str == "1" || str == "2" || str == "3" || str == "4" || str == "5" || str == "6" || str == "7" || str == "8" || str == "9") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return str.length();
|
||||
}
|
||||
|
||||
// boolean digit(String str) {
|
||||
// if (str == "0" || str == "1" || str == "2" || str == "3" || str == "4" || str == "5" || str == "6" || str == "7" || str == "8" || str == "9") {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
String getURL(String urls) {
|
||||
String answer = "";
|
||||
HTTPClient http;
|
||||
@@ -153,10 +153,10 @@ String getURL(String urls) {
|
||||
http.end();
|
||||
return answer;
|
||||
}
|
||||
//===================================================================================================================
|
||||
//===================================================================================================================
|
||||
//===========================================FILES===================================================================
|
||||
// ------------- Добавление файла -----------------------------------------------------------------------------------
|
||||
String safeDataToFile(String data, String Folder) {
|
||||
void safeDataToFile(String data, String Folder) {
|
||||
//String fileName = GetDate();
|
||||
String fileName;
|
||||
fileName.toLowerCase();
|
||||
@@ -168,6 +168,7 @@ String safeDataToFile(String data, String Folder) {
|
||||
Serial.println(fileName);
|
||||
jsonWriteStr(configJson, "test", fileName);
|
||||
}
|
||||
|
||||
// ------------- Чтение файла в строку -------------------------------------------------------------------------------
|
||||
String readFile(String fileName, size_t len) {
|
||||
File configFile = SPIFFS.open("/" + fileName, "r");
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
#include "Global.h"
|
||||
|
||||
void handleUdp_esp32();
|
||||
void add_dev_in_list(String fileName, String id, String dev_name, String ip);
|
||||
|
||||
#ifdef UDP_enable
|
||||
void UDP_init() {
|
||||
server.on("/udp", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
|
||||
Reference in New Issue
Block a user