Skip to content

Firmware Design

Albin Varghese edited this page Sep 15, 2024 · 3 revisions

HydroLink Plus Firmware Documentation

Table of Contents

  1. Introduction
  2. Firmware Overview
  3. Technical Architecture
  4. Hardware Interaction
  5. Power Management
  6. Storage Management
  7. Remote Firmware Updates (OTA)
  8. Diagrams
  9. Conclusion

Introduction

The firmware is the central element that coordinates all operations of the HydroLink Plus system, ensuring that each water meter functions seamlessly while interacting securely with the central Authority Server.


Firmware Overview

The firmware is built using ESP-IDF, enabling it to leverage the full power of the ESP32 microcontroller for multi-tasking, low-power modes, and secure communication.

Key Features

  1. Task Coordination:

    • Efficient task scheduling using FreeRTOS allows the system to manage multiple hardware modules (sensors, actuators, communication modules) and perform scheduled tasks like data collection and transmission.
  2. Meter Registration:

    • Each water meter is uniquely registered with the central Authority Server, and the firmware ensures that communication is tamperproof by encrypting data and employing advanced security measures.
  3. Secure Bidirectional Communication:

    • Mutual authentication ensures that both the water meter and server verify each other before transferring data, preventing unauthorized access or data manipulation.
  4. Remote Over-the-Air (OTA) Updates:

    • OTA allows the firmware to be remotely updated, minimizing the need for manual interventions and making it easier to deploy patches or new features.
  5. Power Management:

    • Power consumption is minimized through the use of Deep Sleep Mode and dynamic control of the hardware modules based on solar input and battery levels.

Technical Architecture

The firmware of HydroLink Plus is designed with several key modules that work in parallel, ensuring that the system remains responsive while maintaining efficiency.

graph TD;
    A[ESP32 Firmware] --> B[Task Scheduler];
    B --> C[Sensor Data Collection];
    B --> D[Power Management];
    B --> E[Communication Handling];
    C --> F{Sensors};
    F --> G[pH Sensor];
    F --> H[Conductivity Sensor];
    F --> I[Turbidity Sensor];
    F --> J[Water Flow Sensor];
    E --> K[Wi-Fi Transmission];
    E --> L[Controller API];
    D --> M[Solar Power Management];
    D --> N[Battery Control];
Loading

This architecture shows the task scheduler managing the key components: sensor data collection, power management, and communication handling.

ESP-IDF Project

Using the ESP-IDF framework, the firmware is developed to leverage the following features of the ESP32:

  • FreeRTOS Multitasking: Manages multiple processes such as reading sensors, controlling the valve, and sending data.
  • Wi-Fi Stack: Handles secure, low-latency data transfers between the device and the remote server.
  • Power Management API: Controls when to activate deep sleep based on power input and consumption.

Task and Process Coordination

The firmware is structured to handle various tasks concurrently. These tasks include:

  1. Data Collection: Sensors periodically report the water’s pH level, temperature, conductivity, and turbidity.
  2. Data Transmission: Sensor data is encrypted and sent to the Authority Server at defined intervals.
  3. Motorized Valve Control: The system can open or close valves based on real-time water usage data or server instructions.
  4. Error Detection: If tampering is detected or hardware malfunctions, alerts are sent to the central server.
gantt
    title Task Scheduling for HydroLink Plus Firmware
    section Tasks
    Data Collection  :active, a1, 2024-09-16, 30s
    Motorized Valve Control :a2, after a1, 15s
    Data Transmission :a3, after a2, 20s
    Power Management :a4, after a3, 10s
Loading

Hardware Interaction

Sensor Regulation

The firmware controls a wide range of sensors that monitor water quality and flow. These include:

  1. pH Sensor: Measures the acidity or alkalinity of the water.
  2. Conductivity Sensor: Measures water purity by analyzing its ability to conduct electricity.
  3. Turbidity Sensor: Assesses the clarity of the water by measuring the amount of suspended particles.
  4. Water Flow Sensor: Continuously monitors the flow rate of water.

The firmware reads from these sensors using analog-to-digital converters (ADC), processes the data, and sends it to the Authority Server for further analysis.

graph TD;
    A[ESP32] -->|Analog Signal| B[pH Sensor];
    A -->|Analog Signal| C[Conductivity Sensor];
    A -->|Digital Signal| D[Water Flow Sensor];
    A -->|Analog Signal| E[Turbidity Sensor];
Loading

Motorized Valve Control

The system controls motorized valves to manage water flow and handle potential issues like leaks. The firmware receives commands from the server to open or close these valves automatically based on pre-set conditions or real-time sensor data.

graph TD;
    Server[Authority Server] -->|Command| ESP32[ESP32 Microcontroller];
    ESP32 -->|Control Signal| Valve[Motorized Valve];
Loading

Power Management

One of the core features of HydroLink Plus is efficient power management. The firmware incorporates solar power monitoring and battery regulation to ensure optimal use of energy.

Deep Sleep Mode

To conserve power, the ESP32 switches to Deep Sleep Mode during idle periods. In this mode:

  • The CPU and most peripherals are powered down.
  • The firmware wakes the system only for critical tasks such as sensor readings or data transmission.
graph TD;
    Start -->|System Active| A[Task Execution];
    A --> B{Idle Period?};
    B -->|Yes| C[Deep Sleep Mode];
    B -->|No| D[Continue Operations];
    C --> E{Wake Event?};
    E -->|Yes| Start;
    E -->|No| C;
Loading

Solar Power and Battery Management

The firmware dynamically adjusts its operations based on solar input and battery levels. If solar power is low or the battery is running out, it shifts to low-power modes, prioritizing critical tasks such as data transmission and sensor monitoring.


Storage Management

The firmware uses Non-Volatile Storage (NVS) to retain important configuration data and logs. Data such as sensor calibration settings, MAC addresses, and event logs are stored in NVS, ensuring that they persist even after a power cycle or reboot.


Remote Firmware Updates (OTA)

Over-the-Air (OTA) updates allow remote administrators to update the firmware without physical access. This is crucial for deploying security patches, feature upgrades, or bug fixes.

The OTA functionality is managed through the ESP-IDF’s OTA API, which performs the following:

  1. Version Checking: The system checks the server for available firmware updates.
  2. Download and Install: If an update is available, the firmware is downloaded, verified, and installed.
  3. Rollback Mechanism: If the update fails, the firmware reverts to the previous stable version.
graph TD;
    Start -->|Check for Updates| A[New Firmware Available?];
    A -->|Yes| B[Download Firmware];
    B --> C[Verify Integrity];
    C -->|Valid| D[Install Firmware];
    D --> E[Restart Device];
    A -->|No| F[Continue Operations];
Loading

Conclusion

The HydroLink Plus firmware is a highly secure, efficient, and flexible system that manages smart water meters. Its ability to handle multiple tasks, minimize power consumption, and maintain secure communication with the central server makes it an essential component of modern water management systems. With the added benefits of OTA updates, tamperproof measures, and advanced power management, HydroLink Plus provides an industry-leading solution for smart water meters.

HydroLink Plus ©2024

Clone this wiki locally