64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
|
#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
|
||
|
}
|