Refactor SerialCommand to support Stream interface and improve command handling

- Added readSerial(Stream &stream) method to allow reading from any Stream-compatible transport.
- Introduced readChar(char inChar) method for processing individual characters.
- Updated command matching logic to enhance debugging output.
- Improved buffer handling and command execution flow.

Enhance platformio.ini for better compatibility and added libraries

- Added NimBLE-Arduino and WebSockets libraries for BLE and WiFi support.
- Updated upload and monitor ports for better compatibility with macOS.

Integrate WiFi and BLE protocol interfaces

- Implemented startWebInterface() to initialize WiFi protocol alongside existing web server.
- Added BLE support with a new EggBot BLE Serial Protocol for command handling over BLE.
- Created WebSocket server for WiFi communication, maintaining compatibility with existing command protocols.

Refactor command handling in Functions.cpp

- Replaced direct Serial.print calls with protocolWrite for consistent output handling.
- Updated command registration to use a lambda function for better readability and maintainability.

Add documentation for EggBot protocols

- Created separate markdown files for BLE, WiFi, and Serial protocols detailing command structures and usage.
- Provided examples of command transactions for better developer guidance.

Implement BLE and WiFi protocol handling in respective source files

- Developed BLE_Interface.cpp for managing BLE connections and data transmission.
- Created WiFi_Protocol.cpp for handling WebSocket communication and data reception.
This commit is contained in:
2026-02-24 22:00:26 +01:00
parent 3487d7c263
commit a1ffcb08ca
15 changed files with 1115 additions and 83 deletions

View File

@@ -0,0 +1,45 @@
# EggBot WiFi Serial Protocol
## Scope
This transport exposes the same EggBot command protocol as serial, but over WiFi/WebSocket.
- Protocol commands and responses are unchanged.
- Framing is unchanged (`\r` command terminator, `\r\n` response lines).
## Transport Profile
- Protocol endpoint: `ws://<eggs-esp32-ip>:1337/`
- WebSocket message type: text or binary frames accepted
- Payload: ASCII command bytes
## Data Model
- Host writes command bytes to the WebSocket.
- Firmware parses incoming bytes with the same EggBot parser used for USB serial and BLE.
- Firmware sends responses as WebSocket text messages.
- Hosts must treat inbound data as a stream and parse lines by `\r\n`.
## Compatibility Rules
- A WiFi client must send commands exactly as serial hosts do.
- Each command must end with `\r`.
- Data-returning commands (`QP`, `QB`, `QN`, `QL`) return a value line before final status (`OK\r\n`).
- Unknown/invalid command format returns `unknown CMD\r\n`.
## Example WiFi Transactions
Version query:
- Send: `v\r`
- Receive: `EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6a\r\n`
Move command:
- Send: `SM,100,0,200\r`
- Receive: `OK\r\n`
Query layer:
- Send: `QL\r`
- Receive: `<layer>\r\n`
- Receive: `OK\r\n`
## Operational Notes
- The WiFi protocol endpoint is started only when ESP32 station WiFi is connected.
- Incoming WiFi bytes are queued and parsed in the main loop.
- If the WiFi RX queue overruns, excess bytes are dropped and a log entry is generated.
- WiFi transport is single active client: first connected sender is accepted until disconnect.
- USB serial, BLE, and WiFi can coexist; responses are routed to the transport that received each command.