BME680 WiFi Sensor

ESP32-based environmental sensor with MQTT connectivity

View the Project on GitHub manupawickramasinghe/bme680-wifi-sensor-firmware

BME680 WiFi Sensor Firmware

This repository contains the firmware for an ESP32-based environmental sensor utilizing the Bosch BME680 sensor. The device connects to a WiFi network and publishes sensor data (temperature, humidity, pressure, and gas resistance) to an MQTT broker. It also subscribes to a command topic to receive instructions.

Features

Hardware Requirements

To build and run this project, you will need the following hardware components:

Wiring Diagram (Example)

BME680 Pin ESP32 Pin (Typical)
VCC 3.3V
GND GND
SDA GPIO 21
SCL GPIO 22

Note: GPIO pins for SDA/SCL might vary depending on your ESP32 board. Refer to your board’s pinout diagram.

Software Dependencies

This project is built using the ESP-IDF framework. Ensure you have the following installed:

Getting Started

Follow these steps to get your BME680 WiFi Sensor up and running:

  1. Clone this repository:
    git clone https://github.com/manupawickramasinghe/bme680-wifi-sensor-firmware.git
    cd bme680-wifi-sensor-firmware
    
  2. Install ESP-IDF: If you haven’t already, install the ESP-IDF framework by following the instructions in the ESP-IDF Programming Guide. This includes setting up the toolchain and environment variables.

  3. Configure WiFi and MQTT credentials: Navigate to the project directory and run the ESP-IDF configuration tool:
    idf.py menuconfig
    

    In menuconfig:

    • Go to Component config -> Wi-Fi and configure your WiFi SSID and Password.
    • Go to Component config -> MQTT and configure your MQTT broker URI (e.g., mqtt://broker.hivemq.com:1883).
    • You might also find options to configure sensor-specific parameters or MQTT topics under custom component configurations if added.
  4. Build the firmware:
    idf.py build
    
  5. Flash the firmware to your ESP32: Connect your ESP32 board to your computer via USB. Ensure you know the serial port name (e.g., /dev/ttyUSB0 on Linux/macOS, COMx on Windows).
    idf.py -p <PORT> flash
    

    Replace <PORT> with your ESP32’s serial port.

  6. Monitor sensor data via MQTT: After flashing, the ESP32 will connect to WiFi and start publishing data. You can monitor the serial output for logs:
    idf.py -p <PORT> monitor
    

    To view the MQTT data, use an MQTT client (e.g., MQTT Explorer, Mosquitto client) and subscribe to the configured topics.

Configuration

The project’s configuration is primarily handled via idf.py menuconfig. Key parameters include:

MQTT Topics and Data Format

Published Data Topic

The sensor publishes data to /zektopic/sensor/bme680/data (or a similar configured topic). The data is sent as a JSON string.

Example JSON Payload:

{
  "temperature_c": 25.50,
  "humidity_percent": 60.25,
  "pressure_hpa": 1012.34,
  "gas_resistance_ohm": 150000.00
}

Subscribed Command Topic

The device subscribes to /zektopic/sensor/bme680/command to receive commands. The expected command format is a simple string.

Example Command Payload:

REBOOT

Note: The current firmware might only log received commands. Extend mqtt_event_handler to implement specific actions based on commands.

Troubleshooting

Contributing

Contributions are welcome! If you have suggestions for improvements, bug fixes, or new features, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.