Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b4283e9
Updati STCC4 driver.
dmitriyk-aethernet May 27, 2026
217e4f3
Fixing WiFi SSID name bug.
dmitriyk-aethernet May 27, 2026
01c390c
Updating Power ON logic for STCC4 sensor.
dmitriyk-aethernet May 28, 2026
e86e3ff
Updating IO pins.
dmitriyk-aethernet May 28, 2026
698241c
Test build.
dmitriyk-aethernet May 28, 2026
251c212
Test build.
dmitriyk-aethernet May 28, 2026
a3daffc
Test build.
dmitriyk-aethernet May 28, 2026
b8dbf65
Test build.
dmitriyk-aethernet May 28, 2026
02550bb
Test build.
dmitriyk-aethernet May 28, 2026
d1086a1
Test build.
dmitriyk-aethernet May 28, 2026
6a496d7
Fixing Ci/Cd.
dmitriyk-aethernet May 28, 2026
33156c1
Fixing BOARD definition for the ULP build.
dmitriyk-aethernet May 29, 2026
d3268f3
Fixing target_compile_definitions for BOARD.
dmitriyk-aethernet May 29, 2026
617ef3f
Fixing Ci/Cd build.
dmitriyk-aethernet May 29, 2026
8189829
Merge branch 'main' into 3-update-the-stcc4-sensor-code-for-the-therm…
dmitriyk-aethernet Jun 3, 2026
9b1d1b7
Fixing gitmodules.
dmitriyk-aethernet Jun 3, 2026
258ff5b
Removing submodules.
dmitriyk-aethernet Jun 3, 2026
517b5dc
Deleting aether-client-cpp submodule.
dmitriyk-aethernet Jun 3, 2026
ea52a70
Fixing comments.
dmitriyk-aethernet Jun 8, 2026
5510419
Migrating to the new ESP32 I2C driver.
dmitriyk-aethernet Jun 18, 2026
67c5beb
Updating STCC4 ULP code.
dmitriyk-aethernet Jun 25, 2026
8acaaa8
Updating I2C speed.
dmitriyk-aethernet Jun 29, 2026
40f8dce
Merge branch 'main' into 3-update-the-stcc4-sensor-code-for-the-therm…
dmitriyk-aethernet Jun 30, 2026
b6a0cab
Fixing issues based on the results of review.
dmitriyk-aethernet Jun 30, 2026
cef2dec
Removing some unnecessary preprocessor directives.
dmitriyk-aethernet Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
sdkconfig*
!sdkconfig.defaults

# Build directory
build/

# IDE directory
.pio
.vscode

# CLang
.clangd
33 changes: 22 additions & 11 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ else()
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/.."
REQUIRES soc ulp
PRIV_REQUIRES
esp_driver_tsens
esp_driver_gpio
esp_http_server
esp_event
esp_timer
esp_netif
esp_hw_support
driver)
idf::driver
idf::esp_driver_i2c
idf::esp_driver_tsens
idf::esp_driver_gpio
idf::esp_http_server
idf::esp_event
idf::esp_timer
idf::esp_netif
idf::esp_hw_support)

set(TARGET_NAME "${COMPONENT_LIB}")

include(../cmake/CPM.cmake)
CPMAddPackage(URI "https://github.com/aethernetio/aether-client-cpp.git#main")

target_link_libraries(${TARGET_NAME} PRIVATE aether)

ulp_add_project("ulp_main" "${CMAKE_CURRENT_LIST_DIR}/../ulp")

if (NOT "${WIFI_SSID}" STREQUAL "")
target_compile_definitions(${TARGET_NAME} PRIVATE "WIFI_SSID=\"${WIFI_SSID}\"")
endif()
Expand All @@ -93,6 +91,19 @@ else()
target_compile_definitions(${TARGET_NAME} PRIVATE "BOARD=${BOARD}")
endif()

# Define the path to the board configuration file in the build folder
set(ULP_BOARD_FILE "${CMAKE_BINARY_DIR}/ulp_board_config.cmake")

# Write the value of the BOARD variable to this file
if(NOT "${BOARD}" STREQUAL "")
file(WRITE "${ULP_BOARD_FILE}" "set(BOARD \"${BOARD}\")\n")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really complicated!

First of all you should use configure_file cmake command for this.

Did you check what BOARD variable is not visible inside ulp/CMakeLists.txt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe later.

else()
file(WRITE "${ULP_BOARD_FILE}" "set(BOARD \"\")\n")
endif()

# We call the project addition as usual
ulp_add_project("ulp_main" "${CMAKE_CURRENT_LIST_DIR}/../ulp")

else()
#Other platforms
message(FATAL_ERROR "Platform ${CM_PLATFORM} is not supported")
Expand Down
18 changes: 13 additions & 5 deletions main/boards/aether_esp32_c6.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,36 @@
# error "Illegal CPU! It must be an ESP32C6."
#endif

#include "hal/i2c_types.h"
#include "soc/gpio_num.h"

#ifndef BOARD_HAS_ULP
# define BOARD_HAS_ULP 0
#endif
#ifndef BOARD_HAS_LED
# define BOARD_HAS_LED 1
#endif
#ifndef BOARD_HAS_PWR_ON
# define BOARD_HAS_PWR_ON 1
#endif
#ifndef STATUS_LED_PIN
# define STATUS_LED_PIN GPIO_NUM_7
# define STATUS_LED_ON_PIN GPIO_NUM_17
# define STATUS_LED_PIN GPIO_NUM_18
#endif
#ifndef PWR_ON_GPIO
# define PWR_ON_GPIO GPIO_NUM_2
# define LP_PWR_ON_GPIO LP_IO_NUM_2
#endif
#ifndef RESET_BUTTON_PIN
# define RESET_BUTTON_PIN GPIO_NUM_9
#endif
// --- Sensors ---
#define BOARD_HAS_SHTC3 0
#define BOARD_HAS_SHT45 1
#define BOARD_HAS_SHT45 0
#define BOARD_HAS_STCC4 1
#define BOARD_HAS_BME688 0
// --- Hardware Settings ---
#define SENSOR_SDA_PIN 19
#define SENSOR_SCL_PIN 18
#define SENSOR_SDA_PIN GPIO_NUM_6
#define SENSOR_SCL_PIN GPIO_NUM_7
// FIX 1: Use a Fixed Buffer instead of VLA (Variable Length Array) to prevent
// stack smash
#define MAX_I2C_BUFFER 64
12 changes: 10 additions & 2 deletions main/boards/m5stack_atom_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@
#endif

#include "hal/i2c_types.h"
#include "soc/gpio_num.h"

#ifndef BOARD_HAS_ULP
# define BOARD_HAS_ULP 0
#endif
#ifndef BOARD_HAS_LED
# define BOARD_HAS_LED 1
#endif
#ifndef BOARD_HAS_PWR_ON
# define BOARD_HAS_PWR_ON 0
#endif
#ifndef STATUS_LED_PIN
# define STATUS_LED_PIN GPIO_NUM_35
#endif
#ifndef PWR_ON_GPIO
# define PWR_ON_GPIO -1
# define LP_PWR_ON_GPIO -1
#endif
#ifndef RESET_BUTTON_PIN
# define RESET_BUTTON_PIN GPIO_NUM_41
#endif
Expand All @@ -40,8 +48,8 @@
#define BOARD_HAS_STCC4 0
#define BOARD_HAS_BME688 1
// --- Hardware Settings ---
#define SENSOR_SDA_PIN 2
#define SENSOR_SCL_PIN 1
#define SENSOR_SDA_PIN GPIO_NUM_2
#define SENSOR_SCL_PIN GPIO_NUM_1
// FIX 1: Use a Fixed Buffer instead of VLA (Variable Length Array) to prevent
// stack smash
#define MAX_I2C_BUFFER 64
11 changes: 9 additions & 2 deletions main/boards/nano_esp32_c6.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@
#ifndef BOARD_HAS_LED
# define BOARD_HAS_LED 1
#endif
#ifndef BOARD_HAS_PWR_ON
# define BOARD_HAS_PWR_ON 0
#endif
#ifndef STATUS_LED_PIN
# define STATUS_LED_PIN GPIO_NUM_8
#endif
#ifndef PWR_ON_GPIO
# define PWR_ON_GPIO -1
# define LP_PWR_ON_GPIO -1
#endif
#ifndef RESET_BUTTON_PIN
# define RESET_BUTTON_PIN GPIO_NUM_9
#endif
// --- Sensors ---
#define BOARD_HAS_SHTC3 0
#define BOARD_HAS_SHT45 1
#define BOARD_HAS_SHT45 0
#define BOARD_HAS_STCC4 0
#define BOARD_HAS_BME688 0
#define BOARD_HAS_BME688 1
// --- Hardware Settings ---
#define SENSOR_SDA_PIN GPIO_NUM_6
#define SENSOR_SCL_PIN GPIO_NUM_7
Expand Down
7 changes: 5 additions & 2 deletions main/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ void loop() {
// implemented in sensors/
void UpdateSensors() {
std::int16_t temperature = {};
ReadSensors(&temperature, nullptr, nullptr, nullptr, nullptr);
std::cout << ae::Format(" >>> Temperature: [{}]\n", temperature);
std::uint32_t humidity = {};
std::uint32_t co2 = {};
ReadSensors(&temperature, &humidity, nullptr, &co2, nullptr);
std::cout << ae::Format(" >>> Temperature: [{}], Humidity: [{}], CO2: [{}]\n",
temperature, humidity, co2);
// TODO: add check if wakeup cause is ulp then send value
SendValue(temperature);
}
Expand Down
54 changes: 44 additions & 10 deletions main/sensors/bme688.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,34 @@
# include "sensors/sensors.h"
# include "sensors/utils.h"

# ifdef IS_ULP_COCPU
# define BME_I2C_NUM LP_I2C_NUM_0
# else
# define BME_I2C_NUM I2C_NUM_0
# if ULP_COMP == 0
static i2c_master_bus_handle_t bus_handle;
static i2c_master_dev_handle_t dev_handle_bme688;
# endif

# if ULP_COMP == 1
# define BME688_I2C_NUM_0 LP_I2C_NUM_0
# define I2C_BUS_HANDLE_S 0
# define I2C_HANDLE_PORT_S BME688_I2C_NUM_0
# elif ULP_COMP == 0
# define BME688_I2C_NUM_0 I2C_NUM_0
# define I2C_BUS_HANDLE_S &bus_handle
# define I2C_HANDLE_PORT_S dev_handle_bme688
# endif

// Constants
# define I2C_TRANS_TIMEOUT_CYCLES 5000
# define I2C_TRANS_WAIT_FOREVER -1
# define I2C_BUS_SPEED 400000 // 400 KHz

// --- SAFER Interface Functions ---
static BME68X_INTF_RET_TYPE bme_i2c_read(uint8_t reg_addr, uint8_t* reg_data,
uint32_t len, void* intf_ptr) {
uint8_t dev_addr = *(uint8_t*)intf_ptr;
esp_err_t err = i2c_write_read(BME_I2C_NUM, dev_addr, &reg_addr, 1, reg_data,

esp_err_t err = i2c_write_read(I2C_HANDLE_PORT_S, dev_addr, &reg_addr, 1, reg_data,
len, I2C_TRANS_TIMEOUT_CYCLES);

return (err == ESP_OK) ? BME68X_OK : BME68X_E_COM_FAIL;
}

Expand All @@ -67,8 +79,8 @@ static BME68X_INTF_RET_TYPE bme_i2c_write(uint8_t reg_addr,
// Safe copy
memcpy(&buffer[1], reg_data, len);

esp_err_t err =
i2c_write(BME_I2C_NUM, dev_addr, buffer, len + 1, I2C_TRANS_WAIT_FOREVER);
esp_err_t err = i2c_write(I2C_HANDLE_PORT_S, dev_addr, buffer, len + 1, I2C_TRANS_WAIT_FOREVER);

return (err == ESP_OK) ? BME68X_OK : BME68X_E_COM_FAIL;
}

Expand All @@ -82,12 +94,30 @@ struct bme68x_dev bme;
struct bme68x_conf conf;
uint8_t dev_addr = BME68X_I2C_ADDR_LOW;

bool Init() {
// 1. INSTALL I2C DRIVER
if (i2c_init(BME_I2C_NUM, SENSOR_SDA_PIN, SENSOR_SCL_PIN) != ESP_OK) {
bool init_i2c(uint8_t dev_addr){
// 2. Install I2C driver
if (i2c_init(I2C_BUS_HANDLE_S, BME688_I2C_NUM_0, SENSOR_SDA_PIN, SENSOR_SCL_PIN, I2C_BUS_SPEED) != ESP_OK) {
return false;
}

#if ULP_COMP == 0
// Configuration of a specific device on the bus
i2c_device_config_t dev_cfg_bme688 = {};
dev_cfg_bme688.dev_addr_length = I2C_ADDR_BIT_LEN_7;
dev_cfg_bme688.device_address = dev_addr; // Address BME688
dev_cfg_bme688.scl_speed_hz = I2C_BUS_SPEED;

if(i2c_master_bus_add_device(bus_handle, &dev_cfg_bme688, &dev_handle_bme688) != ESP_OK){
return false;
}
#endif

return true;
}

bool Init() {
init_i2c(dev_addr);

// 2. Initialize BME Sensor
bme.read = bme_i2c_read;
bme.write = bme_i2c_write;
Expand All @@ -98,6 +128,10 @@ bool Init() {

if (bme68x_init(&bme) != BME68X_OK) {
dev_addr = BME68X_I2C_ADDR_HIGH; // Try alternate address
#if ULP_COMP == 0
i2c_master_bus_rm_device(dev_handle_bme688);
#endif
init_i2c(dev_addr);
if (bme68x_init(&bme) != BME68X_OK) {
return false;
}
Expand Down
53 changes: 32 additions & 21 deletions main/sensors/esp_main_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,55 @@
* limitations under the License.
*/

#if defined ESP_PLATFORM && !defined IS_ULP_COCPU
#include "user_config.h"

#if defined ESP_PLATFORM && ULP_COMP == 0
# include <freertos/FreeRTOS.h>
# include <freertos/task.h>

# include "driver/i2c.h"
# include "driver/i2c_master.h"
# include "esp_log.h"

esp_err_t i2c_init(i2c_port_t port, int sda_pin, int scl_pin) {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = sda_pin,
.scl_io_num = scl_pin,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {.clk_speed = 100000},
.clk_flags = 0,
};
if (i2c_param_config(port, &conf) != ESP_OK) {
static const char *TAG_I2C = "I2C";

esp_err_t i2c_init(i2c_master_bus_handle_t *bus_handle, i2c_port_t i2c_handle_port, int sda_pin, int scl_pin, int i2c_speed) {
esp_err_t err;

i2c_master_bus_config_t bus_cfg = {};

ESP_LOGI(TAG_I2C, "Init ESP i2c");
bus_cfg.i2c_port = i2c_handle_port;
bus_cfg.sda_io_num = sda_pin;
bus_cfg.scl_io_num = scl_pin;
bus_cfg.clk_source = I2C_CLK_SRC_DEFAULT;
bus_cfg.glitch_ignore_cnt = 7;
bus_cfg.intr_priority = 0;
bus_cfg.flags.enable_internal_pullup = 0;
bus_cfg.flags.allow_pd = 0;

err = i2c_new_master_bus(&bus_cfg, bus_handle);
if(err != ESP_OK){
ESP_LOGE(TAG_I2C, "Failed to install the i2c driver! Error: %s", esp_err_to_name(err));
return ESP_ERR_INVALID_STATE;
}
return i2c_driver_install(port, conf.mode, 0, 0, 0);

return ESP_OK;
}

esp_err_t i2c_write(i2c_port_t port, uint8_t address, uint8_t const* data,
esp_err_t i2c_write(i2c_master_bus_handle_t *bus_handle, i2c_master_dev_handle_t i2c_handle_port, uint8_t address, uint8_t const* data,
uint8_t len, int32_t ms_dur) {
return i2c_master_write_to_device(port, address, data, len,
ms_dur);
return i2c_master_transmit(i2c_handle_port, data, len, ms_dur);
}

esp_err_t i2c_read(i2c_port_t port, uint8_t address, uint8_t* data, uint8_t len,
esp_err_t i2c_read(i2c_master_bus_handle_t *bus_handle, i2c_master_dev_handle_t i2c_handle_port, uint8_t address, uint8_t* data, uint8_t len,
int32_t ms_dur) {
return i2c_master_read_from_device(port, address, data, len, ms_dur);
return i2c_master_receive(i2c_handle_port, data, len, ms_dur);
}

esp_err_t i2c_write_read(i2c_port_t port, uint8_t address,
esp_err_t i2c_write_read(i2c_master_bus_handle_t *bus_handle, i2c_master_dev_handle_t i2c_handle_port, uint8_t address,
uint8_t const* write_data, uint8_t write_len,
uint8_t* read_data, uint8_t read_len, int32_t ms_dur) {
return i2c_master_write_read_device(port, address, write_data, write_len,
return i2c_master_transmit_receive(i2c_handle_port, write_data, write_len,
read_data, read_len,
ms_dur);
}
Expand Down
Loading