mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-13 23:45:25 +00:00
Expose TX power adjustment
This commit is contained in:
parent
fb8d9e51a6
commit
5cfb58c2e6
@ -37,11 +37,14 @@ bool AmsConfiguration::setWiFiConfig(WiFiConfig& config) {
|
||||
wifiChanged |= strcmp(config.ssid, existing.ssid) != 0;
|
||||
wifiChanged |= strcmp(config.psk, existing.psk) != 0;
|
||||
wifiChanged |= strcmp(config.ip, existing.ip) != 0;
|
||||
wifiChanged |= strcmp(config.gateway, existing.gateway) != 0;
|
||||
wifiChanged |= strcmp(config.subnet, existing.subnet) != 0;
|
||||
wifiChanged |= strcmp(config.dns1, existing.dns1) != 0;
|
||||
wifiChanged |= strcmp(config.dns2, existing.dns2) != 0;
|
||||
if(strlen(config.ip) > 0) {
|
||||
wifiChanged |= strcmp(config.gateway, existing.gateway) != 0;
|
||||
wifiChanged |= strcmp(config.subnet, existing.subnet) != 0;
|
||||
wifiChanged |= strcmp(config.dns1, existing.dns1) != 0;
|
||||
wifiChanged |= strcmp(config.dns2, existing.dns2) != 0;
|
||||
}
|
||||
wifiChanged |= strcmp(config.hostname, existing.hostname) != 0;
|
||||
wifiChanged |= config.power != existing.power;
|
||||
} else {
|
||||
wifiChanged = true;
|
||||
}
|
||||
@ -627,6 +630,14 @@ bool AmsConfiguration::hasConfig() {
|
||||
configVersion = 0;
|
||||
return false;
|
||||
}
|
||||
case 92:
|
||||
configVersion = -1; // Prevent loop
|
||||
if(relocateConfig92()) {
|
||||
configVersion = 93;
|
||||
} else {
|
||||
configVersion = 0;
|
||||
return false;
|
||||
}
|
||||
case EEPROM_CHECK_SUM:
|
||||
return true;
|
||||
default:
|
||||
@ -755,6 +766,27 @@ bool AmsConfiguration::relocateConfig91() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::relocateConfig92() {
|
||||
WiFiConfig wifi;
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_WIFI_START, wifi);
|
||||
#if defined(ESP32)
|
||||
wifi.power = 195;
|
||||
#elif defined(ESP8266)
|
||||
wifi.power = 205;
|
||||
#endif
|
||||
EEPROM.put(CONFIG_WIFI_START, wifi);
|
||||
|
||||
EnergyAccountingConfig eac;
|
||||
clearEnergyAccountingConfig(eac);
|
||||
EEPROM.put(CONFIG_ENERGYACCOUNTING_START, eac);
|
||||
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, 93);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::save() {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, EEPROM_CHECK_SUM);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#define EEPROM_SIZE 1024*3
|
||||
#define EEPROM_CHECK_SUM 92 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CHECK_SUM 93 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CONFIG_ADDRESS 0
|
||||
#define EEPROM_TEMP_CONFIG_ADDRESS 2048
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#define CONFIG_GPIO_START 266
|
||||
#define CONFIG_ENTSOE_START 290
|
||||
#define CONFIG_WIFI_START 360
|
||||
#define CONFIG_ENERGYACCOUNTING_START 520
|
||||
#define CONFIG_ENERGYACCOUNTING_START 576
|
||||
#define CONFIG_WEB_START 648
|
||||
#define CONFIG_DEBUG_START 824
|
||||
#define CONFIG_DOMOTICZ_START 856
|
||||
@ -52,7 +52,8 @@ struct WiFiConfig {
|
||||
char dns2[16];
|
||||
char hostname[32];
|
||||
bool mdns;
|
||||
}; // 209
|
||||
uint8_t power;
|
||||
}; // 210
|
||||
|
||||
struct MqttConfig86 {
|
||||
char host[128];
|
||||
@ -257,6 +258,7 @@ private:
|
||||
bool relocateConfig87(); // 1.5.4
|
||||
bool relocateConfig90(); // 2.0.0
|
||||
bool relocateConfig91(); // 2.0.2
|
||||
bool relocateConfig92(); // 2.0.3
|
||||
|
||||
int readString(int pAddress, char* pString[]);
|
||||
int readInt(int pAddress, int *pValue);
|
||||
|
||||
@ -988,6 +988,32 @@ void WiFi_connect() {
|
||||
wifiReconnectCount++;
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
#if defined(ESP32)
|
||||
if(wifi.power >= 195)
|
||||
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
||||
else if(wifi.power >= 190)
|
||||
WiFi.setTxPower(WIFI_POWER_19dBm);
|
||||
else if(wifi.power >= 185)
|
||||
WiFi.setTxPower(WIFI_POWER_18_5dBm);
|
||||
else if(wifi.power >= 170)
|
||||
WiFi.setTxPower(WIFI_POWER_17dBm);
|
||||
else if(wifi.power >= 150)
|
||||
WiFi.setTxPower(WIFI_POWER_15dBm);
|
||||
else if(wifi.power >= 130)
|
||||
WiFi.setTxPower(WIFI_POWER_13dBm);
|
||||
else if(wifi.power >= 110)
|
||||
WiFi.setTxPower(WIFI_POWER_11dBm);
|
||||
else if(wifi.power >= 85)
|
||||
WiFi.setTxPower(WIFI_POWER_8_5dBm);
|
||||
else if(wifi.power >= 70)
|
||||
WiFi.setTxPower(WIFI_POWER_7dBm);
|
||||
else if(wifi.power >= 50)
|
||||
WiFi.setTxPower(WIFI_POWER_5dBm);
|
||||
else if(wifi.power >= 20)
|
||||
WiFi.setTxPower(WIFI_POWER_2dBm);
|
||||
#elif defined(ESP8266)
|
||||
WiFi.setOutputPower(wifi.power / 10.0);
|
||||
#endif
|
||||
if(strlen(wifi.ip) > 0) {
|
||||
IPAddress ip, gw, sn(255,255,255,0), dns1, dns2;
|
||||
ip.fromString(wifi.ip);
|
||||
|
||||
@ -514,6 +514,12 @@ void AmsWebServer::configWifiHtml() {
|
||||
}
|
||||
html.replace("{h}", wifi.hostname);
|
||||
html.replace("{m}", wifi.mdns ? "checked" : "");
|
||||
html.replace("{w}", String(wifi.power / 10.0, 1));
|
||||
#if defined(ESP32)
|
||||
html.replace("{wm}", "19.5");
|
||||
#elif defined(ESP8266)
|
||||
html.replace("{wm}", "20.5");
|
||||
#endif
|
||||
|
||||
server.setContentLength(html.length() + HEAD_HTML_LEN + FOOT_HTML_LEN);
|
||||
server.send_P(200, "text/html", HEAD_HTML);
|
||||
@ -1187,6 +1193,7 @@ void AmsWebServer::handleSave() {
|
||||
if(server.hasArg("h") && !server.arg("h").isEmpty()) {
|
||||
strcpy(wifi.hostname, server.arg("h").c_str());
|
||||
}
|
||||
wifi.power = server.arg("w").toFloat() * 10;
|
||||
config->setWiFiConfig(wifi);
|
||||
}
|
||||
|
||||
|
||||
@ -77,6 +77,18 @@
|
||||
<input type="text" name="d2" class="form-control sip" pattern="\d?\d?\d.\d?\d?\d.\d?\d?\d.\d?\d?\d" value="{d2}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3 col-md-4 col-sm-6 form-group">
|
||||
<div class="input-group input-group-sm">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Power</span>
|
||||
</div>
|
||||
<input type="number" name="w" class="form-control text-right" min="0" max="{wm}" step="0.5" value="{w}"/>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">dBm</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user