ESP32 Weather Station Project Information
==========================================

Project Overview:
-----------------
This is a comprehensive weather monitoring system built on ESP32 microcontroller
with multiple environmental sensors and MQTT connectivity for IoT integration.

Hardware Components:
-------------------
- ESP32 Development Board (main controller)
- DHT11 Temperature & Humidity Sensor
- BMP180 Atmospheric Pressure Sensor  
- Rain Sensor Module (analog)
- LDR (Light Dependent Resistor)
- 16x2 I2C LCD Display
- LED (Status Indicator for light detection)
- Breadboard and Jumper Wires

Pin Configuration:
------------------
- DHT11 Sensor: Pin 4
- LDR Sensor: Pin 35 (input only pin)
- Rain Sensor: Pin 34 (analog pin)
- Status LED: Pin 2
- I2C LCD (SDA): Pin 21
- I2C LCD (SCL): Pin 22

Software Features:
-----------------
- Real-time sensor data collection with timed intervals
- Temperature, humidity, pressure, rain, and light monitoring
- Live LCD display of weather data
- WiFi connectivity for network access
- MQTT client for data publishing
- Automatic MQTT reconnection with random client ID
- JSON data format for MQTT messages
- Error handling and status indication
- Serial output for debugging (115200 baud)
- LED status indicator synchronized with LDR readings

Code Structure:
--------------
- Modular sensor reading functions
- Structured WeatherData for data management
- Non-blocking timer-based operations
- Automatic WiFi connection with timeout
- MQTT client with reconnection logic
- LCD display formatting and error messages

MQTT Configuration:
------------------
- Broker: Configurable server address
- Port: 1883 (default)
- Topic: weather/station (configurable)
- Data Format: JSON
- Client ID: Auto-generated (ESP32WeatherStation-XXXX)
- Authentication: None (configurable)

Sensor Reading Schedule:
------------------------
- All sensors read: Every 2 seconds (2000ms)
- MQTT data published: Every 30 seconds (30000ms)
- LCD display updated: Every 2 seconds
- LED status: Updated with each sensor read
- Serial output: With each sensor reading

Technical Specifications:
------------------------
- Microcontroller: ESP32 (Dual Core, 240MHz)
- Memory: 520KB SRAM, 4MB Flash
- Wireless: WiFi 802.11 b/g/n
- Sensors: DHT11 (±2°C, ±5%RH), BMP180 (±1hPa), Rain sensor, LDR
- Display: 16x2 Character LCD with I2C interface (0x27)
- Power: 5V via USB or external supply
- Communication: I2C, WiFi, MQTT

Development Environment:
----------------------
- PlatformIO with ESP32 framework
- Arduino IDE compatible
- Libraries: DHT, LiquidCrystal_I2C, SFE_BMP180, PubSubClient

MQTT Data Format:
-----------------
```json
{
  "temperature": 23.45,
  "humidity": 67.89,
  "pressure": 1013.25,
  "rainLevel": 15,
  "lightDetected": true
}
```

LCD Display Format:
------------------
Line 1: "T:23.4C H:67%"
Line 2: "R:15% P:1013"

Serial Output Format:
-------------------
"Temp: 23.45°C, Humidity: 67.89%, Rain: 15%, Pressure: 1013.25 hPa, Light: YES"

Installation Instructions:
------------------------
1. Connect hardware according to pin configuration
2. Set up MQTT broker (Mosquitto, HiveMQ, AWS IoT, etc.)
3. Update WiFi credentials (ssid, password) in sketch
4. Update MQTT broker settings (mqtt_server, mqtt_port, mqtt_topic)
5. Upload firmware using PlatformIO or Arduino IDE
6. Monitor serial output at 115200 baud rate
7. Subscribe to MQTT topic to receive weather data

MQTT Broker Setup:
-----------------
1. Install Mosquitto broker or use cloud service
2. Configure broker for client connections on port 1883
3. Create topic structure: weather/station (or custom)
4. Test broker connectivity with MQTT client tools
5. Configure firewall if using local broker
6. Verify broker allows anonymous connections or add auth

Troubleshooting:
---------------
- Check wiring connections if sensors return errors
- Verify WiFi credentials if connection fails
- Ensure MQTT broker is accessible and running
- Check MQTT broker address and port
- Verify topic permissions on broker
- Check I2C address (default 0x27) for LCD
- Use external power supply if sensors are unstable
- Check analog pin assignments for rain sensor (Pin 34)
- Monitor serial output for detailed error messages
- Verify BMP180 sensor initialization
- Check DHT11 sensor readings for NaN values

Code Constants and Variables:
----------------------------
- sensorInterval: 2000ms (sensor reading frequency)
- mqttInterval: 30000ms (MQTT publish frequency)
- WiFi connection attempts: 20 (10 seconds total)
- MQTT reconnection delay: 5 seconds
- Rain sensor mapping: 0-4095 to 0-100% (inverted)
- LDR reading: Digital (HIGH/LOW)
- Pressure oversampling: 3 (BMP180)

Project Status:
--------------
Version: 3.0.0 (MQTT Edition)
Last Updated: May 2026
Author: Weather Station Team
License: Open Source

Additional Notes:
---------------
- MQTT provides flexible IoT integration options
- JSON format allows easy data processing and parsing
- Rain sensor values are inverted and mapped to percentage (0-100%)
- LDR provides digital light detection (HIGH=light detected, LOW=no light)
- LED indicates light detection status (ON when light detected)
- LCD shows formatted sensor data locally with error messages
- System requires WiFi connection for MQTT functionality
- Automatic reconnection ensures reliable data transmission
- All sensor data available via MQTT subscription
- Non-blocking code design prevents system hangs
- Modular structure allows easy sensor additions
