From 8a0037620094786ff264f4a25a05441391178c39 Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Wed, 8 Nov 2023 17:57:41 +0100 Subject: [PATCH] Add compliance mode to limit trasmitter power to FCC certified values --- src/debug.h | 6 ++++++ src/network/wifihandler.cpp | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/debug.h b/src/debug.h index 1e5075628..e41e0bca3 100644 --- a/src/debug.h +++ b/src/debug.h @@ -80,6 +80,12 @@ #define I2C_SPEED 400000 +#define COMPLIANCE_MODE true +#define USE_ATTENUATION COMPLIANCE_MODE && ESP8266 +#define ATTENUATION_N 10.0 / 4.0 +#define ATTENUATION_G 14.0 / 4.0 +#define ATTENUATION_B 40.0 / 4.0 + // Send inspection packets over the network to a profiler // Not recommended for production #define ENABLE_INSPECTION false diff --git a/src/network/wifihandler.cpp b/src/network/wifihandler.cpp index e701a6afc..4119c93c9 100644 --- a/src/network/wifihandler.cpp +++ b/src/network/wifihandler.cpp @@ -76,6 +76,9 @@ void WiFiNetwork::setUp() { WiFi.persistent(true); WiFi.mode(WIFI_STA); #if ESP8266 + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_N); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11N); #endif WiFi.hostname("SlimeVR FBT Tracker"); @@ -149,6 +152,9 @@ void WiFiNetwork::upkeep() { // But only if there are credentials, otherwise we just waste time before // switching to hardcoded credentials. if (WiFi.SSID().length() > 0) { + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_G); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11G); setStaticIPIfDefined(); WiFi.begin(); @@ -165,6 +171,9 @@ void WiFiNetwork::upkeep() { #if defined(WIFI_CREDS_SSID) && defined(WIFI_CREDS_PASSWD) // Try hardcoded credentials now #if ESP8266 + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_N); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11N); #endif setStaticIPIfDefined(); @@ -178,6 +187,9 @@ void WiFiNetwork::upkeep() { case SLIME_WIFI_HARDCODE_ATTEMPT: // Couldn't connect with second set of credentials #if defined(WIFI_CREDS_SSID) && defined(WIFI_CREDS_PASSWD) && ESP8266 // Try hardcoded credentials again, but with PHY Mode G + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_G); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11G); setStaticIPIfDefined(); WiFi.begin(WIFI_CREDS_SSID, WIFI_CREDS_PASSWD); @@ -190,6 +202,9 @@ void WiFiNetwork::upkeep() { case SLIME_WIFI_SERVER_CRED_ATTEMPT: // Couldn't connect with server-sent credentials. #if ESP8266 // Try again silently but with 11G + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_G); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11G); setStaticIPIfDefined(); WiFi.begin(); @@ -201,6 +216,9 @@ void WiFiNetwork::upkeep() { case SLIME_WIFI_SERVER_CRED_G_ATTEMPT: // Or if couldn't connect with server-sent credentials // Return to the default PHY Mode N. #if ESP8266 + #if USE_ATTENUATION + WiFi.setOutputPower(20.0 - ATTENUATION_N); + #endif WiFi.setPhyMode(WIFI_PHY_MODE_11N); #endif // Start smart config