#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "http://3579-196-115-68-63.ngrok-free.app/api/receive_code/";
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
Serial.print("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("OK! IP=");
Serial.println(WiFi.localIP());
// Check if we can access the internet (ping to Google DNS)
WiFiClient client;
if (client.connect("8.8.8.8", 80)) {
Serial.println("Ping to Google DNS successful!");
} else {
Serial.println("Ping failed!");
}
// Send code (e.g., 1234) to the Django server
HTTPClient http;
WiFiClientSecure secureClient; // Use secure client for HTTPS
// Disable SSL certificate verification for testing
secureClient.setInsecure(); // This disables certificate validation
// Start the HTTP request
http.begin(secureClient, url);
http.addHeader("Content-Type", "application/json"); // Specify content-type as JSON
// Create JSON payload
String jsonPayload = "{\"code\": 1234}";
// Send POST request with the payload
Serial.print("Sending POST request to: ");
Serial.println(url);
int httpResponseCode = http.POST(jsonPayload); // Send POST with JSON payload
// Check the response from the server
if (httpResponseCode > 0) {
Serial.print("HTTP Response Code: ");
Serial.println(httpResponseCode);
String payload = http.getString(); // Get the server's response
Serial.println("Server Response: ");
Serial.println(payload);
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
// Close the HTTP connection
http.end();
}
void loop() {
// Do nothing in the loop
delay(100);
}