#include <WiFi.h>
#include <HTTPClient.h>
// Replace these with your network credentials
const char* ssid = "RH Niam";
const char* password = "niam 552201";
// Server URL to send data
const char* serverName = "192.168.0.1";
// Phototransistor connected to analog pin GPIO 34
const int sensorPin = 34;
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected to Wi-Fi");
}
void loop() {
// Read the analog value from the sensor
int sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (3.3 / 4095.0); // Convert to voltage
float irradiance = voltage * 1000.0; // Example conversion factor
// Print the values to the Serial Monitor
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.print("V | Irradiance: ");
Serial.print(irradiance);
Serial.println(" W/m^2");
// Check Wi-Fi connection status
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Prepare data to send
String url = String(serverName) + "?sensorValue=" + String(sensorValue) + "&voltage=" + String(voltage) + "&irradiance=" + String(irradiance);
// Send data to the server
http.begin(url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("HTTP Response code: " + String(httpResponseCode));
Serial.println("Response: " + response);
} else {
Serial.println("Error in HTTP request");
}
http.end();
} else {
Serial.println("Wi-Fi Disconnected");
}
// Delay before the next reading
delay(60000); // Take a reading every minute
}