commit 971e55c1aa6540e6d7cd9659e07aeeb141fb64b6 Author: Adil Sadqi Date: Tue May 21 13:54:52 2024 +0000 Upload files to "/" diff --git a/M5Stick-IAM-wifi-hack.zip b/M5Stick-IAM-wifi-hack.zip new file mode 100644 index 0000000..b245131 Binary files /dev/null and b/M5Stick-IAM-wifi-hack.zip differ diff --git a/router+message.ino b/router+message.ino new file mode 100644 index 0000000..e3f42ff --- /dev/null +++ b/router+message.ino @@ -0,0 +1,63 @@ +#include +#include + +const char *homeSSID = "Home"; +const char *homePassword = "Smart@2018"; +const char *apSSID = "M5"; +const char *apPassword = "123456789"; +const char *server = "notify.sadqi.eu.org"; +const int port = 80; + +void connectToHomeWiFi() { + M5.Lcd.println("Connecting to Home WiFi..."); + WiFi.begin(homeSSID, homePassword); + + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.println("Connecting to Home WiFi..."); + } + + M5.Lcd.println("Connected to Home WiFi"); +} + +void setupAccessPoint() { + M5.Lcd.println("Setting up Access Point..."); + WiFi.softAP(apSSID, apPassword); + M5.Lcd.println("Access Point created"); +} + +void setup() { + M5.begin(); + Serial.begin(115200); + + // Connect to Home WiFi + connectToHomeWiFi(); + + // Setup Access Point + setupAccessPoint(); +} + +void loop() { + HTTPClient http; + + M5.Lcd.println("Sending message..."); + + if (http.begin("http://notify.sadqi.eu.org/sadqi")) { + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + + int httpResponseCode = http.POST("Connected"); + + if (httpResponseCode > 0) { + M5.Lcd.println("Message sent successfully!"); + } else { + M5.Lcd.print("Error sending message. HTTP error code: "); + M5.Lcd.println(httpResponseCode); + } + + http.end(); + } else { + M5.Lcd.println("Unable to connect to server"); + } + + delay(5000); // Wait for 5 seconds before sending the next message +} diff --git a/router+message.txt b/router+message.txt new file mode 100644 index 0000000..e3f42ff --- /dev/null +++ b/router+message.txt @@ -0,0 +1,63 @@ +#include +#include + +const char *homeSSID = "Home"; +const char *homePassword = "Smart@2018"; +const char *apSSID = "M5"; +const char *apPassword = "123456789"; +const char *server = "notify.sadqi.eu.org"; +const int port = 80; + +void connectToHomeWiFi() { + M5.Lcd.println("Connecting to Home WiFi..."); + WiFi.begin(homeSSID, homePassword); + + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.println("Connecting to Home WiFi..."); + } + + M5.Lcd.println("Connected to Home WiFi"); +} + +void setupAccessPoint() { + M5.Lcd.println("Setting up Access Point..."); + WiFi.softAP(apSSID, apPassword); + M5.Lcd.println("Access Point created"); +} + +void setup() { + M5.begin(); + Serial.begin(115200); + + // Connect to Home WiFi + connectToHomeWiFi(); + + // Setup Access Point + setupAccessPoint(); +} + +void loop() { + HTTPClient http; + + M5.Lcd.println("Sending message..."); + + if (http.begin("http://notify.sadqi.eu.org/sadqi")) { + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + + int httpResponseCode = http.POST("Connected"); + + if (httpResponseCode > 0) { + M5.Lcd.println("Message sent successfully!"); + } else { + M5.Lcd.print("Error sending message. HTTP error code: "); + M5.Lcd.println(httpResponseCode); + } + + http.end(); + } else { + M5.Lcd.println("Unable to connect to server"); + } + + delay(5000); // Wait for 5 seconds before sending the next message +} diff --git a/router+portal.ino b/router+portal.ino new file mode 100644 index 0000000..f3dbabd --- /dev/null +++ b/router+portal.ino @@ -0,0 +1,83 @@ +#include +#include +#include + +const char *homeSSID = "Home"; +const char *homePassword = "Smart@2018"; +const char *apSSID = "M5"; +const char *apPassword = "123456789"; +const char *server = "notify.sadqi.eu.org"; +const int port = 80; + +AsyncWebServer server(80); + +// Hardcoded list of connection codes +const char *validConnectionCodes[] = {"code1", "code2", "code3"}; + +bool isValidCode(const String &code) { + for (const char *validCode : validConnectionCodes) { + if (code.equals(validCode)) { + return true; + } + } + return false; +} + +void connectToHomeWiFi() { + M5.Lcd.println("Connecting to Home WiFi..."); + WiFi.begin(homeSSID, homePassword); + + int attempts = 0; + while (WiFi.status() != WL_CONNECTED && attempts < 20) { + delay(1000); + Serial.print("."); + attempts++; + } + + if (WiFi.status() == WL_CONNECTED) { + M5.Lcd.println("\nConnected to Home WiFi"); + } else { + M5.Lcd.println("\nFailed to connect to Home WiFi. Creating Access Point."); + setupAccessPoint(); + } +} + +void setupAccessPoint() { + M5.Lcd.println("Setting up Access Point..."); + WiFi.softAP(apSSID, apPassword); + M5.Lcd.println("Access Point created"); + + // Set up the captive portal + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ + if (request->hasParam("code")) { + String enteredCode = request->getParam("code")->value(); + if (isValidCode(enteredCode)) { + request->send(200, "text/html", "

Connected to Internet!

"); + // Implement the logic to allow internet access for the user here + // E.g., you might use WiFi.begin() with the user's WiFi credentials + } else { + request->send(200, "text/html", "

Invalid Connection Code

"); + } + } else { + request->send(200, "text/html", "

Enter Connection Code:



"); + } + }); + + server.begin(); +} + +void setup() { + M5.begin(); + Serial.begin(115200); + + M5.Lcd.println("Booting..."); + + // Connect to Home WiFi + connectToHomeWiFi(); +} + +void loop() { + // Your main loop logic goes here + + delay(5000); // Wait for 5 seconds before repeating the loop +}