From 81af8cd576e22333fa2733e1dbc266678bc12bac Mon Sep 17 00:00:00 2001 From: Kostas Drakontidis Date: Thu, 7 May 2026 00:06:24 +0300 Subject: [PATCH] Initial tag code --- src/officesense_tag/.clangd | 2 + src/officesense_tag/.devcontainer/Dockerfile | 13 +++ .../.devcontainer/devcontainer.json | 19 ++++ src/officesense_tag/.gitignore | 78 ++++++++++++++++ src/officesense_tag/CMakeLists.txt | 8 ++ src/officesense_tag/main/CMakeLists.txt | 2 + src/officesense_tag/main/main.c | 92 +++++++++++++++++++ 7 files changed, 214 insertions(+) create mode 100644 src/officesense_tag/.clangd create mode 100644 src/officesense_tag/.devcontainer/Dockerfile create mode 100644 src/officesense_tag/.devcontainer/devcontainer.json create mode 100644 src/officesense_tag/.gitignore create mode 100644 src/officesense_tag/CMakeLists.txt create mode 100644 src/officesense_tag/main/CMakeLists.txt create mode 100644 src/officesense_tag/main/main.c diff --git a/src/officesense_tag/.clangd b/src/officesense_tag/.clangd new file mode 100644 index 0000000..437f255 --- /dev/null +++ b/src/officesense_tag/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Remove: [-f*, -m*] diff --git a/src/officesense_tag/.devcontainer/Dockerfile b/src/officesense_tag/.devcontainer/Dockerfile new file mode 100644 index 0000000..dafb8ad --- /dev/null +++ b/src/officesense_tag/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +ARG DOCKER_TAG=latest +FROM espressif/idf:${DOCKER_TAG} + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +RUN apt-get update -y && apt-get install udev -y + +RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc + +ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] + +CMD ["/bin/bash", "-c"] \ No newline at end of file diff --git a/src/officesense_tag/.devcontainer/devcontainer.json b/src/officesense_tag/.devcontainer/devcontainer.json new file mode 100644 index 0000000..246b79f --- /dev/null +++ b/src/officesense_tag/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "ESP-IDF QEMU", + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "idf.gitPath": "/usr/bin/git" + }, + "extensions": [ + "espressif.esp-idf-extension", + "espressif.esp-idf-web" + ] + } + }, + "runArgs": ["--privileged"] +} \ No newline at end of file diff --git a/src/officesense_tag/.gitignore b/src/officesense_tag/.gitignore new file mode 100644 index 0000000..7805557 --- /dev/null +++ b/src/officesense_tag/.gitignore @@ -0,0 +1,78 @@ +# macOS +.DS_Store +.AppleDouble +.LSOverride + +# Directory metadata +.directory + +# Temporary files +*~ +*.swp +*.swo +*.bak +*.tmp + +# Log files +*.log + +# Build artifacts and directories +**/build/ +build/ +*.o +*.a +*.out +*.exe # For any host-side utilities compiled on Windows + +# ESP-IDF specific build outputs +*.bin +*.elf +*.map +flasher_args.json # Generated in build directory +sdkconfig.old +sdkconfig + +# ESP-IDF dependencies +# For older versions or manual component management +/components/.idf/ +**/components/.idf/ +# For modern ESP-IDF component manager +managed_components/ +# If ESP-IDF tools are installed/referenced locally to the project +.espressif/ + +# CMake generated files +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake + +# Python environment files +*.pyc +*.pyo +*.pyd +__pycache__/ +*.egg-info/ +dist/ + +# Virtual environment folders +venv/ +.venv/ +env/ + +# Language Servers +.clangd/ +.ccls-cache/ +compile_commands.json + +# Windows specific +Thumbs.db +ehthumbs.db +Desktop.ini + +# User-specific configuration files +*.user +*.workspace # General workspace files, can be from various tools +*.suo # Visual Studio Solution User Options +*.sln.docstates # Visual Studio diff --git a/src/officesense_tag/CMakeLists.txt b/src/officesense_tag/CMakeLists.txt new file mode 100644 index 0000000..63729a0 --- /dev/null +++ b/src/officesense_tag/CMakeLists.txt @@ -0,0 +1,8 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(officesense_tag) \ No newline at end of file diff --git a/src/officesense_tag/main/CMakeLists.txt b/src/officesense_tag/main/CMakeLists.txt new file mode 100644 index 0000000..e0287b7 --- /dev/null +++ b/src/officesense_tag/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "main.c" + INCLUDE_DIRS ".") \ No newline at end of file diff --git a/src/officesense_tag/main/main.c b/src/officesense_tag/main/main.c new file mode 100644 index 0000000..25142f7 --- /dev/null +++ b/src/officesense_tag/main/main.c @@ -0,0 +1,92 @@ +#include +#include +#include "nvs_flash.h" + +#include "nimble/nimble_port.h" +#include "nimble/nimble_port_freertos.h" + +#include "host/ble_hs.h" +#include "services/gap/ble_svc_gap.h" + +static const char *TAG = "BLE"; + +static const ble_uuid128_t service_uuid = + BLE_UUID128_INIT( + 0xF0, 0xDE, 0xBC, 0x9A, + 0x78, 0x56, 0x34, 0x12, + 0xF0, 0xDE, 0xBC, 0x9A, + 0x78, 0x56, 0x34, 0x12); + +static void start_adv(void) +{ + struct ble_hs_adv_fields fields; + memset(&fields, 0, sizeof(fields)); + + fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; + + fields.uuids128 = (ble_uuid128_t *)&service_uuid; + fields.num_uuids128 = 1; + fields.uuids128_is_complete = 1; + + uint8_t mfg_data[5] = {0x34, 0x34, 0x34, 0x34, 0x34}; + + fields.mfg_data = mfg_data; + fields.mfg_data_len = sizeof(mfg_data); + + int rc = ble_gap_adv_set_fields(&fields); + if (rc != 0) + { + ESP_LOGE(TAG, "adv set fields failed: %d", rc); + return; + } + + struct ble_gap_adv_params params; + memset(¶ms, 0, sizeof(params)); + + params.conn_mode = BLE_GAP_CONN_MODE_NON; + params.disc_mode = BLE_GAP_DISC_MODE_GEN; + params.itvl_min = 0x80; // ~100ms + params.itvl_max = 0x80; + + rc = ble_gap_adv_start( + BLE_ADDR_PUBLIC, + NULL, + BLE_HS_FOREVER, + ¶ms, + NULL, + NULL); + + if (rc != 0) + { + ESP_LOGE(TAG, "adv start failed: %d", rc); + } + else + { + ESP_LOGI(TAG, "advertising started"); + } +} + +static void on_sync(void) +{ + ESP_LOGI(TAG, "BLE synced"); + + start_adv(); +} + +static void host_task(void *param) +{ + nimble_port_run(); +} + +void app_main(void) +{ + ESP_ERROR_CHECK(nvs_flash_init()); + nimble_port_init(); + + ble_svc_gap_init(); + ble_svc_gap_device_name_set("XIAO_C6"); + + ble_hs_cfg.sync_cb = on_sync; + + nimble_port_freertos_init(host_task); +}