From 71d6a233a5693dcee50a30fbad65ce7e59fd62be Mon Sep 17 00:00:00 2001 From: HTotoo Date: Tue, 9 Sep 2025 13:09:05 +0200 Subject: [PATCH] Initial test --- .clangd | 2 ++ .gitignore | 7 ++++++ CMakeLists.txt | 6 +++++ main/CMakeLists.txt | 3 +++ main/idf_component.yml | 4 +++ main/main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ sdkconfig.defaults | 1 + 7 files changed, 80 insertions(+) create mode 100644 .clangd create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 main/CMakeLists.txt create mode 100644 main/idf_component.yml create mode 100644 main/main.cpp create mode 100644 sdkconfig.defaults diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..7901c38 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Remove: [-f*, -m*] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..092e838 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.devcontainer +.vscode +build +sdkconfig +sdkconfig.ci +managed_components +dependencies.lock \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e6954b1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following 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(DarkMesh) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt new file mode 100644 index 0000000..8516119 --- /dev/null +++ b/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "main.cpp" + PRIV_REQUIRES spi_flash + INCLUDE_DIRS "") diff --git a/main/idf_component.yml b/main/idf_component.yml new file mode 100644 index 0000000..8b4b2a5 --- /dev/null +++ b/main/idf_component.yml @@ -0,0 +1,4 @@ +dependencies: + EspMeshtasticCompact: + git: https://github.com/htotoo/EspMeshtasticCompact + \ No newline at end of file diff --git a/main/main.cpp b/main/main.cpp new file mode 100644 index 0000000..201dd32 --- /dev/null +++ b/main/main.cpp @@ -0,0 +1,57 @@ + +#include +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" + +#include "esp_random.h" +#include "MeshtasticCompact.hpp" + +static const char* TAG = "DarkMesh"; + +extern "C" { +void app_main(); +} + +Radio_PINS radio_pins = {9, 11, 10, 8, 14, 12, 13}; // Default radio pins for Heltec WSL V3. +LoraConfig lora_config = { + .frequency = 433.125, // default frequency + .bandwidth = 250.0, + .spreading_factor = 11, + .coding_rate = 5, + .sync_word = 0x2b, + .preamble_length = 16, + .output_power = 22, + .tcxo_voltage = 1.8, + .use_regulator_ldo = false, +}; // default LoRa configuration for EU LONGFAST 433 +MeshtasticCompact meshtasticCompact; + +void app_main(void) { + ESP_LOGI(TAG, "Radio initializing..."); + meshtasticCompact.RadioInit(RadioType::SX1262, radio_pins, lora_config); + ESP_LOGI(TAG, "Radio initialized."); + meshtasticCompact.setAutoFullNode(false); // we don't want to be a full node + meshtasticCompact.setSendHopLimit(7); // max hop limit + meshtasticCompact.setStealthMode(true); // stealth mode, we don't + meshtasticCompact.setSendEnabled(true); // we want to send packets + std::string short_name = "DM"; // short name + std::string long_name = "DarkMesh"; // long name + MeshtasticCompactHelpers::NodeInfoBuilder(meshtasticCompact.getMyNodeInfo(), esp_random(), short_name, long_name, esp_random() % 105); // random nodeinfo + MeshtasticCompactHelpers::PositionBuilder(meshtasticCompact.my_position, + -180.0 + static_cast(esp_random()) / UINT32_MAX * 360.0, // random longitude [-180, 180] + -90.0 + static_cast(esp_random()) / UINT32_MAX * 180.0, // random latitude [-90, 90] + esp_random() % 1000 // altitude + ); + uint32_t timer = 0; // 0.1 second timer + while (1) { + timer++; + if (timer % 600000 == 0) { + meshtasticCompact.SendMyNodeInfo(); + meshtasticCompact.SendMyPosition(); + } + vTaskDelay(pdMS_TO_TICKS(100)); // wait 100 milliseconds + } +} diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..939c890 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1 @@ +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000 \ No newline at end of file