Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve WPS stability and a small lighting fix #116

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EleksTubeHAX_pio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html

[env:EleksTubeHax]
platform = espressif32
platform = espressif32@5.4.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like to use specific versions, but we want to keep it simpler for beginners, so no specific versions in the "public" version of the platformio.ini please.
I have and use my "private" one, with very specific verisons sometimes for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rolled back since it didn't fix the problem anyways

board = esp32dev
framework = arduino

Expand Down
6 changes: 5 additions & 1 deletion EleksTubeHAX_pio/src/Backlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ void Backlights::rainbowPattern()
}
if (dimming)
{
setBrightness(0xFF >> max_intensity - (uint8_t)BACKLIGHT_DIMMED_INTENSITY - 1);
#if BACKLIGHT_DIMMED_INTENSITY > 0
setBrightness(0xFF >> max_intensity - (uint8_t)BACKLIGHT_DIMMED_INTENSITY - 1);
#else //turn off backlight if intensity is 0
setBrightness(0);
#endif
}
else
{
Expand Down
12 changes: 8 additions & 4 deletions EleksTubeHAX_pio/src/WiFi_WPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "TFTs.h"
#include "esp_wps.h"
#include "WiFi_WPS.h"
#include "sdkconfig.h"

#include "IPGeolocation_AO.h"

Expand All @@ -19,6 +20,7 @@ double GeoLocTZoffset = 0;
static esp_wps_config_t wps_config;
void wpsInitConfig()
{
memset(&wps_config, 0, sizeof(esp_wps_config_t));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be the safest way to init.

We could also just use the macro from Expressif ;)

static esp_wps_config_t wps_config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);

Copy link
Contributor Author

@bitrot-alpha bitrot-alpha Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like using vendor specific macros when it literally does the same thing as a standard C function that every good C programmer should know about. This memset call also matches the Arduino WPS example.

VS Code also gave me a weird squiggly for that macro since we don't directly #include whatever header that macro comes from, not that it really matters.

Just being an opinionated C programmer lol

wps_config.wps_type = ESP_WPS_MODE;
strcpy(wps_config.factory_info.manufacturer, ESP_MANUFACTURER);
strcpy(wps_config.factory_info.model_number, ESP_MODEL_NUMBER);
Expand Down Expand Up @@ -61,6 +63,7 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
WifiState = wps_failed;
Serial.println("WPS Failed, retrying");
esp_wifi_wps_disable();
wpsInitConfig();
esp_wifi_wps_enable(&wps_config);
esp_wifi_wps_start(0);
break;
Expand All @@ -70,6 +73,7 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
tfts.print("/"); // retry
tfts.setTextColor(TFT_BLUE, TFT_BLACK);
esp_wifi_wps_disable();
wpsInitConfig();
esp_wifi_wps_enable(&wps_config);
esp_wifi_wps_start(0);
WifiState = wps_active;
Expand Down Expand Up @@ -173,8 +177,7 @@ void WifiReconnect()
void WiFiStartWps()
{
// erase settings
snprintf(stored_config.config.wifi.ssid, sizeof(stored_config.config.wifi.ssid), "%s", WiFi.SSID().c_str());
stored_config.config.wifi.password[0] = '\0'; // empty string as password
memset(&stored_config.config.wifi, 0, sizeof(stored_config.config.wifi)); //zero out the entire WiFi config
stored_config.config.wifi.WPS_connected = 0x11; // invalid = different than 0x55
Serial.println(""); Serial.print("Saving config! Triggered from WPS start...");
stored_config.save();
Expand Down Expand Up @@ -208,9 +211,10 @@ void WiFiStartWps()
}
tfts.setTextColor(TFT_WHITE, TFT_BLACK);
snprintf(stored_config.config.wifi.ssid, sizeof(stored_config.config.wifi.ssid), "%s", WiFi.SSID().c_str()); // Copy the SSID into the stored configuration safely
stored_config.config.wifi.password[0] = '\0'; // Since the password cannot be retrieved from WPS, set it to an empty string
memset(&stored_config.config.wifi.password, 0, sizeof(stored_config.config.wifi.password)); // Since the password cannot be retrieved from WPS, set it to an empty string
stored_config.config.wifi.WPS_connected = StoredConfig::valid; // Mark the configuration as valid
Serial.println(); Serial.print("Saving config! Triggered from WPS success...");
Serial.println();
Serial.print("Saving config! Triggered from WPS success...");
stored_config.save();
Serial.println(" WPS finished.");
}
Expand Down
1 change: 1 addition & 0 deletions EleksTubeHAX_pio/src/WiFi_WPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define WIFI_WPS_H

#include "GLOBAL_DEFINES.h"
#include <string.h>

enum WifiState_t
{
Expand Down