-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init: Add node code. Copy paste from EspNowNetwork
- Loading branch information
Showing
32 changed files
with
2,071 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BreakBeforeBraces: Attach | ||
ColumnLimit: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Clang Format CI | ||
on: [workflow_call, push] | ||
jobs: | ||
formatting-check: | ||
name: Formatting Check | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
path: | ||
- 'src' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run clang-format style check for C/C++/Protobuf programs. | ||
uses: jidicula/clang-format-action@v4.11.0 | ||
with: | ||
clang-format-version: '13' | ||
check-path: ${{ matrix.path }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Push EspNowNetworkNode to Espressif Component Service | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build_examples_for_verification: | ||
uses: ./.github/workflows/espidf.yaml | ||
with: | ||
target_path: "examples/espidf" | ||
|
||
upload_components: | ||
runs-on: ubuntu-latest | ||
needs: [build_examples_for_verification] | ||
steps: | ||
- uses: actions/checkout@v4.1.1 | ||
|
||
- name: Remove arduino examples and library related files | ||
run: rm -rf examples/arduino library.json library.properties | ||
|
||
- name: Remove github actions | ||
run: rm -rf .github | ||
|
||
- name: Upload EspNowNetworkNode to component registry | ||
uses: espressif/upload-components-ci-action/@v1 | ||
with: | ||
name: "EspNowNetworkNode" | ||
namespace: "johboh" | ||
api_token: ${{ secrets.ESP_IDF_COMPONENT_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: ESP-IDF CI | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target_path: | ||
type: string | ||
description: 'Path value to select a specific target in the matrix' | ||
required: true | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
version: | ||
- name: v44_build | ||
version_number: release-v4.4 | ||
target: esp32c3 | ||
- name: v51_build | ||
version_number: release-v5.1 | ||
target: esp32c6 | ||
- name: v52_build | ||
version_number: release-v5.2 | ||
target: esp32c6 | ||
- name: v53_build | ||
version_number: release-v5.3 | ||
target: esp32c6 | ||
path: | ||
- name: examples/espidf | ||
|
||
steps: | ||
- if: github.event_name == 'workflow_call' && matrix.path.name != inputs.target_path | ||
run: exit 0 | ||
|
||
- uses: actions/checkout@v4.1.1 | ||
|
||
- name: ESP-IDF Build | ||
uses: espressif/esp-idf-ci-action@v1 | ||
with: | ||
esp_idf_version: ${{ matrix.version.version_number }} | ||
target: ${{ matrix.version.target }} | ||
path: ${{ matrix.path.name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: PlatformIO CI | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target_path: | ||
type: string | ||
description: 'Path value to select a specific target in the matrix' | ||
required: true | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
target: | ||
- path: examples/arduino | ||
library: library.json | ||
remove: "" | ||
extra_dependencies: "" | ||
|
||
steps: | ||
- if: github.event_name == 'workflow_call' && matrix.target.path != inputs.target_path | ||
run: exit 0 | ||
|
||
- uses: actions/checkout@v4.1.1 | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/pip | ||
~/.platformio/.cache | ||
key: ${{ runner.os }}-pio | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install PlatformIO Core | ||
run: pip install --upgrade platformio | ||
|
||
- name: Remove files | ||
run: rm -rf ${{ matrix.target.remove }} | ||
if: ${{ matrix.target.remove }} | ||
|
||
- name: Copy library.json to root (if not src is also in root) | ||
run: mv ${{ matrix.target.library }} ./ || true | ||
if: ${{ matrix.target.library != './library.json' }} | ||
|
||
- name: Build PlatformIO targets | ||
run: ${{ env.PLATFORMIO_CI_BASE_CMD }} --project-option="lib_deps=${{ matrix.target.extra_dependencies }}" | ||
env: | ||
PLATFORMIO_CI_BASE_CMD: pio ci --lib="." --board=lolin_c3_mini --project-option="build_unflags=-std=gnu++11" --project-option="build_flags=-std=gnu++17" --project-option="platform=espressif32@6.4.0" --project-option="lib_ldf_mode=deep" | ||
PLATFORMIO_CI_SRC: ${{ matrix.target.path }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Push EspNowNetworkNode to PlatformIO registry | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build_examples_for_verification: | ||
uses: ./.github/workflows/platformio.yaml | ||
with: | ||
target_path: "examples/arduino" | ||
|
||
upload_library: | ||
runs-on: ubuntu-latest | ||
needs: [build_examples_for_verification] | ||
steps: | ||
- uses: actions/checkout@v4.1.1 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: ESP IDF CMake stuff | ||
run: rm -rf CMakeLists.txt idf_component.yml | ||
|
||
- name: Install PlatformIO Core | ||
run: pip install --upgrade platformio | ||
|
||
- name: Publish PlatformIO library | ||
run: pio pkg publish --owner johboh --no-notify --no-interactive | ||
env: | ||
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: PR verification | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
jobs: | ||
build_espidf_examples_for_verification: | ||
uses: ./.github/workflows/espidf.yaml | ||
|
||
build_platformio_examples_for_verification: | ||
uses: ./.github/workflows/platformio.yaml | ||
|
||
formatting_check: | ||
uses: ./.github/workflows/clang-format.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
/.idea | ||
/.build | ||
/.pio | ||
/out | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FILE(GLOB_RECURSE sources "./src/impl/*.*") | ||
|
||
if(IDF_VERSION_MAJOR GREATER_EQUAL 5) | ||
set(required_components mbedtls esp_wifi esp_http_client esp_partition esp-tls nvs_flash bootloader_support app_update) | ||
else() | ||
set(required_components mbedtls esp_wifi esp_http_client esp-tls nvs_flash bootloader_support app_update) | ||
endif() | ||
|
||
idf_component_register(COMPONENT_NAME "esp_now_network_node" | ||
SRCS ${sources} | ||
INCLUDE_DIRS "./src/" | ||
REQUIRES ${required_components}) | ||
|
||
|
||
if(IDF_VERSION_MAJOR LESS 5) # 5+ compiles with c++23. | ||
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++17) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <Arduino.h> | ||
#include <EspNowCrypt.h> | ||
#include <EspNowNode.h> | ||
#include <EspNowPreferences.h> | ||
#include <esp_crt_bundle.h> | ||
|
||
#define SLEEP_TIME_US (1000LL * 1000LL * 60LL * 1LL) // 1 minute | ||
|
||
// Should be generated by build script. | ||
#define FIRMWARE_VERSION 90201 | ||
|
||
// These structs are the application messages shared across the host and node device. | ||
// Ideally these should live in a shared header file. | ||
#pragma pack(1) | ||
struct MyApplicationMessage { | ||
uint8_t id = 0x01; | ||
double temperature; | ||
}; | ||
#pragma pack(0) | ||
|
||
// Encyption key used for our own packet encryption (GCM). | ||
// We are not using the esp-now encryption due to the peer limitation. | ||
// The key should be the same for both the host and the node. | ||
const char esp_now_encryption_key[] = "0123456789ABCDEF"; // Must be exact 16 bytes long. \0 does not count. | ||
|
||
// Used to validate the integrity of the messages. | ||
// The secret should be the same for both the host and the node. | ||
const char esp_now_encryption_secret[] = "01234567"; // Must be exact 8 bytes long. \0 does not count. | ||
|
||
unsigned long _turn_of_led_at_ms = 0; | ||
|
||
// Callback for logging. Can be omitted. | ||
EspNowNode::OnLog _on_log = [](const std::string message, const esp_log_level_t log_level) { | ||
if (log_level == ESP_LOG_NONE) { | ||
return; // Weird flex, but ok | ||
} | ||
|
||
std::string level; | ||
switch (log_level) { | ||
case ESP_LOG_NONE: | ||
level = "none"; | ||
break; | ||
case ESP_LOG_ERROR: | ||
level = "error"; | ||
break; | ||
case ESP_LOG_WARN: | ||
level = "warning"; | ||
break; | ||
case ESP_LOG_INFO: | ||
level = "info"; | ||
break; | ||
case ESP_LOG_DEBUG: | ||
level = "debug"; | ||
break; | ||
case ESP_LOG_VERBOSE: | ||
level = "verbose"; | ||
break; | ||
default: | ||
level = "unknown"; | ||
break; | ||
} | ||
|
||
Serial.println(("EspNowNode (" + level + "): " + message).c_str()); | ||
}; | ||
|
||
// Status callback. Can be omitted. | ||
EspNowNode::OnStatus _on_status = [](EspNowNode::Status status) { | ||
switch (status) { | ||
case EspNowNode::Status::HOST_DISCOVERY_STARTED: | ||
break; | ||
case EspNowNode::Status::HOST_DISCOVERY_SUCCESSFUL: | ||
break; | ||
case EspNowNode::Status::HOST_DISCOVERY_FAILED: | ||
break; | ||
case EspNowNode::Status::INVALID_HOST: | ||
break; | ||
case EspNowNode::Status::FIRMWARE_UPDATE_STARTED: | ||
break; | ||
case EspNowNode::Status::FIRMWARE_UPDATE_SUCCESSFUL: | ||
break; | ||
case EspNowNode::Status::FIRMWARE_UPDATE_FAILED: | ||
break; | ||
case EspNowNode::Status::FIRMWARE_UPDATE_WIFI_SETUP_FAILED: | ||
break; | ||
} | ||
}; | ||
|
||
EspNowPreferences _esp_now_preferences; | ||
EspNowCrypt _esp_now_crypt(esp_now_encryption_key, esp_now_encryption_secret); | ||
EspNowNode _esp_now_node(_esp_now_crypt, _esp_now_preferences, FIRMWARE_VERSION, _on_status, _on_log, | ||
arduino_esp_crt_bundle_attach); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
_esp_now_preferences.initalizeNVS(); | ||
|
||
// Setup node, send message, and then go to sleep. | ||
if (_esp_now_node.setup()) { | ||
MyApplicationMessage message; | ||
message.temperature = 25.6; | ||
_esp_now_node.sendMessage(&message, sizeof(MyApplicationMessage)); | ||
} | ||
|
||
esp_deep_sleep(SLEEP_TIME_US); | ||
} | ||
|
||
void loop() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 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.5) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := example | ||
|
||
include $(IDF_PATH)/make/project.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FILE(GLOB_RECURSE app_sources *.*) | ||
|
||
idf_component_register( | ||
SRCS ${app_sources} | ||
INCLUDE_DIRS "." | ||
) | ||
|
||
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# | ||
# "main" pseudo-component makefile. | ||
# | ||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies: | ||
EspNowNetworkNode: | ||
path: ../../../. |
Oops, something went wrong.