51 lines
1.4 KiB
Arduino
51 lines
1.4 KiB
Arduino
#include <HTTPClient.h>
|
|
#include <WiFi.h>
|
|
|
|
const char* SERVER_URL = "http://192.168.1.100:8880/send";
|
|
const char* APP_TOKEN = ""; // Set your application token here
|
|
|
|
const char* WIFI_SSID = "YourWiFiSSID";
|
|
const char* WIFI_PASSWORD = "YourWiFiPassword";
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
}
|
|
Serial.println("\nWiFi connected");
|
|
}
|
|
|
|
void sendTelegramMessage(const char* message) {
|
|
if (WiFi.status() == WL_CONNECTED) {
|
|
HTTPClient http;
|
|
http.begin(SERVER_URL);
|
|
http.addHeader("Content-Type", "application/json");
|
|
|
|
if (strlen(APP_TOKEN) > 0) {
|
|
http.addHeader("X-App-Token", APP_TOKEN);
|
|
}
|
|
|
|
String payload = "{\"text\":\"" + String(message) + "\"}";
|
|
int httpResponseCode = http.POST(payload);
|
|
|
|
if (httpResponseCode > 0) {
|
|
String response = http.getString();
|
|
Serial.println("HTTP Response: " + String(httpResponseCode));
|
|
Serial.println(response);
|
|
} else {
|
|
Serial.println("Error: " + String(httpResponseCode));
|
|
}
|
|
|
|
http.end();
|
|
} else {
|
|
Serial.println("WiFi not connected");
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
sendTelegramMessage("Hello from ESP32!");
|
|
delay(60000); // Send every minute
|
|
} |