3rd-Year Engineering Project · 2025 / 2026

Smart-Metrolac

IoT-based rubber latex quality measurement system — automating DRC calculation, fraud detection, and transparent payments for Sri Lanka's natural rubber industry.

Explore Features View Architecture
4
Sensors
3
System Tiers
9
DB Tables
0%
Data Loss
Problem Statement

Why Smart-Metrolac exists

Sri Lanka's natural rubber industry has relied on a decades-old, manual measurement process — open to error, fraud, and opacity. We built the solution.

01 — Status Quo
Manual & Error-Prone
Farmers bring latex to collection centers where measurements are taken manually with pen and paper. No digital records. No transparency into payment calculation.
02 — Risk
Fraud & Adulteration
Salt adulteration and ammonia addition are common fraud vectors. Current manual checks cannot reliably detect adulterated latex before payment is issued.
03 — Our Approach
ESP32-Based IoT Device
Replace the manual process with a fully automated sensor suite. Measure DRC, temperature, pH, and TDS. Generate digital invoices and sync wirelessly to a cloud backend.
04 — Impact
Transparent Payments
Every farmer gets a digital invoice. Weekly payments are auto-calculated. Role-based dashboards give full visibility to farmers, collection centers, and company admins.
Capabilities

Key Features

Every function of the Smart-Metrolac system — from edge sensing to cloud dashboards.

⚖️
DRC Measurement
Automatic Dry Rubber Content calculation using differential weight (plummet in air vs. latex) and a 5.5 cm³ known volume. EMA filtering for accuracy.
🔬
Quality Control
pH sensor detects spoilage (pH < 6.0) or ammonia addition (pH > 8.0). TDS sensor flags salt adulteration above 500 ppm with relay isolation for accuracy.
📄
Digital Invoicing
Each measurement auto-generates a digital invoice: Litres × DRC% × daily price. Displayed on LCD, stored in PostgreSQL, viewable on the web dashboard.
📡
Store-and-Forward
Wi-Fi lost? No data lost. Invoices are appended to /backlog.txt in LittleFS. A background task checks connection every 10s and streams the backlog on reconnect.
🔐
JWT Security
BCrypt password hashing, JWT stateless authentication, and @PreAuthorize role-based access on every API endpoint. Forced password change on first login.
📊
Role-Based Dashboards
Three tailored React.js dashboards: Company Admin (KPIs, price management), Collection Center Admin (farmer management, alerts), Farmer (payment history).
💰
Auto Payments
Weekly payments auto-calculated from invoice totals. Company admin sets the daily rubber price per kg. All math is server-side, auditable, and tamper-proof.
🕐
NTP Time Stamping
Exact timestamps via NTP (GMT+5:30) ensure even offline invoices sitting in the LittleFS backlog are recorded with the correct generation time in the database.
🏭
Multi-Tenant Architecture
Backend designed for multiple companies, multiple collection centers, multiple devices. PostgreSQL with proper indexing supports large data volumes at scale.
System Design

Three-Tier Architecture

Hardware layer (ESP32) communicates via HTTP and MQTT to a Spring Boot backend, which feeds a React.js frontend through REST APIs.

system-architecture.png — Three-Tier Overview
Three-Tier System Architecture Diagram
data-flow.png — Measurement & Offline Flow
Measurement Flow and Store-and-Forward Diagram
Data & Control Flow

Measurement Flow

A state-machine-driven firmware cycle ensures every reading is consistent, accurate, and non-blocking.

01
Farmer ID Input keypad
Farmer types their 4-digit ID on the 4×4 membrane keypad. Device validates the ID and prompts for latex volume in litres.
02
Air Baseline Weight HX711
The plummet is weighed in open air to establish a differential baseline for density calculation.
03
30-Second Stabilization EMA
Plummet is submerged in latex. Weight, temperature (DS18B20), and pH readings are sampled continuously and smoothed via Exponential Moving Average over 30 seconds.
04
TDS Relay Read relay isolation
A 1-channel relay briefly powers the TDS sensor. This prevents galvanic ground-loop interference with the pH sensor in the same liquid.
05
Density → DRC% Calculation
Displaced Mass ÷ 5.5 cm³ plummet volume = density. Temperature-compensated DRC% derived from standard rubber industry formula.
06
Price Fetch HTTP GET
Device performs HTTP GET to Spring Boot backend for today's rubber price. Falls back to offline Preferences cache if Wi-Fi is unavailable.
07
Invoice & QC Alert
Total = Litres × DRC% × Price. pH and TDS are checked against thresholds. Adulteration alerts are shown on LCD and logged to backend.
08
MQTT Publish or LittleFS Save offline-safe
If online: JSON payload published via MQTT to Spring Boot subscriber. If offline: appended to /backlog.txt and streamed on next reconnection.
Hardware Layer

Sensors & Actuators

ESP32 dual-core 240MHz — simultaneously handling sensor reads, JSON serialization, and MQTT. Every component chosen for reliability in a harsh latex environment.

Load Cell Amplifier
HX711 — GPIO 18/19
Measures differential weight (air vs. latex) to calculate displaced mass and compute latex density. EMA filter applied to eliminate vibration noise.
Temperature Sensor
DS18B20 — 1-Wire GPIO 4
±0.5°C accuracy. Used for DRC temperature compensation and TDS reading compensation. 1-Wire protocol ensures clean signal isolation.
pH Sensor
Analog — ADC GPIO 34
Detects latex spoilage (pH < 6.0) or ammonia addition (pH > 8.0). Reading stabilized over the full 30-second immersion window.
TDS Sensor
Analog — ADC GPIO 35
Detects salt adulteration above 500 ppm. Placed behind a relay to eliminate ground-loop interference with the co-submerged pH sensor.
Relay Module
1-Channel — GPIO 5
Acts as a "drawbridge" isolating the TDS sensor until the exact moment it is read. Solves galvanic interference — a key hardware insight of this project.
LCD Display
I2C 20×4 — 0x27
4-line comprehensive UI. Shows measurement progress bars, sensor readings, invoices, and fraud alerts with audible buzzer feedback.
4×4 Keypad
8 GPIO pins
Farmer ID and volume input. [A] = Confirm, [B] = Delete, [*] = Reset. Designed for simple one-handed operation in field conditions.
Flash Storage
LittleFS + Preferences
LittleFS stores offline invoice backlog (/backlog.txt). Preferences caches the latest rubber price across reboots for fully offline operation.
Technologies

Full Tech Stack

Every tool, protocol, and library powering Smart-Metrolac end-to-end.

🔧 Hardware / Firmware
ESP32 Arduino C++ LittleFS ArduinoJson PubSubClient HTTPClient HX711 DS18B20 NTP
⚙️ Backend
Spring Boot Java 21 PostgreSQL Spring Security + JWT Spring Data JPA Spring Integration MQTT BCrypt Hibernate Mosquitto MQTT
🌐 Frontend
React.js Redux Toolkit Axios Tailwind CSS
Current Status

Milestone Progress

Where we stand as of Milestone 2.

Backend — 9-table DB, JWT, MQTT pipeline 100%
Hardware / Firmware — Sensors, Store-and-Forward 90%
Frontend — React dashboards 80%
Project Budget

Estimated Budget

Summary of project expenditure and planned allocation.

budget.png — Project Budget
Project Budget
The Team

Group 16

Department of Computer Engineering · University of Peradeniya

M1
Manilgama N.C.
E/21/254
M2
K.A.P.M.Perera
E/21/292
M3
Rukshan A.D.
E/21/339
M4
Suriyapperuma H.D.
E/21/453