esp32-serial-commands by h1d/agent-skills-esp32
npx skills add https://github.com/h1d/agent-skills-esp32 --skill esp32-serial-commands直接向串口发送命令以模拟按钮按压和用户操作。通过 USB 串口工作。
#include "esp_log.h"
#include <string.h>
static const char* TAG = "SerialCmd";
void serial_command_task(void* arg) {
char buf[64];
int idx = 0;
while (1) {
int c = getchar();
if (c == EOF) {
vTaskDelay(pdMS_TO_TICKS(10));
continue;
}
if (c == '\n' || c == '\r') {
buf[idx] = '\0';
if (idx > 0) {
ESP_LOGI(TAG, "Command: %s", buf);
if (strcmp(buf, "PRESS") == 0) {
button_callback();
} else if (strncmp(buf, "SCREEN:", 7) == 0) {
int screen = atoi(buf + 7);
go_to_screen(screen);
}
}
idx = 0;
} else if (idx < sizeof(buf) - 1) {
buf[idx++] = c;
}
}
}
// In app_main():
// xTaskCreate(serial_command_task, "serial_cmd", 2048, NULL, 5, NULL);
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
Serial.printf("Command: %s\n", cmd.c_str());
if (cmd == "PRESS") {
button_callback();
} else if (cmd.startsWith("SCREEN:")) {
int screen = cmd.substring(7).toInt();
go_to_screen(screen);
} else if (cmd == "STATUS") {
Serial.println("OK");
}
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# Find serial port
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | head -1)
# Send a command
echo "PRESS" > "$PORT"
# Simple command
echo "PRESS" > "$PORT"
# Command with parameter
echo "PRESS:3" > "$PORT" # Press 3 times
echo "SCREEN:2" > "$PORT" # Go to screen 2
echo "MODE:debug" > "$PORT" # Set debug mode
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
for i in {1..100}; do
echo "PRESS" > "$PORT"
echo "Sent press $i"
sleep 2
done
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
END=$(($(date +%s) + 3600)) # 1 hour
count=0
while [ $(date +%s) -lt $END ]; do
count=$((count + 1))
echo "PRESS" > "$PORT"
echo "[$(date +%H:%M:%S)] Press $count"
sleep 30
done
echo "Total: $count presses"
终端 1 - 监控日志:
tail -f /tmp/device.log
终端 2 - 发送命令:
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
echo "PRESS" > "$PORT"
每周安装量
75
代码仓库
GitHub 星标数
7
首次出现
2026年1月29日
安全审计
安装于
opencode65
gemini-cli60
codex60
cursor56
github-copilot54
amp51
Send commands directly to the serial port to emulate button presses and user actions. Works over USB serial.
#include "esp_log.h"
#include <string.h>
static const char* TAG = "SerialCmd";
void serial_command_task(void* arg) {
char buf[64];
int idx = 0;
while (1) {
int c = getchar();
if (c == EOF) {
vTaskDelay(pdMS_TO_TICKS(10));
continue;
}
if (c == '\n' || c == '\r') {
buf[idx] = '\0';
if (idx > 0) {
ESP_LOGI(TAG, "Command: %s", buf);
if (strcmp(buf, "PRESS") == 0) {
button_callback();
} else if (strncmp(buf, "SCREEN:", 7) == 0) {
int screen = atoi(buf + 7);
go_to_screen(screen);
}
}
idx = 0;
} else if (idx < sizeof(buf) - 1) {
buf[idx++] = c;
}
}
}
// In app_main():
// xTaskCreate(serial_command_task, "serial_cmd", 2048, NULL, 5, NULL);
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
Serial.printf("Command: %s\n", cmd.c_str());
if (cmd == "PRESS") {
button_callback();
} else if (cmd.startsWith("SCREEN:")) {
int screen = cmd.substring(7).toInt();
go_to_screen(screen);
} else if (cmd == "STATUS") {
Serial.println("OK");
}
}
}
# Find serial port
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | head -1)
# Send a command
echo "PRESS" > "$PORT"
# Simple command
echo "PRESS" > "$PORT"
# Command with parameter
echo "PRESS:3" > "$PORT" # Press 3 times
echo "SCREEN:2" > "$PORT" # Go to screen 2
echo "MODE:debug" > "$PORT" # Set debug mode
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
for i in {1..100}; do
echo "PRESS" > "$PORT"
echo "Sent press $i"
sleep 2
done
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
END=$(($(date +%s) + 3600)) # 1 hour
count=0
while [ $(date +%s) -lt $END ]; do
count=$((count + 1))
echo "PRESS" > "$PORT"
echo "[$(date +%H:%M:%S)] Press $count"
sleep 30
done
echo "Total: $count presses"
Terminal 1 - Monitor logs:
tail -f /tmp/device.log
Terminal 2 - Send commands:
PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
echo "PRESS" > "$PORT"
Weekly Installs
75
Repository
GitHub Stars
7
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode65
gemini-cli60
codex60
cursor56
github-copilot54
amp51
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
44,900 周安装