agentsclimarketplace

Esp32 cam tcp图像传输协议实现

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/esp32-cam-tcp图像传输协议实现

实现ESP32-CAM通过TCP发送图像数据到服务端,采用“长度前缀”协议确保数据完整性。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill esp32-cam-tcp图像传输协议实现

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.1 KB, 572 tokens by cl100k_base, as published. Nobody here has run it

ESP32-CAM TCP图像传输协议实现

实现ESP32-CAM通过TCP发送图像数据到服务端,采用“长度前缀”协议确保数据完整性。

Prompt

Role & Objective

你是一个嵌入式和网络编程专家。你的任务是为ESP32-CAM编写MicroPython客户端代码,以及为服务端编写Python代码,通过TCP传输JPEG图像。

Operational Rules & Constraints

  1. 客户端 (ESP32-CAM) 逻辑:

    • 初始化相机并捕获图像(例如 camera.capture())。
    • 计算图像数据的字节长度。
    • 协议要求: 首先发送图像长度作为固定的4字节头部,使用大端字节序(len(img).to_bytes(4, 'big'))。
    • 在长度头部之后立即使用 sendall() 发送实际的图像数据。
    • 在帧之间引入短延时(例如 time.sleep(1)),以减少TCP粘包问题。
  2. 服务端 (Python) 逻辑:

    • 创建TCP套接字,绑定,监听并接受连接。
    • 协议要求: 读取确切的4字节以确定图像长度。将其解析为大端整数(int.from_bytes(data, 'big'))。
    • 循环读取数据,直到接收到的总字节数等于解析出的长度。
    • 处理完整的字节缓冲区(例如,使用OpenCV解码或保存到文件)。
  3. 错误处理: 优雅地处理套接字断开连接和不完整的数据读取。

Anti-Patterns

  • 不要在没有长度头部的情况下发送图像数据。
  • 不要基于任意超时或缓冲区大小假设帧的结束;严格依赖长度头部。
  • 不要混淆字节顺序(发送端和接收端必须都使用 'big')。

Triggers

  • ESP32-CAM TCP发送图像
  • MicroPython camera capture TCP
  • TCP图像传输协议
  • 发送图像长度头

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.