LEMION WEATHER STATION // TECHNICAL HANDOVER SPECIFICATION

Complete Architecture Documentation for Lemion Engineering Team | System Version 4.8.5

1. EXECUTIVE SUMMARY & SYSTEM ARCHITECTURE

The Lemion Weather Station is an end-to-end IoT monitoring solution designed to collect ambient environmental parameters (Temperature, Humidity, Barometric Pressure) using an ESP32 hardware microcontroller and BMP280 sensor module, transmit measurements securely over HTTPS REST APIs to a MySQL database, and present real-time/historical telemetry via a futuristic Sci-Fi Web Dashboard featuring interactive 3D Obsidian node graphs and browser-based Web Serial firmware flashing.

Layer Technology Stack Description
HARDWARE ESP32 WROOM-32, BMP280, I2C LCD 1602, Rotary Selector Switch Collects temperature & pressure; outputs locally to I2C LCD; sends JSON payload to HTTPS server every 60s.
BACKEND API PHP 8.3 (PDO, Asia/Bangkok GMT+7), MySQL InnoDB Handles secure data ingestion, querying latest status, and date-filtered historical telemetry retrieval.
FRONTEND HUD HTML5, Vanilla CSS, High-Contrast ApexCharts, Three.js, ESP Web Tools Futuristic Sci-Fi HUD, ApexCharts line graph, Date Picker query, Three.js 3D Obsidian Node Network, Web Serial Flasher.

2. SERVER & DEPLOYMENT SPECIFICATIONS

Hosting Environment: Hostinger Cloud Web Hosting
Live Domain URL: https://lemion.108ido.com
Server Absolute Root Path: /home/u639131817/domains/108ido.com/public_html/lemion

A. Directory & File Structure

/home/u639131817/domains/108ido.com/public_html/lemion/
├── index.html                  # Main Web HUD Dashboard (HTML5)
├── style.css                   # Sci-Fi HUD Design Tokens & 3D Styling (CSS3)
├── app.js                      # Application Engine, High-Contrast ApexCharts & Three.js (JS ES6)
├── manifest.json               # ESP Web Tools Web Flasher Manifest
├── firmware.bin                # Compiled ESP32 Firmware Binary (For Web Flashing)
├── project_handover.html       # Full Technical Handover Documentation
└── api/
    ├── config.php              # Global Database & API Auth Credentials (Asia/Bangkok GMT+7)
    ├── db.php                  # PDO MySQL Connection Singleton (SET time_zone = '+07:00')
    ├── upload.php              # Ingestion Endpoint for ESP32 POST Data (GMT+7 Timestamps)
    ├── latest.php              # Endpoint returning most recent telemetry reading
    ├── history.php             # Endpoint for range queries & specific date filtering
    ├── seed.php                # Database Seeder (Generates realistic history)
    └── setup.php               # Database Schema Initializer (Creates table)
            

B. How to Deploy Updates

  1. Option 1 (Hostinger CLI / API): Use the Hostinger API static deployment tool by compressing files into a ZIP archive and calling hosting_deployStaticWebsite.
  2. Option 2 (FTP / SFTP Upload): Connect via FTP to 108ido.com port 21 using Hostinger cPanel FTP credentials and upload all files into public_html/lemion/.
  3. Browser Cache Invalidation: Whenever updating index.html, increment the version query parameter (e.g. app.js?v=20260725_v8) to ensure clients bypass local caching.

3. DATABASE CREDENTIALS & SCHEMA SPECIFICATION

Parameter Configuration Value
Database Hostlocalhost
Database Nameu639131817_108ido
Database Usernameu639131817_108ido
Database PasswordSukpitak@153
API Secret Keylemion-secret-api-key-2026
Timezone ConfigurationAsia/Bangkok (GMT+7)

Table Schema: lemion_weather

CREATE TABLE IF NOT EXISTS `lemion_weather` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `temperature` FLOAT NOT NULL,
  `humidity` FLOAT NOT NULL,
  `pressure` FLOAT NOT NULL,
  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
            

4. REST API ENDPOINTS SPECIFICATION

1. Data Ingestion Endpoint: POST /api/upload.php

Called by ESP32 microcontroller every 60 seconds to upload sensor readings.

Request Headers: Content-Type: application/json

// Request Body JSON Payload
{
  "api_key": "lemion-secret-api-key-2026",
  "temperature": 28.5,
  "humidity": 65.0,
  "pressure": 1009.4
}
            

2. Latest Reading Endpoint: GET /api/latest.php

// Response JSON (Times returned in Asia/Bangkok GMT+7)
{
  "status": "success",
  "data": {
    "id": 2639,
    "temperature": 27.2,
    "humidity": 69.0,
    "pressure": 1013.4,
    "created_at": "2026-07-25 18:42:07"
  }
}
            

3. History & Date Query Endpoint: GET /api/history.php

5. ESP32 FIRMWARE & COMPILATION GUIDE

The microcontroller source file is located at c:\esp32\esp32_weather.ino (or c:\esp32\esp32_weather\esp32_weather.ino).

Hardware Wiring (Shared I2C Bus on GPIO 21 / 22)

Device VCC GND SDA / Signal SCL
ESP32 Board3.3V / 5VGNDGPIO 21GPIO 22
BMP280 Sensor3.3VGNDGPIO 21GPIO 22
I2C LCD 16025VGNDGPIO 21GPIO 22
Rotary Selector Switch Pin A3.3V (Pullup)GNDGPIO 13 (INPUT_PULLUP)-
Rotary Selector Switch Pin B3.3V (Pullup)GNDGPIO 14 (INPUT_PULLUP)-

How to Compile .ino into firmware.bin

# Using arduino-cli (Command Line):
arduino-cli compile --fqbn esp32:esp32:esp32 "c:\esp32\esp32_weather" --output-dir "c:\esp32\build"

# Using Arduino IDE 2.x:
1. Open esp32_weather.ino in Arduino IDE.
2. Select Board: Tools -> Board -> ESP32 Arduino -> ESP32 Dev Module.
3. Click Sketch -> Export Compiled Binary (Ctrl + Alt + S).
            

6. BROWSER-BASED WEB FIRMWARE FLASHER (WEB SERIAL API)

The dashboard incorporates ESP Web Tools to allow technicians to flash updated ESP32 firmware directly over a USB cable inside Google Chrome or Microsoft Edge without taking the board out of its enclosure or installing local compilers.

  1. Connect the ESP32 board to the computer USB port using a data-capable USB cable.
  2. Open https://lemion.108ido.com in Chrome or Edge.
  3. Click the top bar button: WEB FIRMWARE FLASHER.
  4. Click CONNECT & FLASH FIRMWARE in the popup modal.
  5. Select the COM Port corresponding to your ESP32 (e.g. CP2102 on COM5) and click Connect -> Install.

7. HOSTING LIMITATIONS & HIGH-FREQUENCY INGESTION ANALYSIS (5-SECOND INTERVAL)

Can the ESP32 microcontroller send data to the backend database every 5 seconds? Technically, the ESP32 code can be set to sendInterval = 5000;. However, doing HTTPS POST requests directly to MySQL every 5 seconds on shared web hosting (Hostinger) introduces severe operational limitations and architectural bottlenecks.

A. Data Volume & Database Growth Comparison

Interval Rate Readings / Min Readings / Day Readings / Month Estimated Annual Storage
60 Seconds (Recommended) 1 row 1,440 rows 43,200 rows ~20 MB / year
30 Seconds 2 rows 2,880 rows 86,400 rows ~40 MB / year
5 Seconds (High Frequency) 12 rows 17,280 rows 518,400 rows ~300 MB - 500 MB / year

B. Key Bottlenecks & Hostinger Shared Hosting Limits

  • WAF & IP Rate-Limiting (ModSecurity / Cloudflare): Sending 17,280 HTTPS POST requests per day from a single static IP address triggers ModSecurity anti-DDoS rate limiters on shared hosting, returning HTTP 403 Forbidden or 429 Too Many Requests.
  • PHP-FPM Worker & Entry Process Limits: Shared hosting limits Entry Processes (EP) to 20-30 concurrent processes. High-frequency SSL handshakes consume CPU process slots rapidly.
  • MySQL I/O & Connection Overhead: Opening PDO connections every 5 seconds produces continuous disk I/O writes.

8. PHYSICAL ROTARY SELECTOR SWITCH IMPLEMENTATION GUIDE (DISPLAY TOGGLING)

To enable the front panel Rotary Selector Switch on the enclosure box to switch LCD 1602 display screens (e.g. turning Left displays Temp/Humidity, turning Right displays Pressure/Wi-Fi Status), follow this implementation specification:

A. Hardware Connection Diagram

B. Recommended C++ Firmware Architecture

// Define Pin Assignment for Rotary Switch
#define SWITCH_PIN_LEFT  13
#define SWITCH_PIN_RIGHT 14

void setup() {
    pinMode(SWITCH_PIN_LEFT, INPUT_PULLUP);
    pinMode(SWITCH_PIN_RIGHT, INPUT_PULLUP);
}

void updateLCDDisplay() {
    bool isLeftPressed  = (digitalRead(SWITCH_PIN_LEFT) == LOW);
    bool isRightPressed = (digitalRead(SWITCH_PIN_RIGHT) == LOW);

    lcd.clear();
    if (isLeftPressed) {
        // Mode 1: Display Temperature & Humidity
        lcd.setCursor(0, 0);
        lcd.print("TEMP: "); lcd.print(tempC, 1); lcd.print(" C");
        lcd.setCursor(0, 1);
        lcd.print("HUM : "); lcd.print(humidity, 1); lcd.print(" %");
    } else if (isRightPressed) {
        // Mode 2: Display Barometric Pressure & System Status
        lcd.setCursor(0, 0);
        lcd.print("PRES: "); lcd.print(pressure, 1); lcd.print("hPa");
        lcd.setCursor(0, 1);
        lcd.print("SYS : ONLINE/WiFi");
    } else {
        // Default Mode: Auto-cycle or Summary
        lcd.setCursor(0, 0);
        lcd.print("LEMION SYS READY");
        lcd.setCursor(0, 1);
        lcd.print("SELECT MODE...  ");
    }
}
            

9. OVER-THE-AIR (OTA) WI-FI FIRMWARE FLASHING SPECIFICATION

To eliminate the need to plug in a USB cable when updating ESP32 firmware in the future, integrate ArduinoOTA or AsyncElegantOTA into the C++ codebase:

C++ Code Integration Example (`ArduinoOTA`)

#include <WiFi.h>
#include <ArduinoOTA.h>

void setupOTA() {
    ArduinoOTA.setHostname("lemion-weather-station");
    ArduinoOTA.setPassword("lemion-ota-pass-2026");

    ArduinoOTA.onStart([]() { Serial.println("Start OTA Updating..."); });
    ArduinoOTA.onEnd([]()   { Serial.println("\nEnd OTA Update."); });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    });

    ArduinoOTA.begin();
}

void loop() {
    ArduinoOTA.handle(); // Must be called frequently in loop()
    // ... rest of sensor reading and sending code ...
}
            
How to Flash over Wi-Fi: Once the OTA-enabled binary is written to the board, open Arduino IDE -> Go to Tools -> Port -> Select lemion-weather-station at 192.168.x.x (Network Port) -> Click Upload. The firmware updates wirelessly over Wi-Fi in seconds!

10. RECENT IMPROVEMENTS & HANDOVER CHECKLIST