A lightweight, memory-efficient command executor for Arduino, ESP8266, and ESP32.
It allows you to map string-based commands (like "LED_ON", "GET_TEMP") to specific C++ functions using a simple callback system. Perfect for building Serial consoles, MQTT control interfaces, or WebSocket-based IoT devices.
- Low Memory Footprint: Uses standard C-strings (
const char*) and function pointers. No heavystd::stringorStringobjects. - Case-Insensitive: Commands are matched regardless of case (e.g.,
Help==HELP). - Decoupled Architecture: Easily switch between Serial, MQTT, or HTTP by providing different result callbacks.
- Cross-Platform: Works on AVR (Uno, Nano, Mega) and 32-bit controllers (ESP32, ESP8266).
-
Download: Click the green Code button on GitHub and select Download ZIP.
-
Install: * Open Arduino IDE. * Go to Sketch -> Include Library (Скетч -> Подключить библиотеку). * Select Add .ZIP Library... (Добавить .ZIP библиотеку...). * Choose the downloaded .zip file.
-
Verify: Now you can find the library under Sketch -> Include Library -> Contributed libraries.
If you are using PlatformIO, add the library to your platformio.ini:
lib_deps =
https://github.com/javavirys/UCommandExecutor.gitcd ~/Documents/Arduino/libraries
git clone [https://github.com/javavirys/UCommandExecutor.git](https://github.com/javavirys/UCommandExecutor.git)#include <UCommandExecutor.h>
// 1. Define command functions
void cmdHello(const char* param, CommandResultCallback callback) {
if (callback) callback("HELLO", param, "Success: World!");
}
// 2. Map commands to functions
const UCommand myCommands[] = {
{"HELLO", cmdHello}
};
// 3. Initialize the executor
UCommandExecutor executor(myCommands, sizeof(myCommands) / sizeof(myCommands[0]));
// 4. Result handler
void onResult(const char* cmd, const char* param, const char* status) {
Serial.printf("[%s] Result: %s\n", cmd, status);
}
void setup() {
Serial.begin(115200);
// Execute a command
executor.execute("HELLO", "optional_data", onResult);
}
void loop() {}UCommand Structure
- const char* name: The string trigger for the command.
- CommandFunction function: Pointer to the function to execute.
UCommandExecutor Methods
-
UCommandExecutor(commands, count): Constructor.
-
execute(cmd, param, callback): Searches for cmd in the table and runs the associated function.
void execute(const char* cmd, const char* param, CommandResultCallback callback)
- cmd: The command name to look for (case-insensitive).
- param: A string parameter passed to the command function (can be a value, JSON, etc.).
- callback: The function that handles the execution result (use
nullptrif no response is needed).
# Push changes to main
git add .
git commit -m "Commit message"
git push origin main
# Tag a new release
git tag vX.X.X
git push origin vX.X.XCopyright 2026 javavirys.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Developed by javavirys (UDFSOFT).