Skip to content

Commit

Permalink
Add compliance mode to limit trasmitter power to FCC certified values
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirenliel committed Nov 8, 2023
1 parent 14f2752 commit 8a00376
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/network/wifihandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 8a00376

Please sign in to comment.