Initial tag code

This commit is contained in:
Kostas Drakontidis
2026-05-07 00:06:24 +03:00
parent a429da9e02
commit 81af8cd576
7 changed files with 214 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
CompileFlags:
Remove: [-f*, -m*]
@@ -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"]
@@ -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"]
}
+78
View File
@@ -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
+8
View File
@@ -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)
+2
View File
@@ -0,0 +1,2 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS ".")
+92
View File
@@ -0,0 +1,92 @@
#include <stdio.h>
#include <string.h>
#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(&params, 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,
&params,
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);
}