A full-stack IoT application that automates retail shelf inventory tracking — from hardware sensor to live web dashboard.
An ESP32 microcontroller acts as an edge device, constantly measuring physical product stock via an ultrasonic sensor and transmitting telemetry data over Wi-Fi to a C# ASP.NET Core REST API. The backend persists readings in a SQL Server database and serves them to a live web dashboard that auto-updates in real time.
![]() Hardware on the shelf |
![]() Live web dashboard |
![]() Real-time stock monitor |
![]() ESP32 wiring diagram |
┌──────────────┐ HTTP POST (JSON) ┌──────────────────┐ ┌──────────────┐
│ ESP32 + │ ───────────────────► │ ASP.NET Core │ ◄────► │ SQL Server │
│ HC-SR04 │ Wi-Fi │ REST API (C#) │ │ Database │
│ SSD1306 │ └────────┬─────────┘ └──────────────┘
│ Buzzer │ │ GET /api/inventory
└──────────────┘ ┌────────▼─────────────┐
│ Live Dashboard │
│ (HTML/CSS/JS/Chart) │
└──────────────────────┘
| Component | Details |
|---|---|
| Framework | ASP.NET Core with C# |
| ORM | Entity Framework Core — code-first migrations, SQL Server |
| Endpoints | POST /api/inventory — receive telemetry from ESP32 |
GET /api/inventory/latest — most recent stock reading |
|
GET /api/inventory/history — time-series of last 20 readings |
| Component | Details |
|---|---|
| MCU | ESP32 — Wi-Fi-enabled microcontroller |
| Sensor | HC-SR04 ultrasonic — measures product distance on shelf |
| Display | SSD1306 OLED — shows stock % and boot status locally |
| Alert | Active buzzer — audible alarm when stock < 10% |
| Component | Details |
|---|---|
| Stack | HTML / CSS / JavaScript / Chart.js |
| Behavior | Auto-polling API to render a real-time stock-level line chart — no manual refresh needed |
| Practice | Implementation |
|---|---|
| Secure Credentials | Wi-Fi secrets isolated in a git-ignored secrets.h file — zero sensitive data in version control |
| Robust Data Mapping | Firmware maps raw distance (cm) → stock percentage (%) with constrained bounds, preventing false negatives |
| Async / DI Backend | API uses async/await and Dependency Injection following modern enterprise C# patterns |
| Full-Stack Integration | Bridges low-level C++ memory management on the MCU with high-level C# / SQL Server cloud systems |
git clone https://github.com/MatheusFerraro/SmartRetail-System.gitcd Backend/SmartRetailApi
dotnet ef database update # apply migrations
dotnet run # starts API on https://localhost:5001Connect the components to the Wemos D1 Mini ESP32 as shown below:
| Component | Pin | ESP32 GPIO |
|---|---|---|
| HC-SR04 Trigger | TRIG | GPIO 14 |
| HC-SR04 Echo | ECHO | GPIO 12 |
| HC-SR04 VCC / GND | — | 5V / GND |
| SSD1306 OLED SDA | SDA | GPIO 21 |
| SSD1306 OLED SCL | SCL | GPIO 22 |
| SSD1306 OLED VCC / GND | — | 3.3V / GND |
| Active Buzzer Signal | + | GPIO 27 |
| Active Buzzer GND | − | GND |
- Open
Firmware/SmartRetail.inoin the Arduino IDE - Copy
secrets_template.h→secrets.hand fill in your Wi-Fi credentials & server IP - Select your ESP32 board and upload
Developed by Matheus Ferraro — Software Development Student at NBCC



