Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add standalone setup for stamps3 wifi

Geoa286bf3de0a5
diff --git a/src/Vendors/S3WifiSetup.cpp b/src/Vendors/S3WifiSetup.cpp
new file mode 100644
index 00000000..c498b3a0
--- /dev/null
+++ b/src/Vendors/S3WifiSetup.cpp
@@ -0,0 +1,65 @@
+#ifdef DEVICE_M5STAMPS3
+
+#include "S3WifiSetup.h"
+#include <Preferences.h>
+#include <WiFi.h>
+#include <Arduino.h>
+#include <FastLED.h>
+
+#define NVS_SSID_KEY "ssid"
+#define NVS_PASS_KEY "pass"
+
+#define NUM_LEDS 1
+CRGB leds[NUM_LEDS];
+
+Preferences& getPreferences() {
+ static Preferences preferences;
+ return preferences;
+}
+
+bool loadWifiCredentials(String& ssid, String& password) {
+ Preferences& preferences = getPreferences();
+ preferences.begin("wifi_settings", true); // readonly = true
+ ssid = preferences.getString(NVS_SSID_KEY, "");
+ password = preferences.getString(NVS_PASS_KEY, "");
+ preferences.end();
+ return !ssid.isEmpty() && !password.isEmpty();
+}
+
+bool setupS3Wifi() {
+ // LED RGB init
+ FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
+ leds[0] = CRGB::White;
+ FastLED.show();
+
+ String ssid, password;
+ if (!loadWifiCredentials(ssid, password)) {
+ leds[0] = CRGB::Blue;
+ FastLED.show();
+ delay(2000);
+ FastLED.clear(true);
+ return false;
+ }
+
+ WiFi.begin(ssid.c_str(), password.c_str());
+
+ for (int i = 0; i < 10; ++i) {
+ if (WiFi.status() == WL_CONNECTED) {
+ leds[0] = CRGB::Green;
+ FastLED.show();
+ delay(1000);
+ FastLED.clear(true);
+ return true;
+ }
+ delay(1000);
+ }
+
+ leds[0] = CRGB::Red;
+ FastLED.show();
+ delay(1000);
+ FastLED.clear(true);
+
+ return false;
+}
+
+#endif
diff --git a/src/Vendors/S3WifiSetup.h b/src/Vendors/S3WifiSetup.h
new file mode 100644
index 00000000..7dd37729
--- /dev/null
+++ b/src/Vendors/S3WifiSetup.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#ifdef DEVICE_M5STAMPS3
+
+bool setupS3Wifi();
+
+#endif
\ No newline at end of file