Version 1.22
Web interface minor redesign. Main code minor changes.
This commit is contained in:
parent
7b60f9efb3
commit
8c3b51304e
@ -31,20 +31,20 @@
|
|||||||
|
|
||||||
<p class="text">WiFi settings</p>
|
<p class="text">WiFi settings</p>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<input id="ssid" value="{{ssid}}" placeholder="SSID" label title="WiFi network name" />
|
<input class="text-inp" id="ssid" value="{{ssid}}" placeholder="SSID" label title="WiFi network name" />
|
||||||
<input id="password" value="{{password}}" onfocus="this.type='text'" type="password" placeholder="Password"
|
<input id="password" value="{{password}}" onfocus="this.type='text'" type="password" placeholder="Password"
|
||||||
autocomplete="off" label title="WiFi password" />
|
autocomplete="off" label title="WiFi password" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="text">MQTT settings</p>
|
<p class="text">MQTT settings</p>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<input id="mqttHostName" value="{{mqttHostName}}" placeholder="URL or IP" label
|
<input class="text-inp" id="mqttHostName" value="{{mqttHostName}}" placeholder="URL or IP" label
|
||||||
title="MQTT server URL or IP" />
|
title="MQTT server URL or IP" />
|
||||||
<input id="mqttHostPort" value="{{mqttHostPort}}" placeholder="Port" label title="MQTT server port" />
|
<input id="mqttHostPort" value="{{mqttHostPort}}" placeholder="Port" label title="MQTT server port" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<input id="mqttUserLogin" value="{{mqttUserLogin}}" placeholder="Login" label
|
<input class="text-inp" id="mqttUserLogin" value="{{mqttUserLogin}}" placeholder="Login" label
|
||||||
title="MQTT server user login" />
|
title="MQTT server user login" />
|
||||||
<input id="mqttUserPassword" value="{{mqttUserPassword}}" onfocus="this.type='text'" type="password"
|
<input id="mqttUserPassword" value="{{mqttUserPassword}}" onfocus="this.type='text'" type="password"
|
||||||
placeholder="Password" autocomplete="off" label title="MQTT server user password" />
|
placeholder="Password" autocomplete="off" label title="MQTT server user password" />
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
p{
|
||||||
|
margin: 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: "Gill Sans", sans-serif;
|
font-family: "Gill Sans", sans-serif;
|
||||||
background: rgb(255, 255, 255);
|
background: rgb(255, 255, 255);
|
||||||
@ -21,6 +25,21 @@ h1 {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
margin-left: 10px;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-inp {
|
||||||
|
width: 48%;
|
||||||
|
min-height: 30px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: none;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
padding: 0 10px;
|
||||||
|
color: rgb(0, 0, 0);
|
||||||
|
background: #a3e0f1;
|
||||||
|
transition: .5s;
|
||||||
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrapper {
|
.wrapper {
|
||||||
@ -39,6 +58,7 @@ input {
|
|||||||
color: rgb(0, 0, 0);
|
color: rgb(0, 0, 0);
|
||||||
background: #a3e0f1;
|
background: #a3e0f1;
|
||||||
transition: .5s;
|
transition: .5s;
|
||||||
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:hover {
|
input:hover {
|
||||||
@ -51,6 +71,8 @@ input:hover {
|
|||||||
background: rgb(65, 125, 238);
|
background: rgb(65, 125, 238);
|
||||||
color: white;
|
color: white;
|
||||||
transition: .5s;
|
transition: .5s;
|
||||||
|
margin-left: 0;
|
||||||
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
@ -65,6 +87,10 @@ input:hover {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#espnowNetName {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.wrapper.wrapper--end {
|
.wrapper.wrapper--end {
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
[env:esp8266]
|
[env:ESP8266]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@ -9,7 +9,7 @@ lib_deps =
|
|||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
me-no-dev/ESP Async WebServer@^1.2.3
|
||||||
marvinroger/AsyncMqttClient@^0.9.0
|
marvinroger/AsyncMqttClient@^0.9.0
|
||||||
|
|
||||||
[env:esp8266-ota]
|
[env:ESP8266-OTA]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@ -22,7 +22,7 @@ lib_deps =
|
|||||||
me-no-dev/ESP Async WebServer@^1.2.3
|
me-no-dev/ESP Async WebServer@^1.2.3
|
||||||
marvinroger/AsyncMqttClient@^0.9.0
|
marvinroger/AsyncMqttClient@^0.9.0
|
||||||
|
|
||||||
[env:esp32]
|
[env:ESP32]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = az-delivery-devkit-v4
|
board = az-delivery-devkit-v4
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@ -34,11 +34,11 @@ lib_deps =
|
|||||||
marvinroger/AsyncMqttClient@^0.9.0
|
marvinroger/AsyncMqttClient@^0.9.0
|
||||||
luc-github/ESP32SSDP@^1.2.0
|
luc-github/ESP32SSDP@^1.2.0
|
||||||
|
|
||||||
[env:esp32-ota]
|
[env:ESP32-OTA]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = az-delivery-devkit-v4
|
board = az-delivery-devkit-v4
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_port = 192.168.1.143
|
upload_port = 192.168.1.110
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/aZholtikov/ZHNetwork
|
https://github.com/aZholtikov/ZHNetwork
|
||||||
|
32
src/main.cpp
32
src/main.cpp
@ -34,11 +34,16 @@ void setupWebServer(void);
|
|||||||
|
|
||||||
void connectToMqtt(void);
|
void connectToMqtt(void);
|
||||||
|
|
||||||
const String firmware{"1.21"};
|
const String firmware{"1.22"};
|
||||||
|
|
||||||
String espnowNetName{"DEFAULT"};
|
String espnowNetName{"DEFAULT"};
|
||||||
|
|
||||||
String deviceName{"ESP-NOW gateway"};
|
#if defined(ESP8266)
|
||||||
|
String deviceName = "ESP-NOW gateway " + String(ESP.getChipId(), HEX);
|
||||||
|
#endif
|
||||||
|
#if defined(ESP32)
|
||||||
|
String deviceName = "ESP-NOW gateway " + String(ESP.getEfuseMac(), HEX);
|
||||||
|
#endif
|
||||||
|
|
||||||
String ssid{"SSID"};
|
String ssid{"SSID"};
|
||||||
String password{"PASSWORD"};
|
String password{"PASSWORD"};
|
||||||
@ -72,6 +77,7 @@ void setup()
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
WiFi.onEvent(onWifiEvent);
|
WiFi.onEvent(onWifiEvent);
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
||||||
#endif
|
#endif
|
||||||
@ -88,7 +94,13 @@ void setup()
|
|||||||
myNet.setOnBroadcastReceivingCallback(onEspnowMessage);
|
myNet.setOnBroadcastReceivingCallback(onEspnowMessage);
|
||||||
myNet.setOnUnicastReceivingCallback(onEspnowMessage);
|
myNet.setOnUnicastReceivingCallback(onEspnowMessage);
|
||||||
|
|
||||||
WiFi.softAP(("ESP-NOW Gateway " + myNet.getNodeMac()).c_str(), "12345678");
|
#if defined(ESP8266)
|
||||||
|
WiFi.softAP(("ESP-NOW gateway " + String(ESP.getChipId(), HEX)).c_str(), "12345678");
|
||||||
|
#endif
|
||||||
|
#if defined(ESP32)
|
||||||
|
WiFi.softAP(("ESP-NOW gateway " + String(ESP.getEfuseMac(), HEX)).c_str(), "12345678");
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t scan = WiFi.scanNetworks(false, false, 1);
|
uint8_t scan = WiFi.scanNetworks(false, false, 1);
|
||||||
String name;
|
String name;
|
||||||
int32_t rssi;
|
int32_t rssi;
|
||||||
@ -176,8 +188,8 @@ void onEspnowMessage(const char *data, const uint8_t *sender)
|
|||||||
jsonConfig["command_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/set";
|
jsonConfig["command_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/set";
|
||||||
jsonConfig["json_attributes_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/attributes";
|
jsonConfig["json_attributes_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/attributes";
|
||||||
jsonConfig["availability_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/status";
|
jsonConfig["availability_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/status";
|
||||||
jsonConfig["payload_on"] = json["reverse"] == "true" ? "OFF" : "ON";
|
jsonConfig["payload_on"] = json["payload_on"];
|
||||||
jsonConfig["payload_off"] = json["reverse"] == "true" ? "ON" : "OFF";
|
jsonConfig["payload_off"] = json["payload_off"];
|
||||||
jsonConfig["optimistic"] = "false";
|
jsonConfig["optimistic"] = "false";
|
||||||
jsonConfig["qos"] = 2;
|
jsonConfig["qos"] = 2;
|
||||||
jsonConfig["retain"] = "true";
|
jsonConfig["retain"] = "true";
|
||||||
@ -218,8 +230,8 @@ void onEspnowMessage(const char *data, const uint8_t *sender)
|
|||||||
}
|
}
|
||||||
jsonConfig["json_attributes_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/attributes";
|
jsonConfig["json_attributes_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/attributes";
|
||||||
jsonConfig["availability_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/status";
|
jsonConfig["availability_topic"] = topicPrefix + "/" + getValueName(incomingData.deviceType) + "/" + myNet.macToString(sender) + "/status";
|
||||||
jsonConfig["payload_on"] = "ON";
|
jsonConfig["payload_on"] = json["payload_on"];
|
||||||
jsonConfig["payload_off"] = "OFF";
|
jsonConfig["payload_off"] = json["payload_off"];
|
||||||
jsonConfig["optimistic"] = "false";
|
jsonConfig["optimistic"] = "false";
|
||||||
jsonConfig["qos"] = 2;
|
jsonConfig["qos"] = 2;
|
||||||
jsonConfig["retain"] = "true";
|
jsonConfig["retain"] = "true";
|
||||||
@ -326,7 +338,7 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
|
|||||||
if (String(topic) == topicPrefix + "/espnow_switch/" + mac + "/set" || String(topic) == topicPrefix + "/espnow_led/" + mac + "/set")
|
if (String(topic) == topicPrefix + "/espnow_switch/" + mac + "/set" || String(topic) == topicPrefix + "/espnow_led/" + mac + "/set")
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
json["set"] = message == "ON" ? "ON" : "OFF";
|
json["set"] = message;
|
||||||
}
|
}
|
||||||
if (String(topic) == topicPrefix + "/espnow_led/" + mac + "/brightness")
|
if (String(topic) == topicPrefix + "/espnow_led/" + mac + "/brightness")
|
||||||
{
|
{
|
||||||
@ -387,7 +399,7 @@ void sendAttributesMessage()
|
|||||||
uint32_t hours = mins / 60;
|
uint32_t hours = mins / 60;
|
||||||
uint32_t days = hours / 24;
|
uint32_t days = hours / 24;
|
||||||
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
StaticJsonDocument<sizeof(esp_now_payload_data_t::message)> json;
|
||||||
json["Type"] = "ESP-NOW Gateway";
|
json["Type"] = "ESP-NOW gateway";
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
json["MCU"] = "ESP8266";
|
json["MCU"] = "ESP8266";
|
||||||
#endif
|
#endif
|
||||||
@ -480,7 +492,7 @@ void setupWebServer()
|
|||||||
ssdpDescription += xmlNode("friendlyName", deviceName);
|
ssdpDescription += xmlNode("friendlyName", deviceName);
|
||||||
ssdpDescription += xmlNode("presentationURL", "/");
|
ssdpDescription += xmlNode("presentationURL", "/");
|
||||||
ssdpDescription += xmlNode("serialNumber", "0000000" + String(random(1000)));
|
ssdpDescription += xmlNode("serialNumber", "0000000" + String(random(1000)));
|
||||||
ssdpDescription += xmlNode("modelName", "ESP-NOW Gateway");
|
ssdpDescription += xmlNode("modelName", "ESP-NOW gateway");
|
||||||
ssdpDescription += xmlNode("modelNumber", firmware);
|
ssdpDescription += xmlNode("modelNumber", firmware);
|
||||||
ssdpDescription += xmlNode("modelURL", "https://github.com/aZholtikov/ESP-NOW-Gateway");
|
ssdpDescription += xmlNode("modelURL", "https://github.com/aZholtikov/ESP-NOW-Gateway");
|
||||||
ssdpDescription += xmlNode("manufacturer", "Alexey Zholtikov");
|
ssdpDescription += xmlNode("manufacturer", "Alexey Zholtikov");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user