DEV Community

Cover image for How We Cut IoT Backend Calls by 85% with C++ and BLE Pairing on ESP32
Jay Lee
Jay Lee

Posted on

How We Cut IoT Backend Calls by 85% with C++ and BLE Pairing on ESP32

❄️ How We Cut IoT Backend Calls by 85% with C++ and BLE Pairing on ESP32

Project Snowman is an embedded IoT system built on an ESP32. Our goal?

Collect real-time environmental data, send it to the cloud, and display it on a live frontend —

all while minimizing backend strain and keeping config secure.


🔧 Hardware & Stack

  • ESP32
  • DS18B20 temperature sensors
  • C++ with PlatformIO
  • BLE + Wi-Fi
  • REST API (Render backend)
  • React + Vite frontend (Netlify)

🧱 Modular C++ Architecture (S.O.L.I.D. Principles)

We designed the firmware using modern object-oriented programming:

  • SensorManager handles DS18B20 readings
  • WiFiManager connects to Wi-Fi and checks status
  • BLEServerModule handles proximity-based setup
  • APIClient pushes data only when requested
if (bleTriggeredReconnect && millis() - bleReconnectTime > 10000) {
  WiFi.begin(bleSSID.c_str(), blePassword.c_str());
  bleServer->stopAdvertising();
}
Enter fullscreen mode Exit fullscreen mode

Each class has a single responsibility — easy to debug, maintain, and scale.


🔐 BLE Pairing Mode with Proximity Logic

BLE is used for configuration. No insecure web portals.

  • BLE GATT server activates only during setup mode
  • Accepts Wi-Fi credentials from a phone
  • Reconnects automatically and turns off BLE afterward

⚙️ Request-Only Backend API Flow

Instead of pushing sensor data continuously, the ESP32 sends updates only when requested by the frontend.

  • Dropped backend calls from 100+ per hour~15
  • Reduced bandwidth, power, and compute costs

Chart showing call reduction


💻 Frontend Integration (React + Vite)

The frontend fetches sensor data and renders it in real-time using stat cards.

useEffect(() => {
  fetch("/api/data/latest")
    .then(res => res.json())
    .then(setData);
}, []);
Enter fullscreen mode Exit fullscreen mode

Fast. Clean. Minimal load.


🧠 What We Learned

  • Event-driven IoT logic beats constant loop polling
  • BLE provisioning improves security + UX
  • PlatformIO and C++ OOP scale beautifully for embedded builds

🔜 What’s Next

  • Audit logging for BLE pairing events
  • Push BLE config via mobile app
  • Real-world vehicle deployments
  • Publishing full Medium article + case study

Let me know what you're building — and if you're working on embedded systems or sustainable tech, let's connect!


Tags: #esp32 #c++ #iot #ble #embedded #platformio

Top comments (0)