mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
working wersion with elements
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
button 1 na Включить#все Реле 0 1
|
|
||||||
button 2 13 Прихожая Реле 0 2
|
|
||||||
button 3 14 Кухня Реле 0 3
|
|
||||||
pwm 1 3 Яркость#коредор: Реле 1023 4
|
|
||||||
pwm 2 4 Яркость#ванная: Реле 510 5
|
|
||||||
analog adc 0 Аналоговый#вход Датчики fillgauge 1 1023 1 1023 6
|
|
||||||
logging adc 1 100 Аналоговый#вход Датчики 7
|
|
||||||
|
|
||||||
//Это демо конфигурация. В ней показано как связать кнопки c помощью сценариев
|
|
||||||
//Кнопка номер 1 связана с кнопкой 2, 3 и с pwm 2
|
|
||||||
//Так же продемонстрированна система логгирования данных строкой logging
|
|
||||||
//1 - это интервал между точками в минутах, 100 это количество точек
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
button1 = 1
|
|
||||||
buttonSet 2 1
|
|
||||||
buttonSet 3 1
|
|
||||||
pwmSet 2 1024
|
|
||||||
end
|
|
||||||
button1 = 0
|
|
||||||
buttonSet 2 0
|
|
||||||
buttonSet 3 0
|
|
||||||
pwmSet 2 0
|
|
||||||
end
|
|
||||||
adc > 50
|
|
||||||
buttonSet 2 1
|
|
||||||
end
|
|
||||||
@@ -1 +1 @@
|
|||||||
button-in;id;toggle;Кнопки;Освещение;order;pin[2];db[20]
|
button-in;id;toggle;Кнопки;Освещение;order;pin;db[20]
|
||||||
@@ -1 +1 @@
|
|||||||
button-out;id;toggle;Кнопки;Освещение;order;pin[12];inv[1];st[1]
|
button-out;id;toggle;Кнопки;Освещение;order;pin;inv[1];st[1]
|
||||||
@@ -1 +1 @@
|
|||||||
button-out;id;toggle;Кнопки;Освещение;order;pin[12];st[0]
|
button-out;id;toggle;Кнопки;Освещение;order;pin;st[0]
|
||||||
@@ -1 +1 @@
|
|||||||
pwm-out;id;range;Ползунки;Яркость;order;pin[12];st[500]
|
pwm-out;id;range;Ползунки;Яркость;order;pin;st[500]
|
||||||
1
data/s.scen.txt
Normal file
1
data/s.scen.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
//
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"title": "LittleFS version: 2.3.5"
|
"title": "LittleFS version: 2.4.0"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"title": {
|
"title": {
|
||||||
"#": "Выберите элемент из списка<span class=\"caret\"></span>",
|
"#": "Выберите элемент из списка<span class=\"caret\"></span>",
|
||||||
"/set?addItem=button-out": "1.Кнопка управляющая пином",
|
"/set?addItem=button-out": "1.Кнопка управляющая пином",
|
||||||
"/set?addItem=pwm-out": "2.Широтно импульсная подуляция",
|
"/set?addItem=pwm-out": "2.Широтно импульсная модуляция(pwm)",
|
||||||
"/set?addItem=button-in": "3.Физическая кнопка",
|
"/set?addItem=button-in": "3.Физическая кнопка",
|
||||||
"/set?addItem=input-digit": "4.Окно ввода цифровых значений",
|
"/set?addItem=input-digit": "4.Окно ввода цифровых значений",
|
||||||
"/set?addItem=input-time": "5.Окно ввода времени"
|
"/set?addItem=input-time": "5.Окно ввода времени"
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
"text",
|
"text",
|
||||||
"text"
|
"text"
|
||||||
],
|
],
|
||||||
"state": "conf.csv",
|
"state": "s.conf.csv",
|
||||||
"style": "width:100%;",
|
"style": "width:100%;",
|
||||||
"action": "/set?saveItems",
|
"action": "/set?saveItems",
|
||||||
"class": "btn btn-block btn-default"
|
"class": "btn btn-block btn-default"
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"state": "dev_scen.txt",
|
"state": "s.scen.txt",
|
||||||
"style": "width:100%;height:350px",
|
"style": "width:100%;height:350px",
|
||||||
"title": "Сохранить",
|
"title": "Сохранить",
|
||||||
"action": "/set?sceninit",
|
"action": "/set?sceninit",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "Utils/TimeUtils.h"
|
#include "Utils/TimeUtils.h"
|
||||||
#include "Utils/PrintMessage.h"
|
#include "Utils/PrintMessage.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "Clock.h"
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#include "sntp.h"
|
#include "sntp.h"
|
||||||
@@ -69,7 +71,7 @@ class Clock {
|
|||||||
|
|
||||||
void startSync() {
|
void startSync() {
|
||||||
if (!_configured) {
|
if (!_configured) {
|
||||||
pm.info("sync to: " + _ntp + " timezone: " + String(_timezone));
|
//pm.info("sync to: " + _ntp + " timezone: " + String(_timezone));
|
||||||
setupSntp();
|
setupSntp();
|
||||||
_configured = true;
|
_configured = true;
|
||||||
// лучше не ждать, проверим в следующий раз
|
// лучше не ждать, проверим в следующий раз
|
||||||
@@ -77,9 +79,9 @@ class Clock {
|
|||||||
}
|
}
|
||||||
_hasSynced = hasTimeSynced();
|
_hasSynced = hasTimeSynced();
|
||||||
if (_hasSynced) {
|
if (_hasSynced) {
|
||||||
pm.info("synced " + getDateDotFormated() + " " + getTime());
|
//pm.info("synced " + getDateDotFormated() + " " + getTime());
|
||||||
} else {
|
} else {
|
||||||
pm.error("failed to obtain");
|
//pm.error("failed to obtain");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,18 @@
|
|||||||
/*
|
/*
|
||||||
* Main consts
|
* Main consts
|
||||||
*/
|
*/
|
||||||
#define FIRMWARE_VERSION "2.3.5"
|
#define FIRMWARE_VERSION "2.4.0"
|
||||||
#define NUM_BUTTONS 6
|
#define NUM_BUTTONS 6
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
#define FLASH_4MB true
|
#define FLASH_4MB true
|
||||||
|
|
||||||
#define MQTT_RECONNECT_INTERVAL 20000
|
#define MQTT_RECONNECT_INTERVAL 20000
|
||||||
|
|
||||||
#define TELEMETRY_UPDATE_INTERVAL 7200000
|
#define TELEMETRY_UPDATE_INTERVAL 7200000
|
||||||
|
|
||||||
#define DEVICE_CONFIG_FILE "conf.csv"
|
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
||||||
#define DEVICE_SCENARIO_FILE "dev_scen.txt"
|
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
||||||
|
|
||||||
#define DEFAULT_PRESET 100
|
#define DEFAULT_PRESET 100
|
||||||
#define DEFAULT_SCENARIO 100
|
#define DEFAULT_SCENARIO 100
|
||||||
|
|
||||||
@@ -26,17 +28,22 @@
|
|||||||
//#define MDNS_ENABLED
|
//#define MDNS_ENABLED
|
||||||
//#define WEBSOCKET_ENABLED
|
//#define WEBSOCKET_ENABLED
|
||||||
//#define LAYOUT_IN_RAM
|
//#define LAYOUT_IN_RAM
|
||||||
#define UDP_ENABLED
|
//#define UDP_ENABLED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sensor
|
* Sensor
|
||||||
*/
|
*/
|
||||||
#define TANK_LEVEL_SAMPLES 10
|
#define TANK_LEVEL_SAMPLES 10
|
||||||
#define LEVEL_ENABLED
|
#define LEVEL_ENABLED
|
||||||
|
|
||||||
#define ANALOG_ENABLED
|
#define ANALOG_ENABLED
|
||||||
|
|
||||||
|
|
||||||
#define DALLAS_ENABLED
|
#define DALLAS_ENABLED
|
||||||
#define DHT_ENABLED
|
#define DHT_ENABLED
|
||||||
|
|
||||||
#define BMP_ENABLED
|
#define BMP_ENABLED
|
||||||
|
|
||||||
#define BME_ENABLED
|
#define BME_ENABLED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -5,4 +5,5 @@
|
|||||||
|
|
||||||
extern void addItem(String name);
|
extern void addItem(String name);
|
||||||
extern void delAllItems();
|
extern void delAllItems();
|
||||||
extern int getNewElementNumber(String file);
|
extern uint8_t getNewElementNumber(String file);
|
||||||
|
extern uint8_t getFreePin();
|
||||||
@@ -15,3 +15,5 @@ String jsonWriteInt(String& json, String name, int value);
|
|||||||
String jsonWriteFloat(String& json, String name, float value);
|
String jsonWriteFloat(String& json, String name, float value);
|
||||||
|
|
||||||
String jsonWriteBool(String& json, String name, boolean value);
|
String jsonWriteBool(String& json, String name, boolean value);
|
||||||
|
|
||||||
|
void saveConfig();
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "Utils\StringUtils.h"
|
#include "Utils\StringUtils.h"
|
||||||
#include "Utils\TimeUtils.h"
|
#include "Utils\TimeUtils.h"
|
||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
|
||||||
#define pm PrintMessage(MODULE)
|
#define pm PrintMessage(MODULE)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
const String getChipId();
|
const String getChipId();
|
||||||
|
|
||||||
|
void setLedStatus(LedStatus_t status);
|
||||||
|
|
||||||
const String getUniqueId(const String& name);
|
const String getUniqueId(const String& name);
|
||||||
|
|
||||||
const String printMemoryStatus();
|
const String printMemoryStatus();
|
||||||
@@ -11,3 +13,5 @@ const String printMemoryStatus();
|
|||||||
const String getHeapStats();
|
const String getHeapStats();
|
||||||
|
|
||||||
const String getMacAddress();
|
const String getMacAddress();
|
||||||
|
|
||||||
|
void setChipId();
|
||||||
@@ -1,73 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "HttpServer.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "ESPAsyncWebServer.h"
|
extern String getURL(const String& urls);
|
||||||
|
extern const String getMethodName(AsyncWebServerRequest* request);
|
||||||
const String getMethodName(AsyncWebServerRequest* request) {
|
extern const String getRequestInfo(AsyncWebServerRequest* request);
|
||||||
String res = F("UNKNOWN");
|
|
||||||
if (request->method() == HTTP_GET)
|
|
||||||
res = F("GET");
|
|
||||||
else if (request->method() == HTTP_POST)
|
|
||||||
res = F("POST");
|
|
||||||
else if (request->method() == HTTP_DELETE)
|
|
||||||
res = F("DELETE");
|
|
||||||
else if (request->method() == HTTP_PUT)
|
|
||||||
res = F("PUT");
|
|
||||||
else if (request->method() == HTTP_PATCH)
|
|
||||||
res = F("PATCH");
|
|
||||||
else if (request->method() == HTTP_HEAD)
|
|
||||||
res = F("HEAD");
|
|
||||||
else if (request->method() == HTTP_OPTIONS)
|
|
||||||
res = F("OPTIONS");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
const String getRequestInfo(AsyncWebServerRequest* request) {
|
|
||||||
String res = getMethodName(request);
|
|
||||||
res += ' ';
|
|
||||||
res += "http://";
|
|
||||||
res += request->host();
|
|
||||||
res += request->url();
|
|
||||||
res += '\n';
|
|
||||||
if (request->contentLength()) {
|
|
||||||
res += "content-type: ";
|
|
||||||
res += request->contentType();
|
|
||||||
res += " content-lenght: ";
|
|
||||||
res += prettyBytes(request->contentLength());
|
|
||||||
res += '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->headers()) {
|
|
||||||
res += "headers:\n";
|
|
||||||
for (size_t i = 0; i < request->headers(); i++) {
|
|
||||||
AsyncWebHeader* h = request->getHeader(i);
|
|
||||||
res += h->name();
|
|
||||||
res += '=';
|
|
||||||
res += h->value();
|
|
||||||
res += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->params()) {
|
|
||||||
res += "params:\n";
|
|
||||||
for (size_t i = 0; i < request->params(); i++) {
|
|
||||||
AsyncWebParameter* p = request->getParam(i);
|
|
||||||
if (p->isFile()) {
|
|
||||||
res += "FILE";
|
|
||||||
} else if (p->isPost()) {
|
|
||||||
res += "POST";
|
|
||||||
} else {
|
|
||||||
res += "GET";
|
|
||||||
}
|
|
||||||
res += ' ';
|
|
||||||
res += p->name();
|
|
||||||
res += ':';
|
|
||||||
res += p->value();
|
|
||||||
if (p->isFile()) {
|
|
||||||
res += " size:";
|
|
||||||
res += p->size();
|
|
||||||
}
|
|
||||||
res += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
6
include/Web.h
Normal file
6
include/Web.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
|
void web_init();
|
||||||
|
void setConfigParam(const char* param, const String& value);
|
||||||
@@ -1,39 +1,57 @@
|
|||||||
#include "DeviceList.h"
|
#include "ItemsList.h"
|
||||||
|
|
||||||
static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||||
|
|
||||||
void addItem(String name) {
|
void addItem(String name) {
|
||||||
String item = readFile("items/" + name + ".txt", 1024);
|
String item = readFile("items/" + name + ".txt", 1024);
|
||||||
item.replace("id", "id" + String(getNewElementNumber("id.txt")));
|
|
||||||
|
item.replace("id", name + String(getNewElementNumber("id.txt")));
|
||||||
item.replace("order", String(getNewElementNumber("order.txt")));
|
item.replace("order", String(getNewElementNumber("order.txt")));
|
||||||
|
item.replace("pin", "pin[" + String(getFreePin()) + "]");
|
||||||
|
|
||||||
item.replace("\r\n", "");
|
item.replace("\r\n", "");
|
||||||
item.replace("\r", "");
|
item.replace("\r", "");
|
||||||
item.replace("\n", "");
|
item.replace("\n", "");
|
||||||
addFile("conf.csv", "\n" + item);
|
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delAllItems() {
|
void delAllItems() {
|
||||||
removeFile("conf.csv");
|
removeFile(DEVICE_CONFIG_FILE);
|
||||||
addFile("conf.csv", String(firstLine));
|
addFile(DEVICE_CONFIG_FILE, String(firstLine));
|
||||||
removeFile("id.txt");
|
removeFile("id.txt");
|
||||||
removeFile("order.txt");
|
removeFile("order.txt");
|
||||||
|
removeFile("pins.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNewElementNumber(String file) {
|
uint8_t getNewElementNumber(String file) {
|
||||||
int number = readFile(file, 100).toInt();
|
uint8_t number = readFile(file, 100).toInt();
|
||||||
number++;
|
number++;
|
||||||
removeFile(file);
|
removeFile(file);
|
||||||
addFile(file, String(number));
|
addFile(file, String(number));
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t getFreePin() {
|
||||||
|
#ifdef ESP8266
|
||||||
|
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
|
||||||
|
#endif
|
||||||
|
#ifdef ESP32
|
||||||
|
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
|
||||||
|
#endif
|
||||||
|
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
|
||||||
|
uint8_t i = getNewElementNumber("pins.txt");
|
||||||
|
if (i < array_sz) {
|
||||||
|
return pins[i];
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//void do_getJsonListFromCsv() {
|
//void do_getJsonListFromCsv() {
|
||||||
// if (getJsonListFromCsvFlag) {
|
// if (getJsonListFromCsvFlag) {
|
||||||
// getJsonListFromCsvFlag = false;
|
// getJsonListFromCsvFlag = false;
|
||||||
// removeFile("items/items.json");
|
// removeFile("items/items.json");
|
||||||
// addFile("items/items.json", getJsonListFromCsv("conf.csv", 1));
|
// addFile("items/items.json", getJsonListFromCsv(DEVICE_CONFIG_FILE, 1));
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "Utils\JsonUtils.h"
|
#include "Utils\JsonUtils.h"
|
||||||
|
#include "Utils/FileUtils.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
@@ -50,3 +52,7 @@ String jsonWriteFloat(String& json, String name, float value) {
|
|||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveConfig() {
|
||||||
|
writeFile(String("config.json"), configSetupJson);
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#include "Utils/SysUtils.h"
|
#include "Utils/SysUtils.h"
|
||||||
|
#include "Utils/PrintMessage.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
|
static const char* MODULE = "Main";
|
||||||
|
|
||||||
const String getUniqueId(const char* name) {
|
const String getUniqueId(const char* name) {
|
||||||
return String(name) + getMacAddress();
|
return String(name) + getMacAddress();
|
||||||
}
|
}
|
||||||
@@ -20,6 +22,11 @@ const String getChipId() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setChipId() {
|
||||||
|
chipId = getChipId();
|
||||||
|
pm.info("id: " + chipId);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
static uint32_t total_memory = 52864;
|
static uint32_t total_memory = 52864;
|
||||||
#else
|
#else
|
||||||
@@ -69,6 +76,48 @@ const String getMacAddress() {
|
|||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
void setLedStatus(LedStatus_t status) {
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
switch (status) {
|
||||||
|
case LED_OFF:
|
||||||
|
noTone(LED_PIN);
|
||||||
|
digitalWrite(LED_PIN, HIGH);
|
||||||
|
break;
|
||||||
|
case LED_ON:
|
||||||
|
noTone(LED_PIN);
|
||||||
|
digitalWrite(LED_PIN, LOW);
|
||||||
|
break;
|
||||||
|
case LED_SLOW:
|
||||||
|
tone(LED_PIN, 1);
|
||||||
|
break;
|
||||||
|
case LED_FAST:
|
||||||
|
tone(LED_PIN, 20);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void setLedStatus(LedStatus_t status) {
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
switch (status) {
|
||||||
|
case LED_OFF:
|
||||||
|
digitalWrite(LED_PIN, HIGH);
|
||||||
|
break;
|
||||||
|
case LED_ON:
|
||||||
|
digitalWrite(LED_PIN, LOW);
|
||||||
|
break;
|
||||||
|
case LED_SLOW:
|
||||||
|
break;
|
||||||
|
case LED_FAST:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//===================================================================
|
//===================================================================
|
||||||
/*
|
/*
|
||||||
void web_print (String text) {
|
void web_print (String text) {
|
||||||
|
|||||||
88
src/Utils/WebUtils.cpp
Normal file
88
src/Utils/WebUtils.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "Utils\WebUtils.h"
|
||||||
|
#include "ESPAsyncWebServer.h"
|
||||||
|
|
||||||
|
String getURL(const String& urls) {
|
||||||
|
String res = "";
|
||||||
|
HTTPClient http;
|
||||||
|
http.begin(urls);
|
||||||
|
int httpCode = http.GET();
|
||||||
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
|
res = http.getString();
|
||||||
|
} else {
|
||||||
|
res = "error";
|
||||||
|
}
|
||||||
|
http.end();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const String getMethodName(AsyncWebServerRequest* request) {
|
||||||
|
String res = F("UNKNOWN");
|
||||||
|
if (request->method() == HTTP_GET)
|
||||||
|
res = F("GET");
|
||||||
|
else if (request->method() == HTTP_POST)
|
||||||
|
res = F("POST");
|
||||||
|
else if (request->method() == HTTP_DELETE)
|
||||||
|
res = F("DELETE");
|
||||||
|
else if (request->method() == HTTP_PUT)
|
||||||
|
res = F("PUT");
|
||||||
|
else if (request->method() == HTTP_PATCH)
|
||||||
|
res = F("PATCH");
|
||||||
|
else if (request->method() == HTTP_HEAD)
|
||||||
|
res = F("HEAD");
|
||||||
|
else if (request->method() == HTTP_OPTIONS)
|
||||||
|
res = F("OPTIONS");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String getRequestInfo(AsyncWebServerRequest* request) {
|
||||||
|
String res = getMethodName(request);
|
||||||
|
res += ' ';
|
||||||
|
res += "http://";
|
||||||
|
res += request->host();
|
||||||
|
res += request->url();
|
||||||
|
res += '\n';
|
||||||
|
if (request->contentLength()) {
|
||||||
|
res += "content-type: ";
|
||||||
|
res += request->contentType();
|
||||||
|
res += " content-lenght: ";
|
||||||
|
res += prettyBytes(request->contentLength());
|
||||||
|
res += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->headers()) {
|
||||||
|
res += "headers:\n";
|
||||||
|
for (size_t i = 0; i < request->headers(); i++) {
|
||||||
|
AsyncWebHeader* h = request->getHeader(i);
|
||||||
|
res += h->name();
|
||||||
|
res += '=';
|
||||||
|
res += h->value();
|
||||||
|
res += '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->params()) {
|
||||||
|
res += "params:\n";
|
||||||
|
for (size_t i = 0; i < request->params(); i++) {
|
||||||
|
AsyncWebParameter* p = request->getParam(i);
|
||||||
|
if (p->isFile()) {
|
||||||
|
res += "FILE";
|
||||||
|
} else if (p->isPost()) {
|
||||||
|
res += "POST";
|
||||||
|
} else {
|
||||||
|
res += "GET";
|
||||||
|
}
|
||||||
|
res += ' ';
|
||||||
|
res += p->name();
|
||||||
|
res += ':';
|
||||||
|
res += p->value();
|
||||||
|
if (p->isFile()) {
|
||||||
|
res += " size:";
|
||||||
|
res += p->size();
|
||||||
|
}
|
||||||
|
res += '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
30
src/Web.cpp
30
src/Web.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include "DeviceList.h"
|
#include "Web.h"
|
||||||
|
#include "ItemsList.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
#include "Class/NotAsinc.h"
|
#include "Class/NotAsinc.h"
|
||||||
@@ -93,17 +94,17 @@ void web_init() {
|
|||||||
loadScenario();
|
loadScenario();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("updatelist")) {
|
if (request->hasArg("updatelist")) {
|
||||||
removeFile("/dev.csv");
|
removeFile("/dev.csv");
|
||||||
addFileLn("dev.csv", "device id;device name;ip address");
|
addFileLn("dev.csv", "device id;device name;ip address");
|
||||||
request->redirect("/?set.udp");
|
request->redirect("/?set.udp");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("updatepage")) {
|
if (request->hasArg("updatepage")) {
|
||||||
request->redirect("/?set.udp");
|
request->redirect("/?set.udp");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("devname")) {
|
if (request->hasArg("devname")) {
|
||||||
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@@ -115,34 +116,37 @@ void web_init() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("routerpass")) {
|
if (request->hasArg("routerpass")) {
|
||||||
jsonWriteStr(configSetupJson, "routerpass", request->getParam("routerpass")->value());
|
jsonWriteStr(configSetupJson, "routerpass", request->getParam("routerpass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("apssid")) {
|
if (request->hasArg("apssid")) {
|
||||||
jsonWriteStr(configSetupJson, "apssid", request->getParam("apssid")->value());
|
jsonWriteStr(configSetupJson, "apssid", request->getParam("apssid")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("appass")) {
|
if (request->hasArg("appass")) {
|
||||||
jsonWriteStr(configSetupJson, "appass", request->getParam("appass")->value());
|
jsonWriteStr(configSetupJson, "appass", request->getParam("appass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("weblogin")) {
|
if (request->hasArg("weblogin")) {
|
||||||
jsonWriteStr(configSetupJson, "weblogin", request->getParam("weblogin")->value());
|
jsonWriteStr(configSetupJson, "weblogin", request->getParam("weblogin")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("webpass")) {
|
if (request->hasArg("webpass")) {
|
||||||
jsonWriteStr(configSetupJson, "webpass", request->getParam("webpass")->value());
|
jsonWriteStr(configSetupJson, "webpass", request->getParam("webpass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("timezone")) {
|
if (request->hasArg("timezone")) {
|
||||||
String timezoneStr = request->getParam("timezone")->value();
|
String timezoneStr = request->getParam("timezone")->value();
|
||||||
jsonWriteStr(configSetupJson, "timezone", timezoneStr);
|
jsonWriteStr(configSetupJson, "timezone", timezoneStr);
|
||||||
@@ -150,6 +154,7 @@ void web_init() {
|
|||||||
timeNow->setTimezone(timezoneStr.toInt());
|
timeNow->setTimezone(timezoneStr.toInt());
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("ntp")) {
|
if (request->hasArg("ntp")) {
|
||||||
String ntpStr = request->getParam("ntp")->value();
|
String ntpStr = request->getParam("ntp")->value();
|
||||||
jsonWriteStr(configSetupJson, "ntp", ntpStr);
|
jsonWriteStr(configSetupJson, "ntp", ntpStr);
|
||||||
@@ -157,7 +162,7 @@ void web_init() {
|
|||||||
timeNow->setNtpPool(ntpStr);
|
timeNow->setNtpPool(ntpStr);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("blink")) {
|
if (request->hasArg("blink")) {
|
||||||
bool value = request->getParam("blink")->value().toInt();
|
bool value = request->getParam("blink")->value().toInt();
|
||||||
jsonWriteBool(configSetupJson, "blink", value);
|
jsonWriteBool(configSetupJson, "blink", value);
|
||||||
@@ -196,13 +201,12 @@ void web_init() {
|
|||||||
myNotAsincActions->make(do_MQTTPARAMSCHANGED);
|
myNotAsincActions->make(do_MQTTPARAMSCHANGED);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("mqttsend")) {
|
if (request->hasArg("mqttsend")) {
|
||||||
myNotAsincActions->make(do_MQTTUDP);
|
myNotAsincActions->make(do_MQTTUDP);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
|
||||||
if (request->hasArg("mqttcheck")) {
|
if (request->hasArg("mqttcheck")) {
|
||||||
String buf = "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + MqttClient::getStateStr();
|
String buf = "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + MqttClient::getStateStr();
|
||||||
|
|
||||||
@@ -296,3 +300,9 @@ void web_init() {
|
|||||||
request->send(200, "text/html");
|
request->send(200, "text/html");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setConfigParam(const char* param, const String& value) {
|
||||||
|
pm.info("set " + String(param) + ": " + value);
|
||||||
|
jsonWriteStr(configSetupJson, param, value);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
75
src/main.cpp
75
src/main.cpp
@@ -3,9 +3,9 @@
|
|||||||
#include "Class/NotAsinc.h"
|
#include "Class/NotAsinc.h"
|
||||||
#include "Class/Switch.h"
|
#include "Class/Switch.h"
|
||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
#include "DeviceList.h"
|
#include "ItemsList.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "HttpServer.h"
|
#include "Utils\WebUtils.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
#include "Utils/Timings.h"
|
#include "Utils/Timings.h"
|
||||||
|
|
||||||
@@ -106,76 +106,15 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
String getURL(const String& urls) {
|
|
||||||
String res = "";
|
|
||||||
HTTPClient http;
|
|
||||||
http.begin(urls);
|
|
||||||
int httpCode = http.GET();
|
|
||||||
if (httpCode == HTTP_CODE_OK) {
|
|
||||||
res = http.getString();
|
|
||||||
} else {
|
|
||||||
res = "error";
|
|
||||||
}
|
|
||||||
http.end();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setChipId() {
|
|
||||||
chipId = getChipId();
|
|
||||||
pm.info("id: " + chipId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveConfig() {
|
|
||||||
writeFile(String("config.json"), configSetupJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setConfigParam(const char* param, const String& value) {
|
|
||||||
pm.info("set " + String(param) + ": " + value);
|
|
||||||
jsonWriteStr(configSetupJson, param, value);
|
|
||||||
saveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ESP8266
|
|
||||||
void setLedStatus(LedStatus_t status) {
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
switch (status) {
|
|
||||||
case LED_OFF:
|
|
||||||
noTone(LED_PIN);
|
|
||||||
digitalWrite(LED_PIN, HIGH);
|
|
||||||
break;
|
|
||||||
case LED_ON:
|
|
||||||
noTone(LED_PIN);
|
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
break;
|
|
||||||
case LED_SLOW:
|
|
||||||
tone(LED_PIN, 1);
|
|
||||||
break;
|
|
||||||
case LED_FAST:
|
|
||||||
tone(LED_PIN, 20);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
void setLedStatus(LedStatus_t status) {
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
switch (status) {
|
|
||||||
case LED_OFF:
|
|
||||||
digitalWrite(LED_PIN, HIGH);
|
|
||||||
break;
|
|
||||||
case LED_ON:
|
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
break;
|
|
||||||
case LED_SLOW:
|
|
||||||
break;
|
|
||||||
case LED_FAST:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void clock_init() {
|
void clock_init() {
|
||||||
timeNow = new Clock();
|
timeNow = new Clock();
|
||||||
|
|||||||
Reference in New Issue
Block a user