Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BasedOnStyle: LLVM
ColumnLimit: 100
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
AlignAfterOpenBracket: BlockIndent
UseTab: ForIndentation
IndentWidth: 4
TabWidth: 4
ContinuationIndentWidth: 4
AllowShortFunctionsOnASingleLine: None
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.{c,cc,cpp,h,hpp,ino}]
indent_style = tab
indent_size = tab
tab_width = 4
19 changes: 19 additions & 0 deletions .vscode/bin/clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -euo pipefail

if command -v clang-format >/dev/null 2>&1; then
exec clang-format "$@"
fi

_home_dir="${HOME:-}"
if [ -n "$_home_dir" ]; then
_candidate="$(ls -1d "$_home_dir"/.vscode/extensions/ms-vscode.cpptools-*-linux-x64/LLVM/bin/clang-format 2>/dev/null | tail -n 1 || true)"
if [ -n "$_candidate" ] && [ -x "$_candidate" ]; then
exec "$_candidate" "$@"
fi
fi

echo "clang-format executable not found." >&2
echo "Install clang-format system-wide or install/update ms-vscode.cpptools." >&2
exit 127
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"pioarduino.pioarduino-ide",
"xaver.clang-format"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"files.associations": {
"*.ino": "cpp"
},
"editor.defaultFormatter": "xaver.clang-format",
"C_Cpp.formatting": "Disabled",
"clang-format.style": "file",
"clang-format.executable": "${workspaceRoot}/.vscode/bin/clang-format",
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.formatOnSave": true
},
"[c]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.formatOnSave": true
},
"[arduino]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.formatOnSave": true
}
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Format Firmware Sources",
"type": "shell",
"command": "bash ${workspaceFolder}/scripts/format_cpp.sh",
"group": "build",
"problemMatcher": []
}
]
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ if (webPush.isInitialized()) {
## Tests
Host-side tests are disabled. Use the `examples/` sketches with PlatformIO or Arduino CLI.

## Formatting Baseline

This repository follows the firmware formatting baseline from `esptoolkit-template`:
- `.clang-format` is the source of truth for C/C++/INO layout.
- `.editorconfig` enforces tabs (`tab_width = 4`), LF endings, and final newline.
- Format all tracked firmware sources with `bash scripts/format_cpp.sh`.

## License
MIT — see [LICENSE.md](LICENSE.md).

Expand Down
103 changes: 54 additions & 49 deletions examples/basic_web_push/basic_web_push.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,61 @@ bool tornDown = false;
uint32_t teardownAtMs = 0;

void setup() {
Serial.begin(115200);
delay(200);

WebPushConfig cfg;
cfg.queueLength = 8;
cfg.queueMemory = WebPushQueueMemory::Psram;
cfg.worker.stackSizeBytes = 16 * 1024;
cfg.worker.priority = 3;
cfg.worker.name = "webpush";

webPush.init(
"notify@example.com",
"BAvapidPublicKeyBase64Url...",
"vapidPrivateKeyBase64Url...",
cfg);

Subscription sub;
sub.endpoint = "https://fcm.googleapis.com/fcm/send/...";
sub.p256dh = "BMEp256dhBase64Url...";
sub.auth = "authSecretBase64Url...";

PushMessage msg;
msg.sub = sub;
msg.payload = "{\"title\":\"Hello\",\"body\":\"ESP32\"}";

webPush.send(msg, [](WebPushResult result) {
if (!result.ok()) {
Serial.printf("[webpush] async failed: %s (status %d)\n",
result.message ? result.message : "unknown",
result.statusCode);
return;
}
Serial.printf("[webpush] async ok: %d\n", result.statusCode);
});

WebPushResult syncResult = webPush.send(msg);
if (!syncResult.ok()) {
Serial.printf("[webpush] sync failed: %s\n",
syncResult.message ? syncResult.message : "unknown");
} else {
Serial.printf("[webpush] sync ok: %d\n", syncResult.statusCode);
}

teardownAtMs = millis() + 5000;
Serial.begin(115200);
delay(200);

WebPushConfig cfg;
cfg.queueLength = 8;
cfg.queueMemory = WebPushQueueMemory::Psram;
cfg.worker.stackSizeBytes = 16 * 1024;
cfg.worker.priority = 3;
cfg.worker.name = "webpush";

webPush.init(
"notify@example.com",
"BAvapidPublicKeyBase64Url...",
"vapidPrivateKeyBase64Url...",
cfg
);

Subscription sub;
sub.endpoint = "https://fcm.googleapis.com/fcm/send/...";
sub.p256dh = "BMEp256dhBase64Url...";
sub.auth = "authSecretBase64Url...";

PushMessage msg;
msg.sub = sub;
msg.payload = "{\"title\":\"Hello\",\"body\":\"ESP32\"}";

webPush.send(msg, [](WebPushResult result) {
if (!result.ok()) {
Serial.printf(
"[webpush] async failed: %s (status %d)\n",
result.message ? result.message : "unknown",
result.statusCode
);
return;
}
Serial.printf("[webpush] async ok: %d\n", result.statusCode);
});

WebPushResult syncResult = webPush.send(msg);
if (!syncResult.ok()) {
Serial.printf(
"[webpush] sync failed: %s\n",
syncResult.message ? syncResult.message : "unknown"
);
} else {
Serial.printf("[webpush] sync ok: %d\n", syncResult.statusCode);
}

teardownAtMs = millis() + 5000;
}

void loop() {
if (!tornDown && webPush.isInitialized() && teardownAtMs != 0 && millis() >= teardownAtMs) {
webPush.deinit();
tornDown = true;
}
vTaskDelay(pdMS_TO_TICKS(1000));
if (!tornDown && webPush.isInitialized() && teardownAtMs != 0 && millis() >= teardownAtMs) {
webPush.deinit();
tornDown = true;
}
vTaskDelay(pdMS_TO_TICKS(1000));
}
24 changes: 24 additions & 0 deletions scripts/format_cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

_repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
_clang_format="${_repo_root}/.vscode/bin/clang-format"

if [ ! -x "${_clang_format}" ]; then
echo "clang-format wrapper not found: ${_clang_format}" >&2
exit 1
fi

mapfile -d '' _format_files < <(
git -C "${_repo_root}" ls-files -z -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' '*.ino'
)

if [ "${#_format_files[@]}" -eq 0 ]; then
echo "No tracked C/C++/INO files found to format."
exit 0
fi

"${_clang_format}" -i --style=file "${_format_files[@]}"

echo "Formatted ${#_format_files[@]} files."
Loading