#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TinyGPS++.h>
#include <HardwareSerial.h>
#include <RTClib.h>
#include <HTTPClient.h>
const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";
const char* pushbulletAPIKey = "YourPushbulletAPIKey";
const int server_port = 80;
// LCD Display Configuration
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address if your I2C module has a different address
// GPS Configuration
HardwareSerial gpsSerial(1); // Use Serial1 for ESP32
TinyGPSPlus gps;
// RTC Configuration
RTC_DS3231 rtc;
// Smoke Sensor Configuration
const int smokeSensorPin = A2; // Connect the smoke sensor to an analog pin
int smokeThreshold = 300; // Adjust the threshold based on your sensor's characteristics
// Circuit Breaker Configuration
const int breakerPin = 5; // Connect the breaker control pin
// ... (previous code remains unchanged)
void setup() {
Serial.begin(115200);
lcd.begin(16, 2); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(voltageSensorPin, INPUT);
pinMode(currentSensorPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(breakerPin, OUTPUT); // Set the breaker pin as an output
sensorForTransformerTemp.begin();
sensorForOilTemp.begin();
connectToWiFi();
// GPS setup
gpsSerial.begin(9600, SERIAL_8N1, GPS_RX, GPS_TX); // Change GPS_RX and GPS_TX according to your ESP32 pin mappings
// RTC setup
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting the time...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
float voltage = readVoltage();
float current = readCurrent();
float transformerTemp = readTemperature(transformerTempPin);
float oilTemp = readTemperature(oilTempPin);
int oilLevel = readOpticalSensor(opticalSensorPin);
int smokeLevel = readSmokeSensor(smokeSensorPin);
// GPS reading
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
// Retrieve and display GPS information on the LCD
displayGPSInfo();
}
}
lcd.setCursor(0, 1);
lcd.print(" "); // Clear previous content
if (current == 0) {
// Power is off, send acknowledgment to service man
sendAcknowledgment(server_ip, server_port, "ServiceMan");
lcd.setCursor(0, 1);
lcd.print("Power OFF");
} else {
// Power is on, send acknowledgment to customer and push notification
sendAcknowledgment(server_ip, server_port, "Customer");
sendPushNotification("Power On", "Your power is back!");
lcd.setCursor(0, 1);
lcd.print("Power ON");
// Circuit breaker simulation based on smoke sensor reading
if (smokeLevel > smokeThreshold) {
// Smoke detected, simulate tripping the circuit breaker
digitalWrite(breakerPin, LOW);
lcd.setCursor(0, 1);
lcd.print("Circuit Breaker Tripped");
} else {
// No smoke detected, normal operation
digitalWrite(breakerPin, HIGH);
}
}
// Additional logic based on temperature, optical sensor, and smoke sensor readings can be added here
delay(5000); // Adjust delay based on your requirements
}
void displayGPSInfo() {
lcd.setCursor(0, 0);
lcd.print("Lat: " + String(gps.location.lat(), 6));
lcd.setCursor(0, 1);
lcd.print("Lon: " + String(gps.location.lng(), 6));
}
float readVoltage() {
// Implement voltage sensor reading logic
}
float readCurrent() {
// Implement current sensor reading logic
}
float readTemperature(int tempSensorPin) {
sensorForTransformerTemp.requestTemperatures(); // Replace with the appropriate sensor
return sensorForTransformerTemp.getTempCByIndex(0);
}
int readOpticalSensor(int opticalSensorPin) {
// Implement optical sensor reading logic (e.g., TCRT5000)
}
int readSmokeSensor(int smokeSensorPin) {
return analogRead(smokeSensorPin);
}
void sendAcknowledgment(const char* server, int port, const char* recipient) {
// Implement HTTP POST request to send acknowledgment
}
void sendPushNotification(const char* title, const char* message) {
HTTPClient http;
String url = "https://api.pushbullet.com/v2/pushes";
http.begin(url);
http.addHeader("Content-Type", "application/json");
http.addHeader("Access-Token", pushbulletAPIKey);
String payload = "{\"type\":\"note\",\"title\":\"" + String(title) + "\",\"body\":\"" + String(message) + "\"}";
int httpCode = http.POST(payload);
String response = http.getString();
Serial.println("Pushbullet Response Code: " + String(httpCode));
Serial.println("Pushbullet Response: " + response);
http.end();
}
void connectToWiFi() {
// Implement WiFi connection logic
}