Community Microgrid Station Package
==================================

Files
-----
1. esp32_microgrid_station.ino
   ESP32 code for:
   - 2 producer-side ZMPT voltage sensors
   - 2 consumer-side ACS712 current sensors
   - battery voltage monitoring
   - LCD display
   - Wi-Fi POST to PHP backend

2. schema.sql
   Import this SQL file into MySQL.

3. db.php
   Database connection file.

4. insert_data.php
   Receives POST data from ESP32 and stores it.

5. latest.php
   Returns the newest row as JSON.

6. history.php
   Returns recent rows for charts and history table.

7. summary.php
   Optional summary endpoint.

8. index.php
   Main dashboard with:
   - collapsing sidebar
   - active page highlight
   - cards with icons
   - history table
   - modern charts with trailing area fills
   - automatic refresh

Deployment
----------
1. Import schema.sql into your MySQL database.
2. Upload db.php, insert_data.php, latest.php, history.php, summary.php, and index.php to your cPanel folder.
3. Update credentials in db.php if needed.
4. Update the server URL in esp32_microgrid_station.ino if your path is different.
5. Install the following Arduino libraries:
   - WiFi
   - HTTPClient
   - Wire
   - LiquidCrystal_I2C
   - ZMPT101B
6. Upload the ESP32 sketch.

Notes
-----
- Producer-side exported power is intentionally simulated from live ZMPT voltage.
- Consumer-side current and billing use the ACS712 readings.
- Battery level is approximate and should be tuned to your actual divider and battery range.
- Tune PROD1_SENSITIVITY, PROD2_SENSITIVITY, and battery divider scaling for your hardware.
