mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 02:52:11 +01:00
Add MQTT settings to backup/restore #284
This commit is contained in:
parent
632dd3900b
commit
ea5614c700
12 changed files with 89 additions and 47 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
extern Preferences pref;
|
extern Preferences pref;
|
||||||
|
|
||||||
#define SHADE_HDR_VER 21
|
#define SHADE_HDR_VER 22
|
||||||
#define SHADE_HDR_SIZE 76
|
#define SHADE_HDR_SIZE 76
|
||||||
#define SHADE_REC_SIZE 276
|
#define SHADE_REC_SIZE 276
|
||||||
#define GROUP_REC_SIZE 194
|
#define GROUP_REC_SIZE 194
|
||||||
|
|
@ -554,6 +554,9 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this->file.seek(this->file.position() + this->header.repeaterRecordSize, SeekSet);
|
||||||
|
}
|
||||||
if(opts.settings) {
|
if(opts.settings) {
|
||||||
// First read out the data.
|
// First read out the data.
|
||||||
this->readSettingsRecord();
|
this->readSettingsRecord();
|
||||||
|
|
@ -584,6 +587,7 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
|
||||||
}
|
}
|
||||||
bool ShadeConfigFile::readNetRecord() {
|
bool ShadeConfigFile::readNetRecord() {
|
||||||
if(this->header.netRecordSize > 0) {
|
if(this->header.netRecordSize > 0) {
|
||||||
|
uint32_t startPos = this->file.position();
|
||||||
Serial.println("Reading network settings from file...");
|
Serial.println("Reading network settings from file...");
|
||||||
settings.connType = static_cast<conn_types>(this->readUInt8(static_cast<uint8_t>(conn_types::unset)));
|
settings.connType = static_cast<conn_types>(this->readUInt8(static_cast<uint8_t>(conn_types::unset)));
|
||||||
settings.IP.dhcp = this->readBool(true);
|
settings.IP.dhcp = this->readBool(true);
|
||||||
|
|
@ -598,9 +602,18 @@ bool ShadeConfigFile::readNetRecord() {
|
||||||
settings.IP.dns1.fromString(ip);
|
settings.IP.dns1.fromString(ip);
|
||||||
this->readVarString(ip, sizeof(ip));
|
this->readVarString(ip, sizeof(ip));
|
||||||
settings.IP.dns2.fromString(ip);
|
settings.IP.dns2.fromString(ip);
|
||||||
|
if(this->header.version >= 22) {
|
||||||
|
this->readVarString(settings.MQTT.protocol, sizeof(settings.MQTT.protocol));
|
||||||
|
this->readVarString(settings.MQTT.hostname, sizeof(settings.MQTT.hostname));
|
||||||
|
settings.MQTT.port = this->readUInt16(1883);
|
||||||
|
settings.MQTT.pubDisco = this->readBool(false);
|
||||||
|
this->readVarString(settings.MQTT.rootTopic, sizeof(settings.MQTT.rootTopic));
|
||||||
|
this->readVarString(settings.MQTT.discoTopic, sizeof(settings.MQTT.discoTopic));
|
||||||
|
}
|
||||||
// Now lets check to see if we are the same board. If we are then we will restore
|
// Now lets check to see if we are the same board. If we are then we will restore
|
||||||
// the ethernet phy settings.
|
// the ethernet phy settings.
|
||||||
if(strncmp(settings.serverId, this->header.serverId, sizeof(settings.serverId)) == 0) {
|
if(strncmp(settings.serverId, this->header.serverId, sizeof(settings.serverId)) == 0) {
|
||||||
|
Serial.println("Restoring Ethernet adapter settings");
|
||||||
settings.Ethernet.boardType = this->readUInt8(1);
|
settings.Ethernet.boardType = this->readUInt8(1);
|
||||||
settings.Ethernet.phyType = static_cast<eth_phy_type_t>(this->readUInt8(0));
|
settings.Ethernet.phyType = static_cast<eth_phy_type_t>(this->readUInt8(0));
|
||||||
settings.Ethernet.CLKMode = static_cast<eth_clock_mode_t>(this->readUInt8(0));
|
settings.Ethernet.CLKMode = static_cast<eth_clock_mode_t>(this->readUInt8(0));
|
||||||
|
|
@ -609,9 +622,8 @@ bool ShadeConfigFile::readNetRecord() {
|
||||||
settings.Ethernet.MDCPin = this->readInt8(16);
|
settings.Ethernet.MDCPin = this->readInt8(16);
|
||||||
settings.Ethernet.MDIOPin = this->readInt8(23);
|
settings.Ethernet.MDIOPin = this->readInt8(23);
|
||||||
}
|
}
|
||||||
else {
|
if(this->file.position() != startPos + this->header.netRecordSize) {
|
||||||
// We are not going to get the network adapter settings.
|
Serial.println("Reading to end of network record");
|
||||||
Serial.println("Skipping Ethernet adapter settings (Chip ids do not match)...");
|
|
||||||
this->seekChar(CFG_REC_END);
|
this->seekChar(CFG_REC_END);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -619,6 +631,7 @@ bool ShadeConfigFile::readNetRecord() {
|
||||||
}
|
}
|
||||||
bool ShadeConfigFile::readTransRecord(transceiver_config_t &cfg) {
|
bool ShadeConfigFile::readTransRecord(transceiver_config_t &cfg) {
|
||||||
if(this->header.transRecordSize > 0) {
|
if(this->header.transRecordSize > 0) {
|
||||||
|
uint32_t startPos = this->file.position();
|
||||||
Serial.println("Reading Transceiver settings from file...");
|
Serial.println("Reading Transceiver settings from file...");
|
||||||
cfg.enabled = this->readBool(false);
|
cfg.enabled = this->readBool(false);
|
||||||
cfg.proto = static_cast<radio_proto>(this->readUInt8(0));
|
cfg.proto = static_cast<radio_proto>(this->readUInt8(0));
|
||||||
|
|
@ -633,6 +646,11 @@ bool ShadeConfigFile::readTransRecord(transceiver_config_t &cfg) {
|
||||||
cfg.rxBandwidth = this->readFloat(cfg.rxBandwidth);
|
cfg.rxBandwidth = this->readFloat(cfg.rxBandwidth);
|
||||||
cfg.deviation = this->readFloat(cfg.deviation);
|
cfg.deviation = this->readFloat(cfg.deviation);
|
||||||
cfg.txPower = this->readInt8(cfg.txPower);
|
cfg.txPower = this->readInt8(cfg.txPower);
|
||||||
|
if(this->file.position() != startPos + this->header.transRecordSize) {
|
||||||
|
Serial.println("Reading to end of transceiver record");
|
||||||
|
this->seekChar(CFG_REC_END);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -947,6 +965,12 @@ bool ShadeConfigFile::writeNetRecord() {
|
||||||
this->writeVarString(settings.IP.subnet.toString().c_str());
|
this->writeVarString(settings.IP.subnet.toString().c_str());
|
||||||
this->writeVarString(settings.IP.dns1.toString().c_str());
|
this->writeVarString(settings.IP.dns1.toString().c_str());
|
||||||
this->writeVarString(settings.IP.dns2.toString().c_str());
|
this->writeVarString(settings.IP.dns2.toString().c_str());
|
||||||
|
this->writeVarString(settings.MQTT.protocol);
|
||||||
|
this->writeVarString(settings.MQTT.hostname);
|
||||||
|
this->writeUInt16(settings.MQTT.port);
|
||||||
|
this->writeBool(settings.MQTT.pubDisco);
|
||||||
|
this->writeVarString(settings.MQTT.rootTopic);
|
||||||
|
this->writeVarString(settings.MQTT.discoTopic);
|
||||||
this->writeUInt8(settings.Ethernet.boardType);
|
this->writeUInt8(settings.Ethernet.boardType);
|
||||||
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.phyType));
|
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.phyType));
|
||||||
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.CLKMode));
|
this->writeUInt8(static_cast<uint8_t>(settings.Ethernet.CLKMode));
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,12 @@ uint16_t ConfigSettings::calcNetRecSize() {
|
||||||
+ this->IP.subnet.toString().length() + 3
|
+ this->IP.subnet.toString().length() + 3
|
||||||
+ this->IP.dns1.toString().length() + 3
|
+ this->IP.dns1.toString().length() + 3
|
||||||
+ this->IP.dns2.toString().length() + 3
|
+ this->IP.dns2.toString().length() + 3
|
||||||
|
+ strlen(this->MQTT.protocol) + 3
|
||||||
|
+ strlen(this->MQTT.hostname) + 3
|
||||||
|
+ 6 // MQTT Port
|
||||||
|
+ 6 // PubDisco
|
||||||
|
+ strlen(this->MQTT.rootTopic) + 3
|
||||||
|
+ strlen(this->MQTT.discoTopic) + 3
|
||||||
+ 4 // ETH.boardType
|
+ 4 // ETH.boardType
|
||||||
+ 4 // ETH.phyType
|
+ 4 // ETH.phyType
|
||||||
+ 4 // ETH.clkMode
|
+ 4 // ETH.clkMode
|
||||||
|
|
|
||||||
64
Network.cpp
64
Network.cpp
|
|
@ -71,46 +71,44 @@ void Network::loop() {
|
||||||
mqtt.loop();
|
mqtt.loop();
|
||||||
}
|
}
|
||||||
void Network::emitSockets() {
|
void Network::emitSockets() {
|
||||||
if(WiFi.status() == WL_CONNECTED) {
|
if(this->needsBroadcast || abs(abs(WiFi.RSSI()) - abs(this->lastRSSI)) > 1 || WiFi.channel() != this->lastChannel) {
|
||||||
if(abs(abs(WiFi.RSSI()) - abs(this->lastRSSI)) > 1 || WiFi.channel() != this->lastChannel) {
|
this->emitSockets(255);
|
||||||
char buf[128];
|
sockEmit.loop();
|
||||||
snprintf(buf, sizeof(buf), "{\"ssid\":\"%s\",\"strength\":%d,\"channel\":%d}", WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.channel());
|
this->needsBroadcast = false;
|
||||||
sockEmit.sendToClients("wifiStrength", buf);
|
|
||||||
this->lastRSSI = WiFi.RSSI();
|
|
||||||
this->lastChannel = WiFi.channel();
|
|
||||||
sockEmit.loop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(this->connType == conn_types::ethernet && this->lastRSSI != -100 && this->lastChannel != -1) {
|
|
||||||
sockEmit.sendToClients("wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}");
|
|
||||||
this->lastRSSI = -100;
|
|
||||||
this->lastChannel = -1;
|
|
||||||
sockEmit.loop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Network::emitSockets(uint8_t num) {
|
void Network::emitSockets(uint8_t num) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
if(WiFi.status() == WL_CONNECTED) {
|
if(this->connType == conn_types::ethernet) {
|
||||||
snprintf(buf, sizeof(buf), "{\"ssid\":\"%s\",\"strength\":%d,\"channel\":%d}", WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.channel());
|
snprintf(buf, sizeof(buf), "{\"connected\":%s,\"speed\":%d,\"fullduplex\":%s}", this->connected() ? "true" : "false", ETH.linkSpeed(), ETH.fullDuplex() ? "true" : "false");
|
||||||
sockEmit.sendToClient(num, "wifiStrength", buf);
|
if(num == 255)
|
||||||
this->lastRSSI = WiFi.RSSI();
|
sockEmit.sendToClients("ethernet", buf);
|
||||||
this->lastChannel = WiFi.channel();
|
else
|
||||||
|
sockEmit.sendToClient(num, "ethernet", buf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(this->connType == conn_types::ethernet && this->lastRSSI != -100 && this->lastChannel != -1)
|
if(WiFi.status() == WL_CONNECTED) {
|
||||||
sockEmit.sendToClient(num, "wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}");
|
snprintf(buf, sizeof(buf), "{\"ssid\":\"%s\",\"strength\":%d,\"channel\":%d}", WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.channel());
|
||||||
this->lastRSSI = -100;
|
if(num == 255)
|
||||||
this->lastChannel = -1;
|
sockEmit.sendToClients("wifiStrength", buf);
|
||||||
|
else
|
||||||
|
sockEmit.sendToClient(num, "wifiStrength", buf);
|
||||||
|
this->lastRSSI = WiFi.RSSI();
|
||||||
|
this->lastChannel = WiFi.channel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(num == 255) {
|
||||||
|
sockEmit.sendToClients("wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}");
|
||||||
|
sockEmit.sendToClients("ethernet", "{\"connected\":false,\"speed\":0,\"fullduplex\":false}");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sockEmit.sendToClient(num, "wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}");
|
||||||
|
sockEmit.sendToClient(num, "ethernet", "{\"connected\":false,\"speed\":0,\"fullduplex\":false}");
|
||||||
|
}
|
||||||
|
this->lastRSSI = -100;
|
||||||
|
this->lastChannel = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(this->connType == conn_types::ethernet) {
|
|
||||||
snprintf(buf, sizeof(buf), "{\"connected\":true,\"speed\":%d,\"fullduplex\":%s}", ETH.linkSpeed(), ETH.fullDuplex() ? "true" : "false");
|
|
||||||
sockEmit.sendToClient(num, "ethernet", buf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sockEmit.sendToClient(num, "ethernet", "{\"connected\":false, \"speed\":0,\"fullduplex\":false}");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void Network::setConnected(conn_types connType) {
|
void Network::setConnected(conn_types connType) {
|
||||||
this->connType = connType;
|
this->connType = connType;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class Network {
|
||||||
public:
|
public:
|
||||||
bool wifiFallback = false;
|
bool wifiFallback = false;
|
||||||
bool softAPOpened = false;
|
bool softAPOpened = false;
|
||||||
|
bool needsBroadcast = true;
|
||||||
conn_types connType = conn_types::unset;
|
conn_types connType = conn_types::unset;
|
||||||
bool connected();
|
bool connected();
|
||||||
String ssid;
|
String ssid;
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,12 @@ void SocketEmitter::wsEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t
|
||||||
Serial.printf("Socket [%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
Serial.printf("Socket [%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
||||||
// Send all the current shade settings to the client.
|
// Send all the current shade settings to the client.
|
||||||
sockServer.sendTXT(num, "Connected");
|
sockServer.sendTXT(num, "Connected");
|
||||||
|
sockServer.loop();
|
||||||
settings.emitSockets(num);
|
settings.emitSockets(num);
|
||||||
somfy.emitState(num);
|
somfy.emitState(num);
|
||||||
net.emitSockets(num);
|
|
||||||
git.emitUpdateCheck(num);
|
git.emitUpdateCheck(num);
|
||||||
|
net.emitSockets(num);
|
||||||
|
sockServer.loop();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WStype_TEXT:
|
case WStype_TEXT:
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
Web.cpp
11
Web.cpp
|
|
@ -818,6 +818,16 @@ void Web::handleDiscovery(WebServer &server) {
|
||||||
snprintf(g_content, sizeof(g_content), "{\"serverId\":\"%s\",\"version\":\"%s\",\"latest\":\"%s\",\"model\":\"%s\",\"hostname\":\"%s\",\"authType\":%d,\"permissions\":%d,\"chipModel\":\"%s\",\"connType\":\"%s\",\"checkForUpdate\":%s",
|
snprintf(g_content, sizeof(g_content), "{\"serverId\":\"%s\",\"version\":\"%s\",\"latest\":\"%s\",\"model\":\"%s\",\"hostname\":\"%s\",\"authType\":%d,\"permissions\":%d,\"chipModel\":\"%s\",\"connType\":\"%s\",\"checkForUpdate\":%s",
|
||||||
settings.serverId, settings.fwVersion.name, git.latest.name, "ESPSomfyRTS", settings.hostname, static_cast<uint8_t>(settings.Security.type), settings.Security.permissions, settings.chipModel, connType, settings.checkForUpdate ? "true" : "false");
|
settings.serverId, settings.fwVersion.name, git.latest.name, "ESPSomfyRTS", settings.hostname, static_cast<uint8_t>(settings.Security.type), settings.Security.permissions, settings.chipModel, connType, settings.checkForUpdate ? "true" : "false");
|
||||||
server.send_P(200, _encoding_json, g_content);
|
server.send_P(200, _encoding_json, g_content);
|
||||||
|
/*
|
||||||
|
if(net.connType == conn_types::ethernet) {
|
||||||
|
snprintf(g_content, sizeof(g_content), ",\"ethernet\":{\"connected\":true,\"speed\":%d,\"fullduplex\":%s}", ETH.linkSpeed(), ETH.fullDuplex() ? "true" : "false");
|
||||||
|
server.sendContent(g_content);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snprintf(g_content, sizeof(g_content), ",\"wifi\":{\"ssid\":\"%s\",\"strength\":%d,\"channel\":%d}", WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.channel());
|
||||||
|
server.sendContent(g_content);
|
||||||
|
}
|
||||||
|
*/
|
||||||
server.sendContent(",\"rooms\":");
|
server.sendContent(",\"rooms\":");
|
||||||
this->chunkRoomsResponse(server);
|
this->chunkRoomsResponse(server);
|
||||||
server.sendContent(",\"shades\":");
|
server.sendContent(",\"shades\":");
|
||||||
|
|
@ -826,6 +836,7 @@ void Web::handleDiscovery(WebServer &server) {
|
||||||
this->chunkGroupsResponse(server);
|
this->chunkGroupsResponse(server);
|
||||||
server.sendContent("}");
|
server.sendContent("}");
|
||||||
server.sendContent("", 0);
|
server.sendContent("", 0);
|
||||||
|
net.needsBroadcast = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
server.send(500, _encoding_text, "Invalid http method");
|
server.send(500, _encoding_text, "Invalid http method");
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="main.css?v=2.4.0a" type="text/css" />
|
<link rel="stylesheet" href="main.css?v=2.4.0c" type="text/css" />
|
||||||
<link rel="stylesheet" href="widgets.css?v=2.4.0a" type="text/css" />
|
<link rel="stylesheet" href="widgets.css?v=2.4.0c" type="text/css" />
|
||||||
<link rel="stylesheet" href="icons.css?v=2.4.0a" type="text/css" />
|
<link rel="stylesheet" href="icons.css?v=2.4.0c" type="text/css" />
|
||||||
<link rel="icon" type="image/png" href="favicon.png" />
|
<link rel="icon" type="image/png" href="favicon.png" />
|
||||||
<script type="text/javascript" src="index.js?v=2.4.0a"></script>
|
<script type="text/javascript" src="index.js?v=2.4.0c"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="divContainer" class="container main" data-auth="false">
|
<div id="divContainer" class="container main" data-auth="false">
|
||||||
|
|
|
||||||
|
|
@ -571,7 +571,7 @@ async function initSockets() {
|
||||||
};
|
};
|
||||||
socket.onclose = (evt) => {
|
socket.onclose = (evt) => {
|
||||||
wifi.procWifiStrength({ ssid: '', channel: -1, strength: -100 });
|
wifi.procWifiStrength({ ssid: '', channel: -1, strength: -100 });
|
||||||
wifi.procEthernet({ connected: '', speed: 0, fullduplex: false });
|
wifi.procEthernet({ connected: false, speed: 0, fullduplex: false });
|
||||||
if (document.getElementsByClassName('socket-wait').length === 0)
|
if (document.getElementsByClassName('socket-wait').length === 0)
|
||||||
ui.waitMessage(document.getElementById('divContainer')).classList.add('socket-wait');
|
ui.waitMessage(document.getElementById('divContainer')).classList.add('socket-wait');
|
||||||
if (evt.wasClean) {
|
if (evt.wasClean) {
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="main.css?v=2.0.0" type="text/css" />
|
<link rel="stylesheet" href="main.css?v=2.4.0" type="text/css" />
|
||||||
<link rel="stylesheet" href="widgets.css?v=2.0.0" type="text/css" />
|
<link rel="stylesheet" href="widgets.css?v=2.4.0" type="text/css" />
|
||||||
<link rel="stylesheet" href="icons.css?v=2.0.0" type="text/css" />
|
<link rel="stylesheet" href="icons.css?v=2.4.0" type="text/css" />
|
||||||
<link rel="icon" type="image/png" href="favicon.png" />
|
<link rel="icon" type="image/png" href="favicon.png" />
|
||||||
<script type="text/javascript" src="index.js?v=2.0.0"></script>
|
<script type="text/javascript" src="index.js?v=2.4.0"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="general.loadLogin();">
|
<body onload="general.loadLogin();">
|
||||||
<div id="divContainer" class="container" data-securitytype="0">
|
<div id="divContainer" class="container" data-securitytype="0">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue