Added WiFi signal status and settings
This commit is contained in:
parent
e29d53574e
commit
d6e9610721
5 changed files with 68 additions and 2 deletions
2
data
2
data
|
@ -1 +1 @@
|
||||||
Subproject commit d25284e3a47a9efe6c0a8877e8abeac098ced8af
|
Subproject commit b38dabec52a55d79e090d3db4b5f2432d075bc0f
|
|
@ -1,4 +1,4 @@
|
||||||
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
||||||
|
|
||||||
idf_component_register(SRCS ${app_sources})
|
idf_component_register(SRCS ${app_sources})
|
||||||
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++11)
|
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++17)
|
||||||
|
|
|
@ -21,6 +21,7 @@ void setup()
|
||||||
if (mcp.digitalRead(3) == LOW)
|
if (mcp.digitalRead(3) == LOW)
|
||||||
{
|
{
|
||||||
preferences.putBool("wifiConfigured", false);
|
preferences.putBool("wifiConfigured", false);
|
||||||
|
preferences.remove("txPower");
|
||||||
|
|
||||||
WiFi.eraseAP();
|
WiFi.eraseAP();
|
||||||
queueLedEffect(LED_EFFECT_WIFI_ERASE_SETTINGS);
|
queueLedEffect(LED_EFFECT_WIFI_ERASE_SETTINGS);
|
||||||
|
@ -51,6 +52,7 @@ void tryImprovSetup()
|
||||||
{
|
{
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
|
|
||||||
|
|
||||||
if (!preferences.getBool("wifiConfigured", false))
|
if (!preferences.getBool("wifiConfigured", false))
|
||||||
{
|
{
|
||||||
setFgColor(GxEPD_BLACK);
|
setFgColor(GxEPD_BLACK);
|
||||||
|
@ -143,6 +145,12 @@ void tryImprovSetup()
|
||||||
WiFi.setAutoConnect(true);
|
WiFi.setAutoConnect(true);
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
|
if(preferences.getInt("txPower", 0)) {
|
||||||
|
if(WiFi.setTxPower(static_cast<wifi_power_t>(preferences.getInt("txPower", 0)))) {
|
||||||
|
Serial.printf("WiFi max tx power set to %d\n", preferences.getInt("txPower", 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,8 @@ void setupWebserver()
|
||||||
|
|
||||||
server.on("/api/status", HTTP_GET, onApiStatus);
|
server.on("/api/status", HTTP_GET, onApiStatus);
|
||||||
server.on("/api/system_status", HTTP_GET, onApiSystemStatus);
|
server.on("/api/system_status", HTTP_GET, onApiSystemStatus);
|
||||||
|
server.on("/api/wifi_set_tx_power", HTTP_GET, onApiSetWifiTxPower);
|
||||||
|
|
||||||
server.on("/api/full_refresh", HTTP_GET, onApiFullRefresh);
|
server.on("/api/full_refresh", HTTP_GET, onApiFullRefresh);
|
||||||
|
|
||||||
server.on("/api/action/pause", HTTP_GET, onApiActionPause);
|
server.on("/api/action/pause", HTTP_GET, onApiActionPause);
|
||||||
|
@ -104,6 +106,8 @@ StaticJsonDocument<768> getStatusObject()
|
||||||
conStatus["price"] = isPriceNotifyConnected();
|
conStatus["price"] = isPriceNotifyConnected();
|
||||||
conStatus["blocks"] = isBlockNotifyConnected();
|
conStatus["blocks"] = isBlockNotifyConnected();
|
||||||
|
|
||||||
|
root["rssi"] = WiFi.RSSI();
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +348,27 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.containsKey("txPower")) {
|
||||||
|
int txPower = settings["txPower"].as<int>();
|
||||||
|
|
||||||
|
if (txPower == 80) {
|
||||||
|
preferences.remove("txPower");
|
||||||
|
if (WiFi.getTxPower() != 80) {
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
} else if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <= txPower &&
|
||||||
|
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm)) {
|
||||||
|
// is valid value
|
||||||
|
|
||||||
|
|
||||||
|
if(WiFi.setTxPower(static_cast<wifi_power_t>(txPower))) {
|
||||||
|
Serial.printf("Set WiFi Tx power to: %d\n", txPower);
|
||||||
|
preferences.putInt("txPower", txPower);
|
||||||
|
settingsChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
if (settingsChanged)
|
if (settingsChanged)
|
||||||
{
|
{
|
||||||
|
@ -393,6 +418,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
||||||
root["hostnamePrefix"] = preferences.getString("hostnamePrefix", "btclock");
|
root["hostnamePrefix"] = preferences.getString("hostnamePrefix", "btclock");
|
||||||
root["hostname"] = getMyHostname();
|
root["hostname"] = getMyHostname();
|
||||||
root["ip"] = WiFi.localIP();
|
root["ip"] = WiFi.localIP();
|
||||||
|
root["txPower"] = WiFi.getTxPower();
|
||||||
|
|
||||||
#ifdef GIT_REV
|
#ifdef GIT_REV
|
||||||
root["gitRev"] = String(GIT_REV);
|
root["gitRev"] = String(GIT_REV);
|
||||||
|
@ -672,12 +698,42 @@ void onApiSystemStatus(AsyncWebServerRequest *request)
|
||||||
root["espHeapSize"] = ESP.getHeapSize();
|
root["espHeapSize"] = ESP.getHeapSize();
|
||||||
root["espFreePsram"] = ESP.getFreePsram();
|
root["espFreePsram"] = ESP.getFreePsram();
|
||||||
root["espPsramSize"] = ESP.getPsramSize();
|
root["espPsramSize"] = ESP.getPsramSize();
|
||||||
|
root["rssi"] = WiFi.RSSI();
|
||||||
|
root["txPower"] = WiFi.getTxPower();
|
||||||
|
|
||||||
serializeJson(root, *response);
|
serializeJson(root, *response);
|
||||||
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STRINGIFY(x) #x
|
||||||
|
#define ENUM_TO_STRING(x) STRINGIFY(x)
|
||||||
|
|
||||||
|
|
||||||
|
void onApiSetWifiTxPower(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
if (request->hasParam("txPower")) {
|
||||||
|
AsyncWebParameter *txPowerParam = request->getParam("txPower");
|
||||||
|
int txPower = txPowerParam->value().toInt();
|
||||||
|
if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <= txPower &&
|
||||||
|
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm)) {
|
||||||
|
// is valid value
|
||||||
|
String txPowerName = std::to_string(static_cast<std::underlying_type_t<wifi_power_t>>(txPower)).c_str();
|
||||||
|
|
||||||
|
Serial.printf("Set WiFi Tx power to: %s\n", txPowerName);
|
||||||
|
|
||||||
|
if(WiFi.setTxPower(static_cast<wifi_power_t>(txPower))) {
|
||||||
|
preferences.putInt("txPower", txPower);
|
||||||
|
request->send(200, "application/json", "{\"setTxPower\": \"ok\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return request->send(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void onApiLightsStatus(AsyncWebServerRequest *request)
|
void onApiLightsStatus(AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "lib/block_notify.hpp"
|
#include "lib/block_notify.hpp"
|
||||||
#include "lib/price_notify.hpp"
|
#include "lib/price_notify.hpp"
|
||||||
|
@ -21,6 +22,7 @@ bool processEpdColorSettings(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
void onApiStatus(AsyncWebServerRequest *request);
|
void onApiStatus(AsyncWebServerRequest *request);
|
||||||
void onApiSystemStatus(AsyncWebServerRequest *request);
|
void onApiSystemStatus(AsyncWebServerRequest *request);
|
||||||
|
void onApiSetWifiTxPower(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
void onApiShowScreen(AsyncWebServerRequest *request);
|
void onApiShowScreen(AsyncWebServerRequest *request);
|
||||||
void onApiShowText(AsyncWebServerRequest *request);
|
void onApiShowText(AsyncWebServerRequest *request);
|
||||||
|
|
Loading…
Reference in a new issue