Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web serial config #13

Merged
merged 7 commits into from
Oct 30, 2023
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
Empty file modified build.sh
100644 → 100755
Empty file.
522 changes: 522 additions & 0 deletions code/.vscode/c_cpp_properties.json

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions code/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html

{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "/Users/mark/projects/nostr-zap-lamp/code/.pio/build/esp32dev/firmware.elf",
"projectEnvName": "esp32dev",
"toolchainBinDir": "/Users/mark/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
}
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/Users/mark/projects/nostr-zap-lamp/code/.pio/build/esp32dev/firmware.elf",
"projectEnvName": "esp32dev",
"toolchainBinDir": "/Users/mark/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "/Users/mark/projects/nostr-zap-lamp/code/.pio/build/esp32dev/firmware.elf",
"projectEnvName": "esp32dev",
"toolchainBinDir": "/Users/mark/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart",
"loadMode": "manual"
}
]
}
File renamed without changes
84 changes: 84 additions & 0 deletions nostrZapLamp/100_config.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
void configOverSerialPort() {
executeConfig();
}

void executeConfig() {

while (true) {
if (Serial.available() == 0) continue;
String data = Serial.readStringUntil('\n');
Serial.println("received: " + data);
KeyValue kv = extractKeyValue(data);
String commandName = kv.key;
if (commandName == "/config-done") {
Serial.println("/config-done");
return;
}
executeCommand(commandName, kv.value);
}
}

void executeCommand(String commandName, String commandData) {
Serial.println("executeCommand: " + commandName + " > " + commandData);
KeyValue kv = extractKeyValue(commandData);
String path = kv.key;
String data = kv.value;

if (commandName == "/file-remove") {
return removeFile(path);
}
if (commandName == "/file-append") {
return appendToFile(path, data);
}

if (commandName == "/file-read") {
Serial.println("prepare to read");
readFile(path);
Serial.println("readFile done");
return;
}

Serial.println("command unknown");
}

void removeFile(String path) {
Serial.println("removeFile: " + path);
SPIFFS.remove("/" + path);
}

void appendToFile(String path, String data) {
Serial.println("appendToFile: " + path);
File file = SPIFFS.open("/" + path, FILE_APPEND);
if (!file) {
file = SPIFFS.open("/" + path, FILE_WRITE);
}
if (file) {
file.println(data);
file.close();
}
}

void readFile(String path) {
Serial.println("readFile: " + path);
File file = SPIFFS.open("/" + path);
if (file) {
while (file.available()) {
String line = file.readStringUntil('\n');
Serial.println("/file-read " + line);
}
file.close();
}
Serial.println("");
Serial.println("/file-done");
}


KeyValue extractKeyValue(String s) {
int spacePos = s.indexOf(" ");
String key = s.substring(0, spacePos);
if (spacePos == -1) {
return {key, ""};
}
String value = s.substring(spacePos + 1, s.length());
return {key, value};
}
Loading
Loading