AI on the Edge Device Documentation

repository·main·Indexed 27 days ago

https://github.com/jomjol/ai-on-the-edge-device

A project using an ESP32-CAM and TensorFlow Lite to convert analog water, gas, and electricity meter readings into digital data via edge-based AI. Features include image processing for ROI extraction, a web interface for administration, OTA updates, and data integration with MQTT, InfluxDB, and Home Assistant.

Tokens
17.1K
Snippets
38
Records
133
Agent score
94%

What's inside AI on the Edge Device

  1. Overview of AI on the Edge Device

    main
    AI on the Edge Device is a project that uses an ESP32-CAM to digitize analog meters (water, gas, or electricity). It utilizes edge computing to process images locally, extracting meter values using TensorFlow Lite (TFLite) without requiring cloud computing. The device captures photos at set intervals, identifies Regions of Interest (ROIs), and runs AI models to produce a digitized value.
  2. Key Features of AI on the Edge Device

    main

    The device provides several capabilities for meter digitization and data integration:

    • AI/ML: TensorFlow Lite (TFLite) integration with an easy-to-use wrapper.
    • Image Processing: Inline processing including feature detection, alignment, and ROI extraction.
    • Hardware: Small, affordable ESP32-based device with integrated camera and illumination.
    • Connectivity & Control: Web interface for administration, OTA (Over-the-Air) updates via Wi-Fi, and MQTT protocol support.
    • Data Integration: Full integration with Home Assistant, support for InfluxDB (versions 1 and 2), and a REST API for data access.
  3. Key Features of Miniz

    main

    Miniz provides several specialized capabilities for embedded and high-performance applications:

    • Zlib Compatibility: Implements zlib and Deflate standards with a portable, single-source/header implementation.
    • Stream-based Processing: Supports coroutine-style stream processing (not block-based). The zlib-style API functions can be called one byte at a time.
    • Low-level Codecs: The tdefl (compressor) and tinfl (decompressor) low-level APIs use simple state structs that can be saved/restored via memcpy. These APIs do not use the heap.
    • Archive & Image Support: Includes APIs for reading/writing/appending .ZIP archives and writing .PNG format image files.
    • Real-time Compression: Features a specialized real-time compressor designed to compete with fastlz and minilzo.
  4. Flash the ESP32 Firmware

    main

    Initial firmware installation must be done via a USB connection. Subsequent updates can be performed via OTA (Over-the-Air) using the web interface.

    Available flashing methods:

    1. Web Installer and Console (Preferred): A browser-based tool that flashes the ESP32 and allows log extraction over USB.
    2. Espressif Flash Tool
    3. ESPtool (command-line tool)

    Refer to the Installation documentation for detailed steps.

  5. Manually edit MaxRateValue in the configuration file

    main

    When editing the configuration file manually, you cannot use MaxRateValue as a standalone key. Because this parameter is specific to each number sequence defined in the ROIs (Regions of Interest), you must prefix the parameter with the name of the <NUMBER> sequence followed by a dot.

    Example: If your number sequence is named main, the configuration key must be main.MaxRateValue.

    main.MaxRateValue
  6. Set up a prepared demo on the SD Card

    main

    To use a prepared demo setup, copy the specific configuration and image files into the config folder of your SD Card, then restart the device. This allows you to test the device using pre-defined reference images and settings.

    Required files to copy to the SD Card config folder:

    • config.ini
    • ref0.jpg
    • ref1.jpg
    • reference.jpg
    • prevalue.ini
  7. Use the Gasmeter Value History Downloader

    main

    The Gasmeter Value History Downloader is a tool designed to download datafiles (*.txt for versions before V13.0.1 or *.csv for versions V13.0.1 and newer) from an ESP32 device. It extracts the last value of each day and stores them in a single consolidated *.csv file.

    Prerequisites

    1. Enable DataLogging: You must activate DataLogging in your device configuration via Configuration / Data Logging / DataLogActive.
    2. Retention Policy: Ensure your device's data retention setting (in days) is greater than or equal to the number of days you intend to download.

    Configuration Variables

    To use the tool, you must provide the following parameters:

    • URL to Logfile-Path on Device: The base URL where the files are hosted, typically http://<ESP32-IP-Address>/fileserver/log/.
    • Download datafiles to: A local directory path where the raw files will be saved (e.g., D:\Gaszaehler\Auswertung\Log-Downloads\).
    • Output CSV-File: The local path and filename for the consolidated daily values file (e.g., D:\Gaszaehler\Auswertung\DailyValues.csv).
    • Download past # days: The maximum number of past days to download (starting from yesterday). This value must be less than or equal to your device's configured data retention value. Note that the tool does not download data for the current day.
  8. Prepare the SD Card for AI on the Edge Device

    main

    To set up the SD card for the device, do not copy the contents of the sd-card/ folder from this repository directly onto your SD card. Doing so will result in a non-functional setup.

    Instead, you must use the artifacts generated by the Build-Pipeline. The files in the html folder within this repository are only templates; the functional html folder required for the device is generated during the GitHub Actions build process.