SmartScale is an innovative solution for smart retail environments that uses radar-based imaging and AI to evaluate fresh produce. Instead of just appearance, SmartScale assesses the true internal and external condition of fruits and vegetables at the point of sale.
This repository contains the ESP32 firmware and web interface for the SmartScale system, which enables:
- Real-time weight measurement of produce
- AI-based assessment of produce type and freshness
- Dynamic pricing based on freshness scores
- Web interface for displaying results to customers
- ESP32 microcontroller (Adafruit Feather ESP32 V2)
- Radar-based imaging sensor (Infineon PSoC™ 6 AI Evaluation Kit)
- Display (web interface served by ESP32)
- ESP32 Firmware: Arduino-based C++ application
- Web Server: AsyncWebServer serving HTML/CSS/JS interface
- File System: LittleFS for storing web assets
- Wireless Communication: WiFi access point for device access
The firmware is structured into several logical components:
main.cpp
: Entry point and main program logic- LittleFS initialization and management
- WiFi access point setup
- UART communication for sensor data
- Web server and API endpoints
- JSON data formatting and parsing
- Event-based real-time data streaming to clients
- Weight and produce data structure
- Random data generation for testing without hardware
- Configurable simulation parameters
- API endpoints for controlling simulation
- Adafruit Feather ESP32 V2 board
- USB cable for programming
- Optional: External sensors (radar)
- PlatformIO (recommended) or Arduino IDE
- Required libraries:
- AsyncTCP
- ESPAsyncWebServer
- LittleFS
Key parameters can be adjusted in main.cpp
:
#define WIFI_SSID "SmartScale" // Access point name
#define WIFI_PWD "123456789" // Access point password
// UART configuration for external sensors
#define UART_RX 16
#define UART_TX 17
#define UART_BAUD 115200
- Open the project in PlatformIO
- Build the project:
pio run
- Upload the firmware:
pio run --target upload
- Upload the filesystem:
pio run --target uploadfs
- Install the required libraries through the Library Manager
- Open
main.cpp
as your main sketch - Select the correct board and port
- Upload the sketch
- Use ESP32 LittleFS Filesystem Uploader plugin to upload the
data
directory
The web interface provides a user-friendly display for the SmartScale system:
- Real-time weight display
- Produce type identification
- Freshness score visualization
- Dynamic pricing calculation
- Sustainability impact information
index.html
: Main UI structure and layoutstyle.css
: Styling and visual designmain.js
: Client-side logic and data handling
The web interface receives data from the ESP32 through Server-Sent Events (SSE):
weightUpdate
events for continuous weight readingsscaleData
events for complete produce information after scanning
The firmware exposes several HTTP endpoints:
Endpoint | Method | Description |
---|---|---|
/ |
GET | Serves the main web interface |
/api/scale-data |
GET | Returns current scale data as JSON |
/api/trigger-scan |
GET | Trigger a manual produce scan (test mode) |
/api/toggle-simulation |
GET | Toggle simulation mode on/off |
The firmware expects data from the ripeness sensor in the following format:
PRODUCE:Apple,FRESHNESS:87
Data sent to web clients follows this structure:
{
"weight": 0.235,
"produceType": "Apple",
"freshnessScore": 87
}
The firmware includes a simulation mode for testing without physical hardware:
Test mode is enabled by default and can be toggled via the /api/toggle-simulation
endpoint.
- Random weight fluctuations
- Simulated produce detection
- Automatic scanning at configurable intervals
- Variable freshness scores
If you see "An Error has occurred while mounting LittleFS", the filesystem may be corrupted. The firmware will automatically format LittleFS and retry.
- Verify the ESP32 is powered correctly
- Check that you're connecting to the "SmartScale" WiFi network
- Confirm password is "123456789"
- Ensure the web interface is loaded from the ESP32 (not a local file)
- Check browser console for any JavaScript errors
- Verify the EventSource connection is established
Modify the JavaScript produceTypes
array in main.js
to add new produce types with their pricing information.
For custom freshness assessment algorithms, modify the logic in parseUARTData()
function in the ESP32 firmware.
The firmware can be extended to support additional sensors by:
- Adding appropriate libraries and initialization code
- Extending the data structure to include new sensor readings
- Updating the web interface to display new data