j-finger / qfuse_esp32c6

C++ firmware for ESP32C6 that receives JSON data from RP2040 and publishes it to the MQTT server.
0 stars 0 forks source link

ESP32C6 Firmware for qfuse Data Transmission System

Overview

This repository contains the firmware for the ESP32C6 module used in the qfuse development board. The ESP32C6 acts as the communication bridge between the RP2040 microcontroller and the backend server. It receives serialized sensor data over UART from the RP2040, appends timestamps, and transmits the data over Wi-Fi using the MQTT protocol to a backend server for further processing and storage.

System Overview

The ESP32C6 acts as a bridge between the RP2040 and the Raspberry Pi 4 server:

  1. Receiving Data: Receives JSON-formatted data from the RP2040 over UART.
  2. Time Synchronization: Synchronizes the current time using NTP and appends a timestamp to the JSON data.
  3. Data Transmission: Sends the time-stamped JSON data to the Raspberry Pi 4 server via MQTT over Wi-Fi.

Features

Hardware Setup

Components

Pin Assignments

Network Configuration

Software Dependencies

Build Instructions

Prerequisites

  1. Install ESP-IDF:
    • Follow the instructions at ESP-IDF Programming Guide to set up the ESP-IDF environment for the ESP32C6.
    • Ensure that the IDF_PATH environment variable is set to the location of the ESP-IDF.
  2. Install CMake:
    • Version 3.16 or higher is required.
  3. Install Python 3.x:
    • Required for the ESP-IDF build system and tools.

Building the Firmware

  1. Clone the Repository:
    git clone https://github.com/yourusername/qfuse-esp32c6-firmware.git
    cd qfuse-esp32c6-firmware
  2. Set Up Wi-Fi Credentials:
    • Copy config.h.example to config.h:
      cp main/config.h.example main/config.h
    • Edit main/config.h to include your Wi-Fi SSID and password:
      #define WIFI_SSID "YourWiFiSSID"
      #define WIFI_PASS "YourWiFiPassword"
  3. Configure the Project:
    • Run the menu configuration tool:
      idf.py menuconfig
    • In the menu, you can set additional configurations like UART pins, baud rate, and other settings if needed.
  4. Build the Firmware:
    idf.py build
    • This will compile the firmware and generate a .bin file.
  5. Flash the Firmware:
    • Connect the ESP32C6 module to your computer via USB.
    • Flash the firmware:
      idf.py -p /dev/ttyUSB0 flash
      • Replace /dev/ttyUSB0 with the appropriate serial port.
  6. Monitor the Output:
    • To monitor the serial output:
      idf.py -p /dev/ttyUSB0 monitor

Usage Instructions

Upon startup, the ESP32C6 will:

  1. Power On the System:
    • Ensure that the qfuse board is powered and the ESP32C6 module is connected to the RP2040 via UART.
  2. Establish Wi-Fi Connection:
    • On startup, the ESP32C6 will attempt to connect to the configured Wi-Fi network.
    • The status LED will blink during initialization.
  3. MQTT Communication:
    • The module will connect to the MQTT broker specified in main.cpp (default is mqtt://192.168.4.1:1883).
    • It subscribes to the time/response topic to receive the current time.
  4. Data Reception and Transmission:
    • The ESP32C6 receives JSON data from the RP2040 over UART.
    • It appends the current UNIX epoch time to the data.
    • Publishes the data to the MQTT topic sensor/data.
  5. Time Synchronization:
    • Upon connecting to the MQTT broker, the ESP32C6 publishes an empty message to time/request.
    • It waits for a response on time/response to synchronize its clock.
  6. LED Indicator:
    • The LED connected to GPIO 15 provides visual status:
      • Blinking: Initialization and setup phases.
      • On: Normal operation after setup is complete.

Code Organization

main.cpp

wifi.cpp and wifi.h

config.h and config.h.example

CMakeLists.txt

Configuration

License

This project is licensed under the MIT License.

Acknowledgments