добавил меню подключение

This commit is contained in:
Dmitry Borisenko
2022-02-02 23:39:41 +01:00
parent bd1d25d79a
commit 0540ea5b04
8 changed files with 74 additions and 110 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -12,10 +12,5 @@
"mqttPort": 8021,
"mqttPrefix": "/ver4test",
"mqttUser": "rise",
"mqttPass": "hostel3333",
"mqttServer2": "",
"mqttPort2": 0,
"mqttPrefix2": "",
"mqttUser2": "",
"mqttPass2": ""
"mqttPass": "hostel3333"
}

View File

@@ -1,94 +0,0 @@
[
{
"type": "Variable",
"subtype": "ButtonOut",
"id": "btn1",
"widget": "toggle",
"page": "Кнопки",
"descr": "Освещение",
"gpio": 13,
"inv": false
},
{
"type": "Variable",
"subtype": "PwmOut",
"id": "pwm1",
"widget": "range",
"page": "Регуляторы",
"descr": "Освещение",
"gpio": 14,
"inv": false
},
{
"type": "Reading",
"subtype": "ButtonIn",
"id": "btn",
"widget": "toggle",
"page": "Кнопки",
"descr": "Освещение",
"gpio": 12,
"inv": false
},
{
"type": "Reading",
"subtype": "OutputValue",
"id": "txt",
"widget": "anydataRed",
"page": "Предупреждения",
"descr": "Статус"
},
{
"type": "Reading",
"subtype": "InputValue",
"id": "txt",
"widget": "inputDgt",
"page": "Лимиты",
"descr": "Порог"
},
{
"type": "Reading",
"subtype": "Bme280",
"id": "t",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура"
},
{
"type": "Reading",
"subtype": "Bme280",
"id": "p",
"widget": "anydataMm",
"page": "Сенсоры",
"descr": "Давление"
},
{
"type": "Reading",
"subtype": "Bme280",
"id": "h",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"int": 10,
"addr": "0x78"
},
{
"type": "Reading",
"subtype": "AnalogAdc",
"id": "t1",
"widget": "anydataDef",
"page": "Сенсоры",
"descr": "Температура",
"pin": 0,
"int": 10
},
{
"type": "Reading",
"subtype": "AnalogAdc",
"id": "t2",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"pin": 0,
"int": 15
}
]

View File

@@ -26,5 +26,12 @@ extern FS* filesystem;
extern bool fileSystemInit();
extern void globalVarsSync();
void saveSettingsFlashJson();
void saveParamsFlashJson();
extern void saveSettingsFlashJson();
extern void saveParamsFlashJson();
extern const String getChipId();
extern void setChipId();
extern const String getUniqueId(const char* name);
extern uint32_t ESP_getChipId(void);
extern uint32_t ESP_getFlashChipId(void);
extern const String getMacAddress();

View File

@@ -20,4 +20,52 @@ void saveSettingsFlashJson() {
void saveParamsFlashJson() {
writeFile(F("params.json"), paramsFlashJson);
}
const String getChipId() {
return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId());
}
void setChipId() {
chipId = getChipId();
SerialPrint("I", "System", "id: " + chipId);
}
const String getUniqueId(const char* name) {
return String(name) + getMacAddress();
}
uint32_t ESP_getChipId(void) {
#ifdef ESP32
uint32_t id = 0;
for (uint32_t i = 0; i < 17; i = i + 8) {
id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return id;
#else
return ESP.getChipId();
#endif
}
uint32_t ESP_getFlashChipId(void) {
#ifdef ESP32
// Нет аналогичной (без доп.кода) функций в 32
// надо использовать другой id - варианты есть
return ESP_getChipId();
#else
return ESP.getFlashChipId();
#endif
}
const String getMacAddress() {
uint8_t mac[6];
char buf[13] = {0};
#if defined(ESP8266)
WiFi.macAddress(mac);
sprintf(buf, MACSTR, MAC2STR(mac));
#else
esp_read_mac(mac, ESP_MAC_WIFI_STA);
sprintf(buf, MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#endif
return String(buf);
}

View File

@@ -12,6 +12,9 @@ void setup() {
//инициализация файловой системы
fileSystemInit();
//получение chip id
setChipId();
//синхронизация глобальных переменных с flash
globalVarsSync();

View File

@@ -29,23 +29,28 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
for (size_t i = 0; i < headerLenth; i++) {
headerStr += (char)payload[i];
}
// dashboard===================================================================
if (headerStr == "/") {
sendFileToWs5("/layout.json", num, 1024);
}
if (headerStr == "/tuoyal") {
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
}
// configutation===============================================================
if (headerStr == "/config") {
sendFileToWs5("/items.json", num, 1024);
sendFileToWs5("/widgets.json", num, 1024);
sendFileToWs5("/config.json", num, 1024);
}
if (headerStr == "/gifnoc") {
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
}
if (headerStr == "/tuoyal") {
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
// connection===================================================================
if (headerStr == "/connec") {
sendFileToWs5("/settings.json", num, 1024);
}
if (headerStr == "/cennoc") {
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
}
} break;