[WebUI] Completion of WiFi and MQTT Configuration (#1603)
* Configure WiFi - 1/2 working * WiFi and MQTT Configuration * Refactor MQTTtoSYS * Firmware Upgrade is Wired
This commit is contained in:
1 parent
8c7c8cc437
commit
479ac5d343
4 files changed
+385
-46
No files matched your search
+355
-29
@@ -179,6 +179,68 @@ size_t strchrspn(const char* str1, int character) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WifiGetRssiAsQuality(int rssi) {
|
||||||
|
int quality = 0;
|
||||||
|
|
||||||
|
if (rssi <= -100) {
|
||||||
|
quality = 0;
|
||||||
|
} else if (rssi >= -50) {
|
||||||
|
quality = 100;
|
||||||
|
} else {
|
||||||
|
quality = 2 * (rssi + 100);
|
||||||
|
}
|
||||||
|
return quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetTextIndexed(char* destination, size_t destination_size, uint32_t index, const char* haystack) {
|
||||||
|
// Returns empty string if not found
|
||||||
|
// Returns text of found
|
||||||
|
char* write = destination;
|
||||||
|
const char* read = haystack;
|
||||||
|
|
||||||
|
index++;
|
||||||
|
while (index--) {
|
||||||
|
size_t size = destination_size - 1;
|
||||||
|
write = destination;
|
||||||
|
char ch = '.';
|
||||||
|
while ((ch != '\0') && (ch != '|')) {
|
||||||
|
ch = pgm_read_byte(read++);
|
||||||
|
if (size && (ch != '|')) {
|
||||||
|
*write++ = ch;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 == ch) {
|
||||||
|
if (index) {
|
||||||
|
write = destination;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*write = '\0';
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char kUnescapeCode[] = "&><\"\'\\";
|
||||||
|
const char kEscapeCode[] PROGMEM = "&|>|<|"|'|\";
|
||||||
|
|
||||||
|
String HtmlEscape(const String unescaped) {
|
||||||
|
char escaped[10];
|
||||||
|
size_t ulen = unescaped.length();
|
||||||
|
String result;
|
||||||
|
result.reserve(ulen); // pre-reserve the required space to avoid mutiple reallocations
|
||||||
|
for (size_t i = 0; i < ulen; i++) {
|
||||||
|
char c = unescaped[i];
|
||||||
|
char* p = strchr(kUnescapeCode, c);
|
||||||
|
if (p != nullptr) {
|
||||||
|
result += GetTextIndexed(escaped, sizeof(escaped), p - kUnescapeCode, kEscapeCode);
|
||||||
|
} else {
|
||||||
|
result += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
# endif // ESP32
|
# endif // ESP32
|
||||||
|
|
||||||
void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_payload = nullptr, const char* log_data_retained = nullptr) {
|
void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_payload = nullptr, const char* log_data_retained = nullptr) {
|
||||||
@@ -439,14 +501,142 @@ void handleCN() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief /WI - Configure WiFi Page
|
* @brief /WI - Configure WiFi Page
|
||||||
*
|
* T: handleWI: uri: /wi, args: 4, method: 1
|
||||||
|
* T: handleWI Arg: 0, s1=SSID
|
||||||
|
* T: handleWI Arg: 1, p1=xxxxxx
|
||||||
|
* T: handleWI Arg: 3, save=
|
||||||
*/
|
*/
|
||||||
void handleWI() {
|
void handleWI() {
|
||||||
WEBUI_TRACE_LOG(F("handleWI: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
WEBUI_TRACE_LOG(F("handleWI: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||||
|
String WiFiScan = "";
|
||||||
if (server.args()) {
|
if (server.args()) {
|
||||||
for (uint8_t i = 0; i < server.args(); i++) {
|
for (uint8_t i = 0; i < server.args(); i++) {
|
||||||
WEBUI_TRACE_LOG(F("handleWI Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
WEBUI_TRACE_LOG(F("handleWI Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||||
}
|
}
|
||||||
|
if (server.hasArg("scan")) {
|
||||||
|
bool limitScannedNetworks = true;
|
||||||
|
int n = WiFi.scanNetworks();
|
||||||
|
|
||||||
|
WEBUI_TRACE_LOG(F("handleWI scan: found %d" CR), n);
|
||||||
|
if (0 == n) {
|
||||||
|
// WSContentSend_P(PSTR(D_NO_NETWORKS_FOUND));
|
||||||
|
// limitScannedNetworks = false; // in order to show D_SCAN_FOR_WIFI_NETWORKS
|
||||||
|
} else {
|
||||||
|
//sort networks
|
||||||
|
int indices[n];
|
||||||
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
|
indices[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RSSI SORT
|
||||||
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
|
for (uint32_t j = i + 1; j < n; j++) {
|
||||||
|
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||||
|
std::swap(indices[i], indices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t networksToShow = n;
|
||||||
|
if ((limitScannedNetworks) && (networksToShow > MAX_WIFI_NETWORKS_TO_SHOW)) {
|
||||||
|
networksToShow = MAX_WIFI_NETWORKS_TO_SHOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
|
if (-1 == indices[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String cssid = WiFi.SSID(indices[i]);
|
||||||
|
uint32_t cschn = WiFi.channel(indices[i]);
|
||||||
|
for (uint32_t j = i + 1; j < n; j++) {
|
||||||
|
if ((cssid == WiFi.SSID(indices[j])) && (cschn == WiFi.channel(indices[j]))) {
|
||||||
|
WEBUI_TRACE_LOG(F("handleWI scan: duplicate %s" CR), WiFi.SSID(indices[j]).c_str());
|
||||||
|
indices[j] = -1; // set dup aps to index -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//display networks in page
|
||||||
|
for (uint32_t i = 0; i < networksToShow; i++) {
|
||||||
|
if (-1 == indices[i]) {
|
||||||
|
continue;
|
||||||
|
} // skip dups
|
||||||
|
int32_t rssi = WiFi.RSSI(indices[i]);
|
||||||
|
WEBUI_TRACE_LOG(F("D_LOG_WIFI D_SSID %s, D_BSSID %s, D_CHANNEL %d, D_RSSI %d" CR),
|
||||||
|
WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), rssi);
|
||||||
|
int quality = WifiGetRssiAsQuality(rssi);
|
||||||
|
String ssid_copy = WiFi.SSID(indices[i]);
|
||||||
|
if (!ssid_copy.length()) {
|
||||||
|
ssid_copy = F("no_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFiScan += "<div><a href='#p' onclick='c(this)'>" + HtmlEscape(ssid_copy) + "</a> (" + WiFi.channel(indices[i]) + ") <span class='q'>" + quality + "% (" + rssi + " dBm)</span></div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WEBUI_TRACE_LOG(F("handleWI scan: results %s" CR), WiFiScan.c_str());
|
||||||
|
|
||||||
|
char jsonChar[100];
|
||||||
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
|
||||||
|
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure WiFi").c_str());
|
||||||
|
String response = String(buffer);
|
||||||
|
response += String(wifi_script);
|
||||||
|
response += String(script);
|
||||||
|
response += String(style);
|
||||||
|
// wifi_ssid, wifi_password, gateway_name
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_wifi_body, jsonChar, gateway_name, WiFiScan.c_str(), WiFi.SSID(), WiFi.psk());
|
||||||
|
response += String(buffer);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
|
response += String(buffer);
|
||||||
|
server.send(200, "text/html", response);
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else if (server.hasArg("save")) {
|
||||||
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
|
JsonObject WEBtoSYS = jsonBuffer.to<JsonObject>();
|
||||||
|
bool update = false;
|
||||||
|
if (server.hasArg("s1")) {
|
||||||
|
WEBtoSYS["wifi_ssid"] = server.arg("s1");
|
||||||
|
if (strncmp((char*)WiFi.SSID().c_str(), server.arg("s1").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (server.hasArg("p1")) {
|
||||||
|
WEBtoSYS["wifi_pass"] = server.arg("p1");
|
||||||
|
if (strncmp((char*)WiFi.psk().c_str(), server.arg("p1").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (update) {
|
||||||
|
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
|
||||||
|
String output;
|
||||||
|
serializeJson(WEBtoSYS, output);
|
||||||
|
Log.notice(F("[WebUI] MQTTtoSYS %s" CR), output.c_str());
|
||||||
|
Log.warning(F("[WebUI] Save WiFi and Restart" CR));
|
||||||
|
char jsonChar[100];
|
||||||
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save WiFi and Restart").c_str());
|
||||||
|
String response = String(buffer);
|
||||||
|
response += String(restart_script);
|
||||||
|
response += String(script);
|
||||||
|
response += String(style);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save WiFi and Restart");
|
||||||
|
response += String(buffer);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
|
response += String(buffer);
|
||||||
|
server.send(200, "text/html", response);
|
||||||
|
|
||||||
|
delay(2000); // Wait for web page to be sent before
|
||||||
|
MQTTtoSYS((char*)topic.c_str(), WEBtoSYS);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Log.warning(F("[WebUI] No changes" CR));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
char jsonChar[100];
|
char jsonChar[100];
|
||||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
@@ -455,9 +645,11 @@ void handleWI() {
|
|||||||
|
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure WiFi").c_str());
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure WiFi").c_str());
|
||||||
String response = String(buffer);
|
String response = String(buffer);
|
||||||
|
response += String(wifi_script);
|
||||||
response += String(script);
|
response += String(script);
|
||||||
response += String(style);
|
response += String(style);
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_wifi_body, jsonChar, gateway_name, "", "", "", "", "", "");
|
// wifi_ssid, wifi_password, gateway_name
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_wifi_body, jsonChar, gateway_name, WiFiScan.c_str(), WiFi.SSID(), WiFi.psk());
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
@@ -466,12 +658,13 @@ void handleWI() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief /MQ - Configure MQTT Page
|
* @brief /MQ - Configure MQTT Page
|
||||||
* T: handleMQ Arg: 0, mh=192.168.1.17
|
* T: handleMQ: uri: /mq, args: 8, method: 1
|
||||||
|
* T: handleMQ Arg: 0, mh=192.168.1.11
|
||||||
* T: handleMQ Arg: 1, ml=1883
|
* T: handleMQ Arg: 1, ml=1883
|
||||||
* T: handleMQ Arg: 2, mu=your_username
|
* T: handleMQ Arg: 2, mu=1234
|
||||||
* T: handleMQ Arg: 3, mp=your_password
|
* T: handleMQ Arg: 3, mp=
|
||||||
* T: handleMQ Arg: 4, sc=on
|
* T: handleMQ Arg: 4, sc=on
|
||||||
* T: handleMQ Arg: 5, msc=suds
|
* T: handleMQ Arg: 5, h=
|
||||||
* T: handleMQ Arg: 6, mt=home/
|
* T: handleMQ Arg: 6, mt=home/
|
||||||
* T: handleMQ Arg: 7, save=
|
* T: handleMQ Arg: 7, save=
|
||||||
*/
|
*/
|
||||||
@@ -482,28 +675,94 @@ void handleMQ() {
|
|||||||
WEBUI_TRACE_LOG(F("handleMQ Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
WEBUI_TRACE_LOG(F("handleMQ Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||||
}
|
}
|
||||||
if (server.hasArg("save")) {
|
if (server.hasArg("save")) {
|
||||||
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
|
JsonObject WEBtoSYS = jsonBuffer.to<JsonObject>();
|
||||||
|
bool update = false;
|
||||||
|
|
||||||
if (server.hasArg("mh")) {
|
if (server.hasArg("mh")) {
|
||||||
strncpy(mqtt_server, server.arg("mh").c_str(), parameters_size);
|
WEBtoSYS["mqtt_server"] = server.arg("mh");
|
||||||
|
if (strncmp(mqtt_server, server.arg("mh").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server.hasArg("ml")) {
|
if (server.hasArg("ml")) {
|
||||||
strncpy(mqtt_port, server.arg("ml").c_str(), 6);
|
WEBtoSYS["mqtt_port"] = server.arg("ml");
|
||||||
|
if (strncmp(mqtt_port, server.arg("ml").c_str(), 6)) {
|
||||||
|
update = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server.hasArg("mu")) {
|
if (server.hasArg("mu")) {
|
||||||
strncpy(mqtt_user, server.arg("mu").c_str(), parameters_size);
|
WEBtoSYS["mqtt_user"] = server.arg("mu");
|
||||||
|
if (strncmp(mqtt_user, server.arg("mu").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server.hasArg("mp")) {
|
if (server.hasArg("mp")) {
|
||||||
strncpy(mqtt_pass, server.arg("mp").c_str(), parameters_size);
|
WEBtoSYS["mqtt_pass"] = server.arg("mp");
|
||||||
|
if (strncmp(mqtt_pass, server.arg("mp").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
}
|
}
|
||||||
mqtt_secure = server.hasArg("sc");
|
|
||||||
if (server.hasArg("msc")) {
|
|
||||||
mqtt_cert = server.arg("msc"); // String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SC - Secure Connection argument is only present when true
|
||||||
|
WEBtoSYS["mqtt_secure"] = server.hasArg("sc");
|
||||||
|
if (mqtt_secure != server.hasArg("sc")) {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!update) {
|
||||||
|
Log.warning(F("[WebUI] clearing" CR));
|
||||||
|
for (JsonObject::iterator it = WEBtoSYS.begin(); it != WEBtoSYS.end(); ++it) {
|
||||||
|
WEBtoSYS.remove(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server.hasArg("h")) {
|
||||||
|
WEBtoSYS["gateway_name"] = server.arg("h");
|
||||||
|
if (strncmp(gateway_name, server.arg("h").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server.hasArg("mt")) {
|
if (server.hasArg("mt")) {
|
||||||
strncpy(mqtt_topic, server.arg("mt").c_str(), parameters_size);
|
WEBtoSYS["mqtt_topic"] = server.arg("mt");
|
||||||
|
if (strncmp(mqtt_topic, server.arg("mt").c_str(), parameters_size)) {
|
||||||
|
update = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# ifndef ESPWifiManualSetup
|
# ifndef ESPWifiManualSetup
|
||||||
saveMqttConfig();
|
if (update) {
|
||||||
connectMQTT();
|
Log.warning(F("[WebUI] Save MQTT and Restart" CR));
|
||||||
|
|
||||||
|
char jsonChar[100];
|
||||||
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save MQTT and Restart").c_str());
|
||||||
|
String response = String(buffer);
|
||||||
|
response += String(restart_script);
|
||||||
|
response += String(script);
|
||||||
|
response += String(style);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save MQTT and Restart");
|
||||||
|
response += String(buffer);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
|
response += String(buffer);
|
||||||
|
server.send(200, "text/html", response);
|
||||||
|
|
||||||
|
delay(2000); // Wait for web page to be sent before
|
||||||
|
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
|
||||||
|
String output;
|
||||||
|
serializeJson(WEBtoSYS, output);
|
||||||
|
Log.notice(F("[WebUI] MQTTtoSYS %s" CR), output.c_str());
|
||||||
|
MQTTtoSYS((char*)topic.c_str(), WEBtoSYS);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Log.warning(F("[WebUI] No changes" CR));
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +777,7 @@ void handleMQ() {
|
|||||||
response += String(script);
|
response += String(script);
|
||||||
response += String(style);
|
response += String(style);
|
||||||
// mqtt server (mh), mqtt port (ml), mqtt username (mu), mqtt password (mp), secure connection (sc), server certificate (msc), topic (mt)
|
// mqtt server (mh), mqtt port (ml), mqtt username (mu), mqtt password (mp), secure connection (sc), server certificate (msc), topic (mt)
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_mqtt_body, jsonChar, gateway_name, mqtt_server, mqtt_port, mqtt_user, mqtt_pass, (mqtt_secure ? "checked" : ""), mqtt_cert, mqtt_topic);
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_mqtt_body, jsonChar, gateway_name, mqtt_server, mqtt_port, mqtt_user, mqtt_pass, (mqtt_secure ? "checked" : ""), gateway_name, mqtt_topic);
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
@@ -537,7 +796,8 @@ void handleLO() {
|
|||||||
for (uint8_t i = 0; i < server.args(); i++) {
|
for (uint8_t i = 0; i < server.args(); i++) {
|
||||||
WEBUI_TRACE_LOG(F("handleLO Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
WEBUI_TRACE_LOG(F("handleLO Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||||
}
|
}
|
||||||
if (server.hasArg("save") && server.hasArg("lo")) {
|
if (server.hasArg("save") && server.hasArg("lo") && server.arg("lo").toInt() != Log.getLevel()) {
|
||||||
|
Log.fatal(F("[WebUI] Log level changed to: %d" CR), server.arg("lo").toInt());
|
||||||
Log.setLevel(server.arg("lo").toInt());
|
Log.setLevel(server.arg("lo").toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -770,7 +1030,67 @@ void handleUP() {
|
|||||||
for (uint8_t i = 0; i < server.args(); i++) {
|
for (uint8_t i = 0; i < server.args(); i++) {
|
||||||
WEBUI_TRACE_LOG(F("handleUP Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
WEBUI_TRACE_LOG(F("handleUP Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||||
}
|
}
|
||||||
} else {
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
|
JsonObject WEBtoSYS = jsonBuffer.to<JsonObject>();
|
||||||
|
|
||||||
|
if (server.hasArg("o")) {
|
||||||
|
WEBtoSYS["url"] = server.arg("o");
|
||||||
|
WEBtoSYS["version"] = "test";
|
||||||
|
WEBtoSYS["password"] = ota_pass;
|
||||||
|
|
||||||
|
char jsonChar[100];
|
||||||
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Updating Firmware and Restart").c_str());
|
||||||
|
String response = String(buffer);
|
||||||
|
response += String(restart_script);
|
||||||
|
response += String(script);
|
||||||
|
response += String(style);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Updating Firmware and Restart");
|
||||||
|
response += String(buffer);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
|
response += String(buffer);
|
||||||
|
server.send(200, "text/html", response);
|
||||||
|
|
||||||
|
delay(2000); // Wait for web page to be sent before
|
||||||
|
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSupdate);
|
||||||
|
String output;
|
||||||
|
serializeJson(WEBtoSYS, output);
|
||||||
|
Log.notice(F("[WebUI] MQTTtoSYSupdate %s" CR), output.c_str());
|
||||||
|
MQTTHttpsFWUpdate((char*)topic.c_str(), WEBtoSYS);
|
||||||
|
return;
|
||||||
|
} else if (server.hasArg("le")) {
|
||||||
|
uint32_t le = server.arg("le").toInt();
|
||||||
|
if (le != 0) {
|
||||||
|
WEBtoSYS["version"] = (le == 1 ? "latest" : (le == 2 ? "dev" : "unknown"));
|
||||||
|
WEBtoSYS["password"] = ota_pass;
|
||||||
|
|
||||||
|
char jsonChar[100];
|
||||||
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||||
|
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Updating Firmware and Restart").c_str());
|
||||||
|
String response = String(buffer);
|
||||||
|
response += String(restart_script);
|
||||||
|
response += String(script);
|
||||||
|
response += String(style);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Updating Firmware and Restart");
|
||||||
|
response += String(buffer);
|
||||||
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
|
response += String(buffer);
|
||||||
|
server.send(200, "text/html", response);
|
||||||
|
|
||||||
|
delay(2000); // Wait for web page to be sent before
|
||||||
|
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSupdate);
|
||||||
|
String output;
|
||||||
|
serializeJson(WEBtoSYS, output);
|
||||||
|
Log.notice(F("[WebUI] MQTTtoSYSupdate %s" CR), output.c_str());
|
||||||
|
MQTTHttpsFWUpdate((char*)topic.c_str(), WEBtoSYS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
char jsonChar[100];
|
char jsonChar[100];
|
||||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||||
|
|
||||||
@@ -780,16 +1100,13 @@ void handleUP() {
|
|||||||
String response = String(buffer);
|
String response = String(buffer);
|
||||||
response += String(script);
|
response += String(script);
|
||||||
response += String(style);
|
response += String(style);
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, upgrade_body, jsonChar, gateway_name, "http://upgrade/");
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, upgrade_body, jsonChar, gateway_name, "https://github.com/1technophile/OpenMQTTGateway/releases/");
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||||
response += String(buffer);
|
response += String(buffer);
|
||||||
server.send(200, "text/html", response);
|
server.send(200, "text/html", response);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t logIndex = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief /CS - Serial Console and Command Line
|
* @brief /CS - Serial Console and Command Line
|
||||||
*
|
*
|
||||||
@@ -1067,7 +1384,7 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
strlcpy(message->title, strtok(topic, "/"), WEBUI_TEXT_WIDTH);
|
strlcpy(message->title, strtok(topic, "/"), WEBUI_TEXT_WIDTH);
|
||||||
free(topic);
|
free(topic);
|
||||||
|
|
||||||
WEBUI_TRACE_LOG(F("[ webUIPubPrint ] switch %s " CR), message->title);
|
// WEBUI_TRACE_LOG(F("[ webUIPubPrint ] switch %s " CR), message->title);
|
||||||
switch (webUIHash(message->title)) {
|
switch (webUIHash(message->title)) {
|
||||||
case webUIHash("SYStoMQTT"): {
|
case webUIHash("SYStoMQTT"): {
|
||||||
// {"uptime":456356,"version":"lilygo-rtl_433-test-A-v1.1.1-25-g574177d[lily-cloud]","freemem":125488,"mqttport":"1883","mqttsecure":false,"freestack":3752,"rssi":-36,"SSID":"The_Beach","BSSID":"64:A5:C3:69:C3:38","ip":"192.168.1.239","mac":"4C:75:25:A8:D5:D8","actRec":3,"mhz":433.92,"RTLRssiThresh":-98,"RTLRssi":-108,"RTLAVGRssi":-107,"RTLCnt":121707,"RTLOOKThresh":90,"modules":["LILYGO_OLED","CLOUD","rtl_433"]}
|
// {"uptime":456356,"version":"lilygo-rtl_433-test-A-v1.1.1-25-g574177d[lily-cloud]","freemem":125488,"mqttport":"1883","mqttsecure":false,"freestack":3752,"rssi":-36,"SSID":"The_Beach","BSSID":"64:A5:C3:69:C3:38","ip":"192.168.1.239","mac":"4C:75:25:A8:D5:D8","actRec":3,"mhz":433.92,"RTLRssiThresh":-98,"RTLRssi":-108,"RTLAVGRssi":-107,"RTLCnt":121707,"RTLOOKThresh":90,"modules":["LILYGO_OLED","CLOUD","rtl_433"]}
|
||||||
@@ -1111,7 +1428,7 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
|
|
||||||
# ifdef ZgatewayRTL_433
|
# ifdef ZgatewayRTL_433
|
||||||
case webUIHash("RTL_433toMQTT"): {
|
case webUIHash("RTL_433toMQTT"): {
|
||||||
if (!strncmp(data["model"], "status", 6) && data.containsKey("id")) {
|
if (strncmp(data["model"], "status", 6)) { // Does not contain "status"
|
||||||
// {"model":"Acurite-Tower","id":2043,"channel":"B","battery_ok":1,"temperature_C":5.3,"humidity":81,"mic":"CHECKSUM","protocol":"Acurite 592TXR Temp/Humidity, 5n1 Weather Station, 6045 Lightning, 3N1, Atlas","rssi":-81,"duration":121060}
|
// {"model":"Acurite-Tower","id":2043,"channel":"B","battery_ok":1,"temperature_C":5.3,"humidity":81,"mic":"CHECKSUM","protocol":"Acurite 592TXR Temp/Humidity, 5n1 Weather Station, 6045 Lightning, 3N1, Atlas","rssi":-81,"duration":121060}
|
||||||
|
|
||||||
// Line 1
|
// Line 1
|
||||||
@@ -1120,10 +1437,12 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
|
|
||||||
// Line 2
|
// Line 2
|
||||||
|
|
||||||
|
if (data["id"] || data["channel"]) {
|
||||||
String id = data["id"];
|
String id = data["id"];
|
||||||
String channel = data["channel"];
|
String channel = data["channel"];
|
||||||
String line2 = "id: " + id + " channel: " + channel;
|
String line2 = "id: " + id + " channel: " + channel;
|
||||||
line2.toCharArray(message->line2, WEBUI_TEXT_WIDTH);
|
line2.toCharArray(message->line2, WEBUI_TEXT_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
// Line 3
|
// Line 3
|
||||||
|
|
||||||
@@ -1165,10 +1484,14 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
|
|
||||||
// Line 4
|
// Line 4
|
||||||
|
|
||||||
String rssi = data["rssi"];
|
String line4 = "";
|
||||||
String battery_ok = data["battery_ok"];
|
if (data["battery_ok"]) {
|
||||||
|
line4 = "batt: " + data["battery_ok"].as<String>();
|
||||||
|
} else {
|
||||||
|
line4 = "pulses: " + data["pulses"].as<String>();
|
||||||
|
}
|
||||||
|
|
||||||
String line4 = "batt: " + battery_ok + " rssi: " + rssi;
|
line4 += " rssi: " + data["rssi"].as<String>();
|
||||||
line4.toCharArray(message->line4, WEBUI_TEXT_WIDTH);
|
line4.toCharArray(message->line4, WEBUI_TEXT_WIDTH);
|
||||||
|
|
||||||
// Queue completed message
|
// Queue completed message
|
||||||
@@ -1179,6 +1502,9 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
} else {
|
} else {
|
||||||
// Log.notice(F("[ WebUI ] Queued %s" CR), message->title);
|
// Log.notice(F("[ WebUI ] Queued %s" CR), message->title);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.error(F("[ WebUI ] rtl_433 not displaying %s" CR), message->title);
|
||||||
|
free(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1559,7 +1885,7 @@ void webUIPubPrint(const char* topicori, JsonObject& data) {
|
|||||||
Log.error(F("[ WebUI ] webUIQueue full, discarding signal %s" CR), message->title);
|
Log.error(F("[ WebUI ] webUIQueue full, discarding signal %s" CR), message->title);
|
||||||
free(message);
|
free(message);
|
||||||
} else {
|
} else {
|
||||||
Log.notice(F("[ WebUI ] Queued %s" CR), message->title);
|
// Log.notice(F("[ WebUI ] Queued %s" CR), message->title);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
WEBUI_TRACE_LOG(F("[ WebUI ] incomplete messaage %s" CR), topicori);
|
WEBUI_TRACE_LOG(F("[ WebUI ] incomplete messaage %s" CR), topicori);
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ const char restart_script[] = "setTimeout(function() { location.href = '.'; }, 1
|
|||||||
|
|
||||||
const char information_script[] = "function i() { var s, o = \"<table style='width:100%%'><tr><th>%s</td></tr></table>\"; s = o.replace(/}1/g, \"</td></tr><tr><th>\").replace(/}2/g, \"</th><td>\"); eb('i').innerHTML = s; } wl(i);";
|
const char information_script[] = "function i() { var s, o = \"<table style='width:100%%'><tr><th>%s</td></tr></table>\"; s = o.replace(/}1/g, \"</td></tr><tr><th>\").replace(/}2/g, \"</th><td>\"); eb('i').innerHTML = s; } wl(i);";
|
||||||
|
|
||||||
const char console_script[] = " var sn = 0, id = 0, ft, ltm = 2345; function l(p) { var c, o = ''; clearTimeout(lt); clearTimeout(ft); t = eb('t1'); if (p == 1) { c = eb('c1'); o = '&c1=' + encodeURIComponent(c.value); c.value = ''; t.scrollTop = 99999; sn = t.scrollTop; } if (t.scrollTop >= sn) { if (x != null) { x.abort(); } x = new XMLHttpRequest(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { var z, d; d = x.responseText.split(/}1/); id = d.shift(); if (d.shift() == 0) { t.value = ''; } z = d.shift(); if (z.length > 0) { t.value += z; } t.scrollTop = 99999; sn = t.scrollTop; clearTimeout(ft); lt = setTimeout(l, ltm); } }; x.open('GET', 'cs?c2=' + id + o, true); x.send(); ft = setTimeout(l, 20000); } else { lt = setTimeout(l, ltm); } return false; } wl(l); var hc = [], cn = 0; function h() { eb('c1').addEventListener('keydown', function(e) { var b = eb('c1'), c = e.keyCode; if (38 == c || 40 == c) { b.autocomplete = 'off'; } 38 == c ? (++cn > hc.length && (cn = hc.length), b.value = hc[cn - 1] || '') : 40 == c ? (0 > --cn && (cn = 0), b.value = hc[cn - 1] || '') : 13 == c && (hc.length > 19 && hc.pop(), hc.unshift(b.value), cn = 0) }); } wl(h);";
|
const char console_script[] = "var sn = 0, id = 0, ft, ltm = 2345; function l(p) { var c, o = ''; clearTimeout(lt); clearTimeout(ft); t = eb('t1'); if (p == 1) { c = eb('c1'); o = '&c1=' + encodeURIComponent(c.value); c.value = ''; t.scrollTop = 99999; sn = t.scrollTop; } if (t.scrollTop >= sn) { if (x != null) { x.abort(); } x = new XMLHttpRequest(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { var z, d; d = x.responseText.split(/}1/); id = d.shift(); if (d.shift() == 0) { t.value = ''; } z = d.shift(); if (z.length > 0) { t.value += z; } t.scrollTop = 99999; sn = t.scrollTop; clearTimeout(ft); lt = setTimeout(l, ltm); } }; x.open('GET', 'cs?c2=' + id + o, true); x.send(); ft = setTimeout(l, 20000); } else { lt = setTimeout(l, ltm); } return false; } wl(l); var hc = [], cn = 0; function h() { eb('c1').addEventListener('keydown', function(e) { var b = eb('c1'), c = e.keyCode; if (38 == c || 40 == c) { b.autocomplete = 'off'; } 38 == c ? (++cn > hc.length && (cn = hc.length), b.value = hc[cn - 1] || '') : 40 == c ? (0 > --cn && (cn = 0), b.value = hc[cn - 1] || '') : 13 == c && (hc.length > 19 && hc.pop(), hc.unshift(b.value), cn = 0) }); } wl(h);";
|
||||||
|
|
||||||
|
const char wifi_script[] = "function c(l) {eb('s1').value = l.innerText || l.textContent; eb('p1').focus(); }";
|
||||||
|
|
||||||
const char script[] = "function jd() { var t = 0, i = document.querySelectorAll('input,button,textarea,select'); while (i.length >= t) { if (i[t]) { i[t]['name'] = (i[t].hasAttribute('id') && (!i[t].hasAttribute('name'))) ? i[t]['id'] : i[t]['name']; } t++; } } wl(jd); </script>";
|
const char script[] = "function jd() { var t = 0, i = document.querySelectorAll('input,button,textarea,select'); while (i.length >= t) { if (i[t]) { i[t]['name'] = (i[t].hasAttribute('id') && (!i[t].hasAttribute('name'))) ? i[t]['id'] : i[t]['name']; } t++; } } wl(jd); </script>";
|
||||||
|
|
||||||
@@ -81,13 +83,15 @@ const char console_body[] = body_header "<br><textarea readonly id='t1' cols='34
|
|||||||
|
|
||||||
const char information_body[] = body_header "<style>td {padding: 0px 5px;}</style><div id='i' name='i'></div>" body_footer_main_menu;
|
const char information_body[] = body_header "<style>td {padding: 0px 5px;}</style><div id='i' name='i'></div>" body_footer_main_menu;
|
||||||
|
|
||||||
const char upgrade_body[] = body_header "<div id='f1' style='display:block;'><fieldset><legend><b> Upgrade by web server </b></legend><form method='get' action='u1'><br><b>OTA Url</b><br><input id='o' placeholder=\"OTA_URL\" value=\"%s\"><br><br><button type='submit'>Start upgrade</button></form></fieldset><br><br><fieldset><legend><b> Upgrade by file upload </b></legend><form method='post' action='u2' enctype='multipart/form-data'><br><input type='file' name='u2'><br><br><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>Start upgrade</button></form></fieldset></div><div id='f2' style='display:none;text-align:center;'><b>Upload started ...</b></div><div id=but2d style=\"display: block;\"></div><p>" body_footer_main_menu;
|
// <fieldset><legend><b> Upgrade by file upload </b></legend><form method='post' action='up' enctype='multipart/form-data'><br><input type='file' name='u2'><br><br><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>Start upgrade</button></form></fieldset>
|
||||||
|
|
||||||
const char config_wifi_body[] = body_header "<div title='-43 dBm (100%)'><a href='#p' onclick='c(this)'>%s</a><span class='q'><div class='si'><i class='b0'></i><i class='b1'></i><i class='b2'></i><i class='b3'></i></span></div></div><div title='-84 dBm (32%)'><a href='#p' onclick='c(this)'>BELL634</a><span class='q'><div class='si'><i class='b0'></i><i class='b1'></i><i class='b2 o30'></i><i class='b3 o30'></i></span></div></div><div title='-86 dBm (28%)'><a href='#p' onclick='c(this)'>MRC</a><span class='q'><div class='si'><i class='b0'></i><i class='b1'></i><i class='b2 o30'></i><i class='b3 o30'></i></span></div></div><br><div><a href='/wi?scan='>Scan for all WiFi Networks</a></div><br><fieldset><legend><b> Wifi parameters </b></legend><form method='get' action='wi'><p><b>WiFi Network</b> () <br><input id='s1' placeholder=\"Type or Select your WiFi Network\" value=\"%s\"></p><p><label><b>WiFi Password</b><input type='checkbox' onclick='sp(\"p1\")'></label><br><input id='p1' type='password' placeholder=\"Enter your WiFi Password\" value=\"****\"></p><p><b>WiFi Network 2</b> () <br><input id='s2' placeholder=\"Type your Alternative WiFi Network\" value=\"\"></p><p><label><b>WiFi Password</b><input type='checkbox' onclick='sp(\"p2\")'></label><br><input id='p2' type='password' placeholder=\"Enter your WiFi Password\" value=\"****\"></p><p><b>Hostname</b>%s<br><input id='h' placeholder=\"%s\" value=\"%s\"></p><p><b>CORS Domain</b><input id='c' placeholder=\"\" value=\"%s\"></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
const char upgrade_body[] = body_header "<div id='f1' style='display:block;'><fieldset><legend><b> Upgrade by web server </b></legend><form method='get' action='up'><br><b>OTA Url</b><br><input id='o' placeholder=\"OTA_URL\" value=\"%s\"><br><br><button type='submit'>Start upgrade</button></form></fieldset><br><br><fieldset><legend><b>Upgrade to Level</b></legend><form method='get' action='up'><p><b>level</b><br><select id='le'><option value='1'>Latest</option><option value='2'>Development</option></select></p><br><button type='submit'>Start upgrade</button></form></fieldset></div><div id='f2' style='display:none;text-align:center;'><b>Upload started ...</b></div><div id=but2d style=\"display: block;\"></div><p>" body_footer_main_menu;
|
||||||
|
|
||||||
|
const char config_wifi_body[] = body_header "%s<br><div><a href='/wi?scan='>Scan for all WiFi Networks</a></div><br><fieldset><legend><b> Wifi parameters </b></legend><form method='get' action='wi'><p><b>WiFi Network</b> () <br><input id='s1' placeholder=\"Type or Select your WiFi Network\" value=\"%s\"></p><p><label><b>WiFi Password</b><input type='checkbox' onclick='sp(\"p1\")'></label><br><input id='p1' type='password' placeholder=\"Enter your WiFi Password\" value=\"%s\"></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
||||||
|
|
||||||
// mqtt server (mh), mqtt port (ml), mqtt username (mu), mqtt password (mp), secure connection (sc), server certificate (msc), topic (mt)
|
// mqtt server (mh), mqtt port (ml), mqtt username (mu), mqtt password (mp), secure connection (sc), server certificate (msc), topic (mt)
|
||||||
|
|
||||||
const char config_mqtt_body[] = body_header "<fieldset><legend><b> MQTT parameters </b></legend><form method='get' action='mq'><p><b>MQTT Server</b><br><input id='mh' placeholder=" MQTT_SERVER " value='%s'></p><p><b>MQTT Port</b><br><input id='ml' placeholder=" MQTT_PORT " value='%s'></p><p><b>MQTT Username</b><br><input id='mu' placeholder=" MQTT_USER " value='%s'></p><p><label><b>MQTT Password</b><input type='checkbox' onclick='sp(\"mp\")'></label><br><input id='mp' type='password' placeholder=\"Password\" value='%s'></p><p><b>MQTT Secure Connection</b><br><input id='sc' type='checkbox' %s></p><p><b>MQTT Server Certificate</b><br><textarea class='form-control' name='msc' id='field_msc' rows='10' cols='64'>%s</textarea></p><p><b>MQTT Base Topic</b><br><input id='mt' placeholder='' value='%s'></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
const char config_mqtt_body[] = body_header "<fieldset><legend><b> MQTT parameters </b></legend><form method='get' action='mq'><p><b>MQTT Server</b><br><input id='mh' placeholder=" MQTT_SERVER " value='%s'></p><p><b>MQTT Port</b><br><input id='ml' placeholder=" MQTT_PORT " value='%s'></p><p><b>MQTT Username</b><br><input id='mu' placeholder=" MQTT_USER " value='%s'></p><p><label><b>MQTT Password</b><input type='checkbox' onclick='sp(\"mp\")'></label><br><input id='mp' type='password' placeholder=\"Password\" value='%s'></p><p><b>MQTT Secure Connection</b><br><input id='sc' type='checkbox' %s></p><p><b>Gateway Name</b><br><input id='h' placeholder=" Gateway_Name " value=\"%s\"></p><p><b>MQTT Base Topic</b><br><input id='mt' placeholder='' value='%s'></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
||||||
|
|
||||||
const char config_logging_body[] = body_header "<fieldset><legend><b>OpenMQTTGateway Logging</b></legend><form method='get' action='lo'><p><b>log level</b><br><select id='lo'><option %s value='0'>Silent</option><option %s value='1'>Fatal</option><option %s value='2'>Error</option><option %s value='3'>Warning</option><option %s value='4'>Notice</option><option %s value='5'>Trace</option><option %s value='6'>Verbose</option></select></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
const char config_logging_body[] = body_header "<fieldset><legend><b>OpenMQTTGateway Logging</b></legend><form method='get' action='lo'><p><b>log level</b><br><select id='lo'><option %s value='0'>Silent</option><option %s value='1'>Fatal</option><option %s value='2'>Error</option><option %s value='3'>Warning</option><option %s value='4'>Notice</option><option %s value='5'>Trace</option><option %s value='6'>Verbose</option></select></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
/*------------------- End of Compiler Directives ----------------------*/
|
/*------------------- End of Compiler Directives ----------------------*/
|
||||||
|
|
||||||
// Structure for queueing OMG messages to the display
|
#define MAX_WIFI_NETWORKS_TO_SHOW 10
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Structure for queueing OMG messages to the display.
|
Structure for queueing OMG messages to the display.
|
||||||
|
|||||||
+21
-12
@@ -2355,7 +2355,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
client.disconnect();
|
client.disconnect();
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
|
|
||||||
Log.warning(F("Attempting connection to new AP" CR));
|
Log.warning(F("Attempting connection to new AP %s" CR), (const char*)SYSdata["wifi_ssid"]);
|
||||||
WiFi.begin((const char*)SYSdata["wifi_ssid"], (const char*)SYSdata["wifi_pass"]);
|
WiFi.begin((const char*)SYSdata["wifi_ssid"], (const char*)SYSdata["wifi_pass"]);
|
||||||
# if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
# if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
||||||
setESP32WifiPorotocolTxPower();
|
setESP32WifiPorotocolTxPower();
|
||||||
@@ -2373,6 +2373,21 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
ESPRestart();
|
ESPRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool disconnectClient = false; // Trigger client.disconnet if a user/password change doesn't
|
||||||
|
|
||||||
|
if (SYSdata.containsKey("mqtt_topic") || SYSdata.containsKey("gateway_name")) {
|
||||||
|
if (SYSdata.containsKey("mqtt_topic")) {
|
||||||
|
strncpy(mqtt_topic, SYSdata["mqtt_topic"], parameters_size);
|
||||||
|
}
|
||||||
|
if (SYSdata.containsKey("gateway_name")) {
|
||||||
|
strncpy(gateway_name, SYSdata["gateway_name"], parameters_size);
|
||||||
|
}
|
||||||
|
# ifndef ESPWifiManualSetup
|
||||||
|
saveMqttConfig();
|
||||||
|
# endif
|
||||||
|
disconnectClient = true; // trigger reconnect in loop using the new topic/name
|
||||||
|
}
|
||||||
|
|
||||||
# ifdef MQTTsetMQTT
|
# ifdef MQTTsetMQTT
|
||||||
if (SYSdata.containsKey("mqtt_user") && SYSdata.containsKey("mqtt_pass")) {
|
if (SYSdata.containsKey("mqtt_user") && SYSdata.containsKey("mqtt_pass")) {
|
||||||
bool update_server = false;
|
bool update_server = false;
|
||||||
@@ -2399,6 +2414,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# if defined(ZgatewayBT) && defined(ESP32)
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
# endif
|
# endif
|
||||||
|
disconnectClient = false;
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
update_server = true;
|
update_server = true;
|
||||||
if (secure_connect != mqtt_secure) {
|
if (secure_connect != mqtt_secure) {
|
||||||
@@ -2422,6 +2438,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# if defined(ZgatewayBT) && defined(ESP32)
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
# endif
|
# endif
|
||||||
|
disconnectClient = false;
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2465,17 +2482,9 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
ESPRestart();
|
ESPRestart();
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
if (SYSdata.containsKey("mqtt_topic") || SYSdata.containsKey("gateway_name")) {
|
|
||||||
if (SYSdata.containsKey("mqtt_topic")) {
|
if (disconnectClient) {
|
||||||
strncpy(mqtt_topic, SYSdata["mqtt_topic"], parameters_size);
|
client.disconnect();
|
||||||
}
|
|
||||||
if (SYSdata.containsKey("gateway_name")) {
|
|
||||||
strncpy(gateway_name, SYSdata["gateway_name"], parameters_size);
|
|
||||||
}
|
|
||||||
# ifndef ESPWifiManualSetup
|
|
||||||
saveMqttConfig();
|
|
||||||
# endif
|
|
||||||
client.disconnect(); // reconnects in loop using the new topic/name
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user