Skip to content

kenYuCh/esp32_sensor

Repository files navigation

YARA ESP32 Sensor

YARA ESP32 Sensor is a comprehensive ESP32 sensor development platform that provides multiple hardware interfaces, web configuration interface, MQTT communication, and OTA update capabilities.

Features

Hardware Interfaces

  • ADC (Analog-to-Digital Converter): 12-bit ADC support for reading analog sensor values
  • I2C: I2C Master mode supporting multiple I2C devices
  • SPI: SPI Master/Slave mode for high-speed data transmission
  • UART: Serial communication interface supporting multiple UART channels
  • PWM: LEDC PWM output with breathing LED effects
  • GPIO: General-purpose input/output control

Network Features

  • WiFi AP+STA Mode: Simultaneous support for Access Point and Station modes
  • Web Server: Built-in web configuration interface supporting WiFi setup, OTA updates, and more
  • MQTT: Support for MQTT over TLS (MQTTS) secure communication
  • SNTP: Automatic network time synchronization

System Features

  • OTA Updates: Support for HTTPS OTA firmware updates
  • NVS Storage: Non-volatile storage for saving WiFi configuration and other settings
  • Authentication System: Web interface login authentication mechanism

Quick Start

Requirements

  • ESP-IDF v5.2.6 or newer
  • Python 3.8+
  • Supported development board: ESP32-S3-WROOM-1 (ESP32-S3-DevKitC-1 4MB/8MB/16MB)

Build and Flash

1. Set up ESP-IDF Environment

# Set ESP-IDF environment variables
. ~/esp/v5.2.6/esp-idf/export.sh

2. Build the Project

cd /path/to/yara_esp32_ota_std
idf.py build

3. Flash Firmware

# Flash all required files
idf.py -p /dev/ttyUSB0 flash

# Or use the complete flash command
idf.py -p /dev/ttyUSB0 flash monitor

4. Flash File Description

Offset Address File Description
0x1000 bootloader.bin Bootloader
0x8000 partition-table.bin Partition table
0xe000 ota_data_initial.bin OTA data initial file
0x270000 yara_esp32_ota_std.bin Application firmware

5. Monitor Serial Output

idf.py -p /dev/ttyUSB0 monitor

Web Configuration Interface

1. Initial Connection

After device startup, it will automatically create a WiFi Access Point:

  • SSID: ESP32_Config (configurable in NVS)
  • Password: 12345678 (configurable in NVS)
  • IP Address: 192.168.4.1

Connect your phone or computer to this WiFi network, then open a browser and visit http://192.168.4.1

3_wifi_ap

2. System Login

First-time access will show the login page:

  • Default Username: admin
  • Default Password: admin123
1_web_login

After successful login, you will enter the main control panel:

4_web_tab_login

3. WiFi STA Configuration

You can configure WiFi Station mode in the web interface to connect the device to an existing WiFi network:

  1. Navigate to the WiFi Settings page
  2. Enter the WiFi SSID and password to connect
  3. Click Save
  4. The device will automatically restart and connect to the configured WiFi
5_wifi_sta

Note:

  • WiFi configuration is stored in NVS and automatically loaded after restart
  • If connection fails, the device will return to AP mode
  • AP mode will automatically close after 5 minutes (only STA mode remains)

4. OTA Firmware Update

The system supports OTA updates via HTTPS:

  1. Navigate to the OTA Update page
  2. Enter the firmware download URL (HTTPS)
  3. Click Start Update
  4. The system will automatically download and install the new firmware
2_ota_update

OTA Update Process:

  • Automatically check version number
  • Download new firmware to OTA partition
  • Verify firmware integrity
  • Automatically restart and switch to new firmware

Hardware Interface Usage

GPIO Configuration

All interface GPIO configurations are defined in main/interface/interface_config.h.
By default, CHIP_NAME is set to CHIP_ESP32_S3_WROOM, which corresponds to ESP32-S3-WROOM-1 (ESP32-S3-DevKitC-1):

// I2C Configuration (ESP32-S3-WROOM-1)
#define I2C_SDA_PIN        GPIO_NUM_8    // SDA
#define I2C_SCL_PIN        GPIO_NUM_9    // SCL
#define I2C_CLOCK_SPEED_HZ 100000

// SPI Configuration (ESP32-S3-WROOM-1, FSPI)
#define SPI_MOSI_PIN       GPIO_NUM_11   // MOSI
#define SPI_MISO_PIN       GPIO_NUM_13   // MISO
#define SPI_SCLK_PIN       GPIO_NUM_12   // SCLK
#define SPI_CS_PIN         GPIO_NUM_10   // CS

// UART Configuration (ESP32-S3-WROOM-1, USB-to-UART)
#define UART_TX_PIN        GPIO_NUM_43   // TX
#define UART_RX_PIN        GPIO_NUM_44   // RX
#define UART_BAUD_RATE     115200

// PWM Example Pins (ESP32-S3-WROOM-1)
#define PWM_PIN_0          GPIO_NUM_2
#define PWM_PIN_1          GPIO_NUM_4
#define PWM_PIN_2          GPIO_NUM_5
#define PWM_PIN_3          GPIO_NUM_12

// ADC Example Pins (ESP32-S3-WROOM-1)
#define ADC_PIN_0          GPIO_NUM_1
#define ADC_PIN_1          GPIO_NUM_2

Usage Examples

For detailed interface usage examples, please refer to:

  • main/interface/README.md - Complete interface API documentation
  • main/examples/ - Various usage examples

ADC Reading Example

#include "interface/adc_interface.h"

adc_oneshot_unit_handle_t adc_handle;
adc_interface_init(ADC_UNIT_1, ADC_BITWIDTH_12, &adc_handle);

int adc_value;
adc_interface_read(adc_handle, ADC_CHANNEL_0, &adc_value);

I2C Read/Write Example

#include "interface/i2c_interface.h"

i2c_master_bus_handle_t bus_handle;
i2c_interface_init_default(I2C_NUM_0, &bus_handle);

i2c_master_dev_handle_t dev_handle;
i2c_interface_device_add(bus_handle, 0x48, &dev_handle);

uint8_t data[2] = {0x00, 0x01};
i2c_interface_write(dev_handle, data, 2, 1000);

UART Communication Example

#include "interface/uart_interface.h"

uart_interface_init_default(UART_NUM_1);

uint8_t tx_data[] = "Hello";
uart_interface_write(UART_NUM_1, tx_data, sizeof(tx_data)-1);

uint8_t rx_data[64];
int len = uart_interface_read(UART_NUM_1, rx_data, sizeof(rx_data), 1000);

MQTT Features

The system includes a built-in MQTT over TLS (MQTTS) client with support for:

  • Secure Connection: TLS/SSL encrypted communication
  • Message Queues: RX/TX message queue mechanism
  • Auto Reconnect: Automatic reconnection on connection loss
  • QoS Support: Support for QoS 0/1

MQTT Usage Example

Refer to main/examples/mqtts_example.c for complete usage instructions.

Project Structure

yara_esp32_ota_std/
├── main/
│   ├── interface/          # Hardware interface modules
│   │   ├── adc_interface.c/h
│   │   ├── i2c_interface.c/h
│   │   ├── spi_interface.c/h
│   │   ├── uart_interface.c/h
│   │   ├── pwm_interface.c/h
│   │   ├── gpio_interface.c/h
│   │   └── interface_config.h
│   ├── helper/             # Helper modules
│   │   ├── my_nvs.c/h      # NVS quick operations
│   │   └── my_queue.c/h    # Message queue
│   ├── examples/           # Usage examples
│   ├── web_server.c/h      # Web server
│   ├── wifi_manager.c/h    # WiFi management
│   ├── mqtts_client.c/h    # MQTT client
│   ├── ota_update.c/h      # OTA update
│   └── main.c              # Main program
├── document/               # Documentation images
└── README.md              # This file

Development and Debugging

Serial Monitoring

idf.py -p /dev/ttyUSB0 monitor

Clean and Rebuild

idf.py fullclean
idf.py build

Clear NVS Data

If you need to clear all stored settings (WiFi configuration, etc.), you can call in your code:

my_nvs_clear_namespace("wifi_config");
my_nvs_clear_namespace("web_auth");

Or use idf.py erase-flash to erase the entire Flash.

Frequently Asked Questions

1. WiFi Connection Failed

  • Check if SSID and password are correct
  • Ensure WiFi signal strength is sufficient
  • Check serial output logs to understand the error

2. OTA Update Failed

  • Verify HTTPS URL is accessible
  • Check if certificate is valid
  • Ensure partition table has sufficient space

3. Interface Initialization Failed

  • Check if GPIO configuration matches hardware
  • Ensure no GPIO conflicts
  • Review settings in interface_config.h

4. Web Interface Unreachable

  • Ensure you are connected to the device's WiFi AP
  • Check if IP address is 192.168.4.1
  • Clear browser cache and try again

Technical Support

License

This project is developed based on ESP-IDF and follows the corresponding open source license terms.

Version Information

  • Firmware Version: Check build output or version.md
  • ESP-IDF Version: v5.2.6
  • Supported Platform: ESP32-S3-WROOM-1 (ESP32-S3-DevKitC-1)

Note: When using for the first time, ensure that the ESP-IDF environment is properly configured and use the correct serial port for flashing and monitoring.

esp32_sensor_release

Example Images

OLED Display (SSD1306)

oled_ss1306 Simple example showing how sensor data can be displayed on a 0.96" SSD1306 OLED via I2C.

SCD30 Sensor (CO₂ / Temperature / Humidity)

scd30

Example wiring and setup of the Sensirion SCD30 CO₂ / temperature / humidity sensor over I2C.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages