diff --git a/HOWTO-FLASH.md b/HOWTO-FLASH.md new file mode 100644 index 0000000..5a7a181 --- /dev/null +++ b/HOWTO-FLASH.md @@ -0,0 +1,281 @@ +# How to Flash ESPSomfy-RTS to a XIAO ESP32-C6 + +A step-by-step guide to flashing the ESPSomfy-RTS firmware to a Seeed Studio XIAO ESP32-C6 for controlling Somfy RTS motorized blinds and shades. + +## What is ESPSomfy-RTS? + +ESPSomfy-RTS is an open-source project that turns an ESP32 with a CC1101 radio transceiver into a controller for Somfy RTS blinds and shades. It provides: + +- Web interface for controlling up to 32 shades and 16 groups +- MQTT integration for home automation +- Home Assistant integration via HACS +- Support for RTS, RTW, and RTV protocols on 433MHz + +This guide uses a fork specifically optimized for the ESP32-C6 chip. + +## Hardware Requirements + +### Components + +| Component | Description | +|-----------|-------------| +| **XIAO ESP32-C6** | Seeed Studio XIAO ESP32-C6 development board | +| **CC1101 Module** | 433MHz radio transceiver module | +| **Jumper Wires** | Dupont wires for connections | +| **USB-C Cable** | For programming and power | + +### Wiring: XIAO ESP32-C6 to CC1101 + +The firmware uses these default pin mappings for the XIAO ESP32-C6: + +| CC1101 Pin | XIAO ESP32-C6 Pin | Function | +|------------|-------------------|----------| +| VCC | 3V3 | Power (3.3V) | +| GND | GND | Ground | +| MOSI | D10 (GPIO18) | SPI Data Out | +| MISO | D9 (GPIO20) | SPI Data In | +| SCK | D8 (GPIO19) | SPI Clock | +| CSN | D2 (GPIO2) | Chip Select | +| GDO0 | D3 (GPIO17) | TX Data | +| GDO2 | D6 (GPIO16) | RX Data | + +> **Note**: These pins can be reconfigured via the web interface after flashing. + +## Software Requirements + +- **macOS, Linux, or Windows** with USB drivers +- **PlatformIO** (we'll install it below) +- **Python 3.8+** with `uv` or `pip` + +## Step-by-Step Flashing Guide + +### Step 1: Clone the Repository + +```bash +git clone https://github.com/your-username/ESPSomfy-RTS.git +cd ESPSomfy-RTS +``` + +### Step 2: Install PlatformIO + +Using `uv` (recommended): +```bash +uv tool install platformio +``` + +Or using `pip`: +```bash +pip install platformio +``` + +Or using `pipx`: +```bash +pipx install platformio +``` + +Verify installation: +```bash +pio --version +``` + +### Step 3: Connect the XIAO ESP32-C6 + +1. Connect the XIAO ESP32-C6 to your computer via USB-C +2. The device should appear as a serial port: + - **macOS**: `/dev/cu.usbmodem*` + - **Linux**: `/dev/ttyACM0` or `/dev/ttyUSB0` + - **Windows**: `COM3` (or similar) + +Verify the connection: +```bash +# macOS/Linux +ls /dev/cu.usb* /dev/tty.usb* 2>/dev/null + +# Or use PlatformIO +pio device list +``` + +### Step 4: Build the Firmware + +```bash +pio run +``` + +This will: +- Download the ESP32-C6 toolchain +- Install required libraries (ArduinoJson, WebSockets, CC1101 driver, etc.) +- Compile the firmware + +Expected output: +``` +RAM: [=== ] 26.3% (used 86228 bytes from 327680 bytes) +Flash: [========= ] 88.8% (used 1396240 bytes from 1572864 bytes) +========================= [SUCCESS] Took XX.XX seconds ========================= +``` + +### Step 5: Upload the Firmware + +```bash +pio run -t upload +``` + +PlatformIO will automatically detect the serial port and flash the firmware. + +Expected output: +``` +Uploading .pio/build/debug/firmware.bin +... +Writing at 0x00010000... (100 %) +Wrote 1505136 bytes (824256 compressed) at 0x00010000 in 4.7 seconds +... +========================= [SUCCESS] Took XX.XX seconds ========================= +``` + +### Step 6: Upload the Filesystem + +The web interface files are stored in a LittleFS partition. Upload them with: + +```bash +pio run -t uploadfs +``` + +Expected output: +``` +Building FS image from 'data' directory to .pio/build/debug/littlefs.bin +/appversion +/icon.png +/index.html +... +Wrote 983040 bytes (96657 compressed) at 0x00310000 in 1.4 seconds +========================= [SUCCESS] Took XX.XX seconds ========================= +``` + +### Step 7: Verify the Device + +Monitor the serial output to confirm the device is running: + +```bash +pio device monitor +``` + +Or using `screen`: +```bash +screen /dev/cu.usbmodem2101 115200 +``` + +Press `Ctrl+]` then `q` to exit screen, or `Ctrl+C` to exit PlatformIO monitor. + +## First Boot Configuration + +1. **Connect to the WiFi AP**: On first boot, the device creates a WiFi access point named `ESPSomfy-RTS` + +2. **Open the Configuration Portal**: Connect to the AP and navigate to `http://192.168.4.1` + +3. **Configure WiFi**: Enter your home WiFi credentials + +4. **Access the Web Interface**: After connecting to your network, find the device's IP address (check your router or use mDNS: `http://espsomfy-rts.local`) + +## Build Environments + +The project includes multiple build configurations: + +| Environment | Command | Description | +|-------------|---------|-------------| +| `debug` | `pio run` | Debug build with logging (default) | +| `release` | `pio run -e release` | Optimized release build | +| `debugSSDP` | `pio run -e debugSSDP` | Debug with SSDP discovery enabled | +| `releaseSSDP` | `pio run -e releaseSSDP` | Release with SSDP discovery enabled | + +For production use, consider the release build: +```bash +pio run -e release -t upload +pio run -e release -t uploadfs +``` + +## Partition Layout + +The firmware uses a custom partition scheme optimized for ESP32-C6: + +| Partition | Type | Size | Purpose | +|-----------|------|------|---------| +| nvs | data | 20KB | Non-volatile storage | +| otadata | data | 8KB | OTA update metadata | +| app0 | app | 1.5MB | Main application | +| app1 | app | 1.5MB | OTA update slot | +| spiffs | data | 960KB | LittleFS filesystem | + +This layout supports Over-The-Air (OTA) updates while maximizing space for the web interface. + +## Troubleshooting + +### Device not detected + +1. Try a different USB cable (some are charge-only) +2. Check if the USB port provides enough power +3. On macOS, check System Information > USB +4. Try pressing the BOOT button while connecting + +### Upload fails with timeout + +1. Hold the **BOOT** button on the XIAO +2. Press and release the **RESET** button +3. Release the **BOOT** button +4. Run the upload command immediately + +### Build errors + +```bash +# Clean and rebuild +pio run -t clean +pio run +``` + +### Serial monitor shows garbage + +Verify the baud rate is set to `115200`: +```bash +pio device monitor --baud 115200 +``` + +## Useful Commands Reference + +```bash +# Build firmware +pio run + +# Upload firmware +pio run -t upload + +# Upload filesystem +pio run -t uploadfs + +# Monitor serial output +pio device monitor + +# Clean build files +pio run -t clean + +# Build specific environment +pio run -e release + +# List connected devices +pio device list + +# Full rebuild and upload +pio run -t clean && pio run -t upload && pio run -t uploadfs +``` + +## Resources + +- [ESPSomfy-RTS Wiki](https://github.com/rstrouse/ESPSomfy-RTS/wiki) - Original project documentation +- [Home Assistant Integration](https://github.com/rstrouse/ESPSomfy-RTS-HA) - HACS integration +- [XIAO ESP32-C6 Pinout](https://wiki.seeedstudio.com/xiao_esp32c6_getting_started/) - Seeed Studio documentation +- [PlatformIO Documentation](https://docs.platformio.org/) - Build system docs + +## License + +This project is open source. See the repository for license details. + +--- + +*Last updated: January 2025* diff --git a/flash.sh b/flash.sh new file mode 100755 index 0000000..02445d7 --- /dev/null +++ b/flash.sh @@ -0,0 +1,245 @@ +#!/bin/bash +# +# ESPSomfy-RTS Flash Script +# Automates flashing firmware to XIAO ESP32-C6 devices +# + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Default values +ENV="debug" +SKIP_BUILD=false +SKIP_FS=false +MONITOR=false +FORCE=false +PORT="" + +# Print colored output +info() { echo -e "${BLUE}[INFO]${NC} $1"; } +success() { echo -e "${GREEN}[OK]${NC} $1"; } +warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } +error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } + +# Show usage +usage() { + cat << EOF +Usage: $(basename "$0") [OPTIONS] + +Flash ESPSomfy-RTS firmware to a XIAO ESP32-C6 device. + +OPTIONS: + -e, --env ENV Build environment: debug, release, debugSSDP, releaseSSDP + (default: debug) + -p, --port PORT Serial port (auto-detected if not specified) + -s, --skip-build Skip building, use existing firmware + -f, --skip-fs Skip filesystem upload + -m, --monitor Open serial monitor after flashing + -y, --yes Skip confirmation prompt + -h, --help Show this help message + +EXAMPLES: + $(basename "$0") # Flash with defaults (debug build) + $(basename "$0") -e release # Flash release build + $(basename "$0") -e release -m # Flash release and monitor + $(basename "$0") -s -f # Quick reflash (skip build & fs) + $(basename "$0") -p /dev/cu.usbmodem2101 # Specify port + +EOF + exit 0 +} + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + -e|--env) + ENV="$2" + shift 2 + ;; + -p|--port) + PORT="$2" + shift 2 + ;; + -s|--skip-build) + SKIP_BUILD=true + shift + ;; + -f|--skip-fs) + SKIP_FS=true + shift + ;; + -m|--monitor) + MONITOR=true + shift + ;; + -y|--yes) + FORCE=true + shift + ;; + -h|--help) + usage + ;; + *) + error "Unknown option: $1\nUse --help for usage." + ;; + esac +done + +# Validate environment +case $ENV in + debug|release|debugSSDP|releaseSSDP) + ;; + *) + error "Invalid environment: $ENV\nValid options: debug, release, debugSSDP, releaseSSDP" + ;; +esac + +echo "" +echo -e "${GREEN}╔═══════════════════════════════════════════════════════════╗${NC}" +echo -e "${GREEN}║ ESPSomfy-RTS Flash Script ║${NC}" +echo -e "${GREEN}║ Target: XIAO ESP32-C6 ║${NC}" +echo -e "${GREEN}╚═══════════════════════════════════════════════════════════╝${NC}" +echo "" + +# Check if PlatformIO is installed +info "Checking PlatformIO installation..." +if ! command -v pio &> /dev/null; then + error "PlatformIO not found. Install with: uv tool install platformio" +fi +success "PlatformIO found: $(pio --version)" + +# Check for device +info "Detecting device..." + +if [[ -n "$PORT" ]]; then + if [[ ! -e "$PORT" ]]; then + error "Specified port not found: $PORT" + fi + info "Using specified port: $PORT" +else + # Auto-detect on macOS/Linux + if [[ "$OSTYPE" == "darwin"* ]]; then + PORTS=($(ls /dev/cu.usbmodem* 2>/dev/null || true)) + else + PORTS=($(ls /dev/ttyACM* /dev/ttyUSB* 2>/dev/null || true)) + fi + + if [[ ${#PORTS[@]} -eq 0 ]]; then + error "No device detected. Please connect your XIAO ESP32-C6 and try again." + elif [[ ${#PORTS[@]} -gt 1 ]]; then + warn "Multiple devices detected:" + for i in "${!PORTS[@]}"; do + echo " [$i] ${PORTS[$i]}" + done + echo "" + read -p "Select device [0-$((${#PORTS[@]}-1))]: " selection + if [[ ! "$selection" =~ ^[0-9]+$ ]] || [[ "$selection" -ge ${#PORTS[@]} ]]; then + error "Invalid selection" + fi + PORT="${PORTS[$selection]}" + else + PORT="${PORTS[0]}" + fi + success "Device detected: $PORT" +fi + +CHIP_TYPE="pending" + +# Confirmation prompt +if [[ "$FORCE" == false ]]; then + echo "" + echo -e "${YELLOW}Ready to flash:${NC}" + echo " Port: $PORT" + echo " Chip: ${CHIP_TYPE:-unknown}" + echo " Environment: $ENV" + echo "" + read -p "Proceed with flashing? [Y/n]: " confirm + if [[ "$confirm" =~ ^[Nn]$ ]]; then + error "Aborted by user" + fi +fi + +# Build firmware +if [[ "$SKIP_BUILD" == false ]]; then + echo "" + info "Building firmware (environment: $ENV)..." + echo "─────────────────────────────────────────────────────────────" + + if pio run -e "$ENV"; then + success "Build completed successfully" + else + error "Build failed" + fi +else + warn "Skipping build (using existing firmware)" +fi + +# Upload firmware +echo "" +info "Uploading firmware to $PORT..." +echo "─────────────────────────────────────────────────────────────" + +UPLOAD_LOG=$(mktemp) +if pio run -e "$ENV" -t upload --upload-port "$PORT" 2>&1 | tee "$UPLOAD_LOG"; then + if grep -q "Chip is ESP32-C6" "$UPLOAD_LOG"; then + CHIP_TYPE="ESP32-C6" + MAC=$(grep -oE "MAC: [0-9a-f:]+" "$UPLOAD_LOG" | head -1 || true) + success "Firmware uploaded successfully" + success "Verified chip: $CHIP_TYPE ${MAC:+($MAC)}" + elif grep -q "Chip is ESP32-C3" "$UPLOAD_LOG"; then + rm -f "$UPLOAD_LOG" + error "Wrong chip: ESP32-C3 detected. This firmware is for ESP32-C6 only." + elif grep -q "Chip is ESP32" "$UPLOAD_LOG"; then + rm -f "$UPLOAD_LOG" + error "Wrong chip detected. This firmware is for ESP32-C6 only." + else + success "Firmware uploaded successfully" + fi +else + rm -f "$UPLOAD_LOG" + error "Firmware upload failed" +fi +rm -f "$UPLOAD_LOG" + +# Upload filesystem +if [[ "$SKIP_FS" == false ]]; then + echo "" + info "Uploading filesystem (LittleFS)..." + echo "─────────────────────────────────────────────────────────────" + + if pio run -e "$ENV" -t uploadfs --upload-port "$PORT"; then + success "Filesystem uploaded successfully" + else + error "Filesystem upload failed" + fi +else + warn "Skipping filesystem upload" +fi + +# Summary +echo "" +echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}" +echo -e "${GREEN} Flash completed successfully!${NC}" +echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}" +echo "" +echo " Environment: $ENV" +echo " Port: $PORT" +echo " Firmware: $(ls -lh .pio/build/$ENV/firmware.bin 2>/dev/null | awk '{print $5}' || echo 'N/A')" +echo "" +echo " Next steps:" +echo " 1. Device will create WiFi AP 'ESPSomfy-RTS' on first boot" +echo " 2. Connect to AP and configure at http://192.168.4.1" +echo "" + +# Monitor if requested +if [[ "$MONITOR" == true ]]; then + info "Opening serial monitor (Ctrl+C to exit)..." + echo "─────────────────────────────────────────────────────────────" + pio device monitor --port "$PORT" --baud 115200 +fi