{"id":48175421,"url":"https://github.com/trailcurrentoss/trailcurrentswitchback","last_synced_at":"2026-04-16T00:01:24.868Z","repository":{"id":343604667,"uuid":"1178384959","full_name":"trailcurrentoss/TrailCurrentSwitchback","owner":"trailcurrentoss","description":"A repository for the firmware and EDA for the TrailCurrentSwitchback module","archived":false,"fork":false,"pushed_at":"2026-04-15T13:19:20.000Z","size":1415,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-15T14:36:05.960Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trailcurrentoss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-11T01:13:02.000Z","updated_at":"2026-04-15T13:17:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/trailcurrentoss/TrailCurrentSwitchback","commit_stats":null,"previous_names":["trailcurrentoss/trailcurrentswitchback"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/trailcurrentoss/TrailCurrentSwitchback","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailcurrentoss%2FTrailCurrentSwitchback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailcurrentoss%2FTrailCurrentSwitchback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailcurrentoss%2FTrailCurrentSwitchback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailcurrentoss%2FTrailCurrentSwitchback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailcurrentoss","download_url":"https://codeload.github.com/trailcurrentoss/TrailCurrentSwitchback/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailcurrentoss%2FTrailCurrentSwitchback/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31865078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-04T17:37:06.179Z","updated_at":"2026-04-16T00:01:24.862Z","avatar_url":"https://github.com/trailcurrentoss.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrailCurrent Switchback\n\nCAN-controlled 8-channel relay module for the TrailCurrent ecosystem, built on the [Waveshare ESP32-S3-ETH-8DI-8RO-C](https://www.waveshare.com/wiki/ESP32-S3-ETH-8DI-8RO-C).\n\n## Hardware\n\nThe Waveshare ESP32-S3-ETH-8DI-8RO-C provides:\n\n- **ESP32-S3** dual-core LX7 @ 240 MHz with WiFi and BLE\n- **8 relay channels** (1NO/1NC each), rated 10A @ 250V AC / 10A @ 30V DC, via TCA9554PWR I2C I/O expander\n- **8 digital inputs** (optocoupler isolated)\n- **CAN bus** with onboard transceiver and 120 ohm termination jumper\n- **Ethernet** (W5500 via SPI, 10/100 Mbps)\n- **7-36V DC** input (or 5V via USB-C)\n- **RTC** (PCF85063ATL) with battery backup header\n- **SD card** slot (MMC 1-bit mode)\n- DIN-rail mount enclosure\n\n## Firmware\n\n### Pin Assignments\n\nRelays are controlled via TCA9554PWR I2C I/O expander (address 0x20) on I2C SDA=GPIO42, SCL=GPIO41.\n\n| Function   | Pin / Address |\n|------------|---------------|\n| Relay 1-8  | TCA9554 P0-P7 (I2C 0x20) |\n| DI 1-8     | GPIO 4-11     |\n| CAN TX     | GPIO 17       |\n| CAN RX     | GPIO 18       |\n| Buzzer     | GPIO 46       |\n| RGB LED    | GPIO 38       |\n| ETH MOSI   | GPIO 13       |\n| ETH MISO   | GPIO 14       |\n| ETH SCLK   | GPIO 15       |\n| ETH CS     | GPIO 16       |\n\n### CAN Protocol\n\nCAN bus runs at **500 kbps** in no-ACK mode.\n\n| CAN ID | Direction | Description |\n|--------|-----------|-------------|\n| `0x00` | RX | **OTA trigger** — 3-byte payload (MAC bytes 3-5) targets a specific device |\n| `0x01` | RX | **WiFi config** — multi-message chunked protocol to provision SSID and password |\n| `0x25` | RX | **Relay toggle** — toggle a single relay (channel 0-7) or set all relays (channel \u003e= 8, byte 2 = on/off) |\n| `0x28` | TX | **Status broadcast** — 1-byte bitmask (bits 0-7 = relay states), sent at ~30 Hz |\n\n### WiFi Provisioning over CAN\n\nWiFi credentials can be sent to the device over the CAN bus using a multi-message protocol on CAN ID `0x01`:\n\n1. **Start** (type `0x01`) — declares SSID length, password length, chunk counts, and checksum\n2. **SSID chunks** (type `0x02`) — up to 6 bytes per message, indexed\n3. **Password chunks** (type `0x03`) — up to 6 bytes per message, indexed\n4. **End** (type `0x04`) — verifies XOR checksum and saves credentials to NVS\n\nA 5-second timeout resets the state if the sequence is not completed.\n\n### OTA Updates\n\nThe firmware supports over-the-air updates via WiFi. An OTA trigger message on CAN ID `0x00` with the device's MAC address (bytes 3-5) puts the device into OTA mode. The flash partition table supports dual-OTA (app0/app1) for safe rollback.\n\n## Building\n\n### Prerequisites\n\n- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/get-started/) v5.x\n\n### Build and Flash\n\n```bash\nidf.py set-target esp32s3\nidf.py build\nidf.py -p /dev/ttyACM0 flash monitor\n```\n\n## Project Structure\n\n```\nTrailCurrentSwitchback/\n├── main/\n│   ├── main.c              # Entry point — init and CAN task\n│   ├── board.h             # Pin definitions for ESP32-S3-ETH-8DI-8RO-C\n│   ├── relay.h / relay.c   # TCA9554 I2C relay driver (8 channels)\n│   ├── can_handler.h / .c  # CAN protocol and message handling\n│   └── wifi_config.h / .c  # WiFi credential storage and CAN provisioning\n├── CMakeLists.txt          # Top-level ESP-IDF project file\n├── partitions.csv          # Custom flash partition table (dual OTA)\n└── sdkconfig.defaults      # Default SDK configuration\n```\n\n## License\n\nSee [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailcurrentoss%2Ftrailcurrentswitchback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailcurrentoss%2Ftrailcurrentswitchback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailcurrentoss%2Ftrailcurrentswitchback/lists"}