// Module 1: WiFi Setup
#include "WiFi.h"
#include <HTTPClient.h>
#include <Servo.h>
Servo servo;
int const trigPin = 6;
int const echoPin = 5;
void setupWiFi() {
const char* ssid = "Wokwi-GUEST";
const char* password = "";
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void downloadImage() {
Serial.println("Downloading image");
HTTPClient http;
if (http.begin(imageUrl)) { // HTTP connection
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
// Get length of the document (filesize)
int contentLength = http.getSize();
// Read data byte by byte
WiFiClient * stream = http.getStreamPtr();
uint8_t buf[128];
int bytesRead = 0;
while (http.connected() && (bytesRead = stream->readBytes(buf, sizeof(buf))) > 0) {
// Write received bytes to serial
for (int i = 0; i < bytesRead; i++) {
Serial.write(buf[i]);
}
}
Serial.println("\nImage downloaded successfully");
}
} else {
Serial.printf("HTTP request failed with error code: %d\n", httpCode);
}
http.end();
} else {
Serial.println("Unable to connect to server");
}
}
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(3);
Serial.begin(115200);
delay(1000);
// setupWiFi(); // Call function to set up WiFi
// downloadImage();
}
void loop() {
// collectSensorData(); // Call function to collect sensor data
// sendDataToServer(sensorData); // Call function to send data to server
delay(5000); // Delay for 5 seconds
}