#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "your_network_ssid";
const char* password = "your_network_password";
const String serverUrl = "http://your_flask_server_ip/";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
// Wait for the connection to be established
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverUrl);
// Prepare data
String sensorData = "temperature=23&humidity=50"; // Example sensor data
// Send POST request
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpResponseCode = http.POST(sensorData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Data sent: " + response);
} else {
Serial.println("Error sending data");
}
http.end();
}
delay(10000); // Send data every 10 seconds
}