Skip to content

mferuscomelo/smartscale_esp32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmartScale

Overview

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

System Architecture

Hardware Components

  • ESP32 microcontroller (Adafruit Feather ESP32 V2)
  • Radar-based imaging sensor (Infineon PSoC™ 6 AI Evaluation Kit)
  • Display (web interface served by ESP32)

Software Components

  1. ESP32 Firmware: Arduino-based C++ application
  2. Web Server: AsyncWebServer serving HTML/CSS/JS interface
  3. File System: LittleFS for storing web assets
  4. Wireless Communication: WiFi access point for device access

Firmware Structure

The firmware is structured into several logical components:

Core Functionality

  • 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

Data Handling

  • JSON data formatting and parsing
  • Event-based real-time data streaming to clients
  • Weight and produce data structure

Test/Simulation Mode

  • Random data generation for testing without hardware
  • Configurable simulation parameters
  • API endpoints for controlling simulation

Setup and Configuration

Hardware Requirements

  • Adafruit Feather ESP32 V2 board
  • USB cable for programming
  • Optional: External sensors (radar)

Software Requirements

  • PlatformIO (recommended) or Arduino IDE
  • Required libraries:
    • AsyncTCP
    • ESPAsyncWebServer
    • LittleFS

Configuration Options

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

Building and Flashing

Using PlatformIO

  1. Open the project in PlatformIO
  2. Build the project: pio run
  3. Upload the firmware: pio run --target upload
  4. Upload the filesystem: pio run --target uploadfs

Using Arduino IDE

  1. Install the required libraries through the Library Manager
  2. Open main.cpp as your main sketch
  3. Select the correct board and port
  4. Upload the sketch
  5. Use ESP32 LittleFS Filesystem Uploader plugin to upload the data directory

Web Interface

The web interface provides a user-friendly display for the SmartScale system:

Key Features

  • Real-time weight display
  • Produce type identification
  • Freshness score visualization
  • Dynamic pricing calculation
  • Sustainability impact information

File Structure

  • index.html: Main UI structure and layout
  • style.css: Styling and visual design
  • main.js: Client-side logic and data handling

Data Communication

The web interface receives data from the ESP32 through Server-Sent Events (SSE):

  • weightUpdate events for continuous weight readings
  • scaleData events for complete produce information after scanning

API Endpoints

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

Data Format

UART Protocol

The firmware expects data from the ripeness sensor in the following format:

PRODUCE:Apple,FRESHNESS:87

JSON Data Structure

Data sent to web clients follows this structure:

{
  "weight": 0.235,
  "produceType": "Apple",
  "freshnessScore": 87
}

Testing

The firmware includes a simulation mode for testing without physical hardware:

Enabling Test Mode

Test mode is enabled by default and can be toggled via the /api/toggle-simulation endpoint.

Test Features

  • Random weight fluctuations
  • Simulated produce detection
  • Automatic scanning at configurable intervals
  • Variable freshness scores

Troubleshooting

Common Issues

LittleFS Mount Failure

If you see "An Error has occurred while mounting LittleFS", the filesystem may be corrupted. The firmware will automatically format LittleFS and retry.

Cannot Connect to WiFi

  • Verify the ESP32 is powered correctly
  • Check that you're connecting to the "SmartScale" WiFi network
  • Confirm password is "123456789"

No Data Showing in Web Interface

  • 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

Further Development

Adding New Produce Types

Modify the JavaScript produceTypes array in main.js to add new produce types with their pricing information.

Custom Algorithms

For custom freshness assessment algorithms, modify the logic in parseUARTData() function in the ESP32 firmware.

Hardware Expansion

The firmware can be extended to support additional sensors by:

  1. Adding appropriate libraries and initialization code
  2. Extending the data structure to include new sensor readings
  3. Updating the web interface to display new data

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published