Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wi-Fi sensor based on XIAO ESP32-C6

License

NotificationsYou must be signed in to change notification settings

BegoonLab/xiao-esp32c6-wifi-sensor

Repository files navigation

Wi-Fi, MQTT, BME280/BME680/SGP41 Integration & Power Management

Table of Contents

Introduction

The Smart IoT Sensor is a power-efficient device built using theXIAO ESP32C6 tiny board. It integrates Wi-Fi connectivity, MQTT messaging, environmental sensing with BME280/BME680 sensors, and robust power management, making it an ideal solution for smart home and IoT applications.

introduction.jpg

Features

  • Wi-Fi Connectivity: Seamless connection to your home or office network.
  • MQTT Integration: Publishes sensor data to an MQTT broker in JSON format.
  • Environmental Sensing: SupportsBosch BME280 andBME680 sensors for temperature, humidity, and pressure measurements. SupportsSensirion SGP41 VOC and NOx sensor.
  • Power Management: Efficiently manages power using LiPo batteries with built-in charge management.
  • Deep Sleep Mode: Extends battery life by enabling deep sleep between data transmissions.
  • ZigBee Connectivity: Seamless integration with ZigBee networks. Supports standard ZigBee clusters, easily pair your sensor with ZigBee coordinators like Home Assistant.
  • Optional Features:
    • Battery voltage monitoring
    • Connection duration tracking
    • Future support for Wi-Fi 6 and Bluetooth provisioning (TODO)

Usage

The Smart IoT Sensor can be easily integrated withHome Assistant for real-time monitoring and automation.

MQTT Data Structure

The sensor publishes data to an MQTT broker in the following JSON format:

{"ID":"7i29r9k9ltaxmbev","RSSI":-54,"battery_voltage":4.13,"temperature":"24.28","humidity":"29.32","pressure":"999.54","connection_duration_ms":1672}
  • ID: Unique identifier of the sensor
  • RSSI: Wi-Fi signal strength in dBm
  • battery_voltage: Current battery voltage
  • temperature: Temperature reading from the BME sensor
  • humidity: Humidity reading from the BME sensor
  • pressure: Pressure reading from the BME sensor
  • connection_duration_ms: Time taken to establish the MQTT connection

Schematics

Battery Connection

SensorXIAO_battery_connection.png

A battery connection schematic.

Voltage Divider

SensorXIAO_voltage_divider.png

Voltage divider schematic (if battery voltage monitoring is required).

Note: This solution continuously consumes some current from the battery but is functional for voltage monitoring.

BME280/BME680 Connection

SensorXIAO_connect_bme.png

SGP41 Connection

SensorXIAO_connect_SGP41.png

Configuration

This build was developed and tested withESP-IDF v5.3.1Followthis instruction to install it. It is required.

Configure the sensor using the following steps:

idf.py menuconfig

Then go toXIAO Sensor Configuration

  1. Wi-Fi Configuration: Set up your Wi-Fi credentials to enable network connectivity.

  2. MQTT Configuration: Connect the sensor to your MQTT server by providing the necessary broker details.

  3. Battery Check (Optional): Enable battery voltage monitoring if power management insights are needed.

  4. BME Sensor Configuration (Optional): Choose between BME280, BME680 and SGP41 sensors based on your requirements.

  5. Power Management Configuration: Set up wakeup duration, which is the duration in seconds that the device will remain in deep sleep before waking up.

  6. SensorXIAO_menu.png

Enclosure

The sensor is housed in a customizable 3D-printed enclosure.STL files are available for download and 3D printing.To customize a model use aFreeCAD project.A 3D preview is availablehere.

When printing, it is recommended to orient the parts on the hotbed as shown in the picture:

printing_setup_0.png

printing_setup_1.png

Enclosure assembly steps:

  1. Insert XIAO board intoSoC_holder :

SensorXIAO_assemby_0.jpg

  1. Insert holder into thecore part :

SensorXIAO_assembly_1.jpg

Pull down until it can't go any farther

SensorXIAO_assembly_2.jpg

  1. InsertSoC bracket :

SensorXIAO_assembly_3.jpg

  1. Insert BME sensor

SensorXIAO_assembly_4.jpg

  1. Attach an antenna. Put the coaxial wire into the channels in the core part. Use a couple of drops of glue or double-sided tape to secure the antenna in its place.

SensorXIAO_assembly_5.jpg

  1. Now solder up everything together according toschematics. And repeat an assembly steps if everything fits nicely.

SensorXIAO_assembly_6.jpg

SensorXIAO_assembly_7.jpg

  1. Insertlock into thecore part as shown:

SensorXIAO_assembly_8.jpg

  1. Finally, pullthe wrapper onto thecore part. Ensure that thelock is securing the wrapper.

SensorXIAO_assembly_9.jpg

Integration with Home Assistant

Integrate the Smart IoT Sensor with Home Assistant by following these steps:

  1. Set Up MQTT Server: If you don't have an MQTT server, refer to theHome Assistant MQTT Integration guide.
  2. Configureconfiguration.yaml: Add the following configuration to yourconfiguration.yaml file to define the sensor entities.
---mqtt:sensor:    -name:"Sensor RSSI 7i29r9k9ltaxmbev"device_class:signal_strengthstate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"dBm"value_template:"{{ value_json.RSSI }}"    -name:"Sensor Temperature 7i29r9k9ltaxmbev"device_class:temperaturestate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"°C"value_template:"{{ value_json.temperature }}"    -name:"Sensor Humidity 7i29r9k9ltaxmbev"device_class:humiditystate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"%"value_template:"{{ value_json.humidity }}"    -name:"Sensor Pressure 7i29r9k9ltaxmbev"device_class:pressurestate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"hPa"value_template:"{{ value_json.pressure }}"    -name:"Sensor Battery Voltage 7i29r9k9ltaxmbev"device_class:voltagestate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"V"value_template:"{{ value_json.battery_voltage }}"    -name:"Sensor Connection Duration 7i29r9k9ltaxmbev"device_class:durationstate_topic:"xiao/sensor/7i29r9k9ltaxmbev/data"unit_of_measurement:"ms"value_template:"{{ value_json.connection_duration_ms }}"
  1. Restart Home Assistant: After updating the configuration, restart Home Assistant to apply the changes.
  2. Configure Entity Card: Here is an example configuration for the entity card:
---type:entitiesentities:  -entity:sensor.sensor_temperature_7i29r9k9ltaxmbevicon:mdi:thermometer-lowsecondary_info:last-changedname:Temperature  -entity:sensor.sensor_humidity_7i29r9k9ltaxmbevname:Humidity  -entity:sensor.sensor_pressure_7i29r9k9ltaxmbevname:Pressure  -entity:sensor.sensor_rssi_7i29r9k9ltaxmbevicon:mdi:wifi-strength-3secondary_info:nonename:RSSI  -entity:sensor.sensor_battery_voltage_7i29r9k9ltaxmbevicon:mdi:battery-80secondary_info:nonename:Battery  -entity:sensor.sensor_connection_duration_7i29r9k9ltaxmbevname:Connection Durationtitle:Sensor 7i29r9k9ltaxmbev

SensorXIAO_ha_card.png

Getting Started

Follow these steps to set up your Smart IoT Sensor:

  1. Clone the Repository

    git clone https://github.com/BegoonLab/xiao-esp32c6-wifi-sensorcd xiao-esp32c6-wifi-sensorgit submodule update --init --recursive
  2. Install Dependencies

    Ensure you have the necessary tools and libraries installed. Refer to theSoftware section for more details.

  3. Configure the Sensor

    Edit the configuration files to set your Wi-Fi and MQTT credentials.

  4. Build and Flash

    Compile the firmware and flash it to your XIAO ESP32C6 board.

  5. Assemble the Hardware

    Connect the BME sensor and battery as per the schematics. 3D print the enclosure and assemble the components.

  6. Deploy and Monitor

    Power on the sensor and monitor the data through your MQTT broker and Home Assistant.

Hardware

Components Required

  • XIAO ESP32C6: The main microcontroller unit.
  • Bosch BME280 or BME680 Sensor: For measuring temperature, humidity, and pressure.
  • LiPo Battery: Any standard LiPo battery compatible with XIAO's charge management.
  • Voltage Divider Components: If battery voltage monitoring is required.
  • Additional Components:
    • Connectors and cables
    • External antenna (optional, but highly recommended for weak Wi-Fi signals). This is RSSI without and then with external antenna:SensorXIAO_rssi_antenna.png
      • These antennas tested and worked quite well with this build:
      • PCB Antenna 5dBi and U.FL connector
      • SensorXIAO_external_antenna.jpg
      • RadioMaster FPV Drone antenna
      • SensorXIAO_external_antenna_radiomaster.png

Assembly Instructions

  1. Mount the Sensor: Connect the BME280/BME680 to the XIAO ESP32C6.
  2. Connect the Battery: Ensure the battery is properly connected to the charge management circuitry.
  3. Set Up Voltage Divider: If monitoring battery voltage, assemble the voltage divider as per the schematic.
  4. Enclose the Assembly: Use the 3D-printed enclosure to house all components securely.

Software

Dependencies

Building the Firmware

  1. Install ESP-IDF

    Follow theESP-IDF Getting Started Guide to set up the development environment.

  2. Configure the Project

    idf.py menuconfig
    • Set Wi-Fi credentials
    • Configure MQTT broker details
    • Enable or disable optional features
  3. Build and Flash

    idf.py buildidf.py -p<TARGET_PORT> flash

When a sensor misbehaves, it's helpful to output logs to diagnose the issue. By default, logging is disabled. To enable it, follow these steps:

  1. Open the configuration menu:
    idf.py menuconfig
  2. Navigate to:Component configLog outputDefault log verbosity.
  3. Set the verbosity level toInfo.
  4. Save the changes, and then execute the following command to build, flash, and monitor:
    idf.py -p<TARGET_PORT> build flash monitor

ZigBee

ZigBee can be activated in the menu:

idf.py menuconfig

Navigate toXIAO Sensor ConfigurationSelect Sensor Connection TypeZigBee.

Next, go toComponent configZigbeeZigbee Enable and set it to ON. Then, go toXIAO Sensor ConfigurationZigBee Configuration and set aSensor ID.

Build and flash the firmware. After that, the sensor will be ready and will begin commissioning.

To add the sensor to Home Assistant: go toSettingsDevices & ServicesDevicesAdd DeviceAdd Zigbee device. Once completed, your sensor will appear on the Devices page:

SensorXIAO_zb_device.png

Note: The SGP41 sensor is not currently supported because the ZigBee protocol does not include VOC and NOx clusters in its specification.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the Repository

  2. Create a Feature Branch

    git checkout -b feature/YourFeature
  3. Commit Your Changes

  4. Push to the Branch

    git push origin feature/YourFeature
  5. Open a Pull Request

License

This project is licensed under theMIT License. All rights reserved.

TODO

  • Wi-Fi 6 Support: Enhance connectivity options with Wi-Fi 6.
  • Bluetooth Provisioning: Implement Bluetooth-based provisioning for easier setup.
  • Additional Sensor Support: Expand compatibility with other types of sensors.

About

Wi-Fi sensor based on XIAO ESP32-C6

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp