#define BLYNK_TEMPLATE_ID "TMPL3fDpyvlGx"
#define BLYNK_TEMPLATE_NAME "ESP32dronetakeoff"
#define BLYNK_AUTH_TOKEN "u5Dy5Bu652lagmuNpODCqWgGXlqcMWr3"
#include <WiFi.h>
#include <HTTPClient.h>
// Wi-Fi credentials
const char* ssid = "Wokwi-GUEST";
const char* pass = "";
// Your Flask server's IP address (replace localhost with your actual IP)
//const char* serverUrl = "http://192.168.1.15:5000/takeoff";
const char* serverUrl = "https://3860-103-199-163-162.ngrok-free.app/takeoff";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Sending TAKEOFF command...");
HTTPClient http;
http.begin(serverUrl);
http.addHeader("Content-Type", "text/plain");
//int httpResponseCode = http.POST("TAKEOFF");
//int httpResponseCode = http.POST(String("TAKEOFF"));
String payload = "TAKEOFF";
Serial.printf("Sending Payload: '%s'\n", payload.c_str());
int httpResponseCode = http.POST(payload);
Serial.printf("Response Code: %d\n", httpResponseCode);
if (httpResponseCode > 0) {
Serial.printf("Response Code: %d\n", httpResponseCode);
String response = http.getString();
Serial.printf("Response Body: %s\n", response.c_str());
} else {
Serial.printf("Error: %s\n", http.errorToString(httpResponseCode).c_str());
}
http.end(); // Close connection
} else {
Serial.println("WiFi not connected. Retrying...");
}
delay(10000); // Repeat every 10 seconds
}
// BlynkTimer timer;
// // Send the TAKEOFF command
// BLYNK_WRITE(V1) {
// int pinValue = param.asInt();
// if (pinValue == 1) {
// Serial.println("TAKEOFF");
// Serial.println("Takeoff command sent!");
// }
// }
// void setup() {
// Serial.begin(9600); // Virtual Serial to Python
// Serial.println("ESP32 is working!");
// Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// }
// void loop() {
// Blynk.run();
// Serial.println("Running...");
// }
// Send takeoff command to the Python script
// BLYNK_WRITE(V1) {
// int pinValue = param.asInt();
// if (pinValue == 1) {
// Serial2.println("TAKEOFF");
// Serial.println("Takeoff command sent!");
// }
// }
// void setup() {
// Serial.begin(115200); // Debug output to the serial monitor
// Serial2.begin(9600); // Serial communication with the Python script
// Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// }
// void loop() {
// Blynk.run();
// }