Upload files to "/"
This commit is contained in:
commit
971e55c1aa
Binary file not shown.
|
@ -0,0 +1,63 @@
|
||||||
|
#include <M5StickCPlus.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
#include <M5StickCPlus.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include <M5StickCPlus.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
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", "<html><body><h1>Connected to Internet!</h1></body></html>");
|
||||||
|
// 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", "<html><body><h1>Invalid Connection Code</h1></body></html>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
request->send(200, "text/html", "<html><body><h1>Enter Connection Code:</h1><form><input type='text' name='code' placeholder='Connection Code'><br><br><button type='submit'>Connect</button></form></body></html>");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue