# meatpihq/wican-fw architecture

> Architecture diagram of the GitHub repository meatpihq/wican-fw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meatpihq/wican-fw
- Repository: https://github.com/meatpihq/wican-fw

## Overview

WiCAN is embedded firmware for vehicle OBD-II/CAN access over Wi-Fi, BLE and USB/serial, with vehicle-data reporting and diagnostic protocols. The main workflow initializes device services, receives or transmits CAN frames, and dispatches host traffic according to the configured protocol; AutoPID and MQTT provide vehicle-data reporting. The README also documents web setup, Home Assistant webhooks, sleep behavior and diagnostic interfaces. Several implementation files were not sampled, so uncertain subsystem links are omitted; documented capabilities may be represented at their existing source path without implying inspected internals.

Main entry points: [`main/main.c`](https://github.com/meatpihq/wican-fw/blob/main/main/main.c) (Firmware runtime), [`main/autopid.c`](https://github.com/meatpihq/wican-fw/blob/main/main/autopid.c) (AutoPID profiles), [`main/can.c`](https://github.com/meatpihq/wican-fw/blob/main/main/can.c) (CAN driver), [`main/mqtt.c`](https://github.com/meatpihq/wican-fw/blob/main/main/mqtt.c) (MQTT reporting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Device services"]
  node_app_main["Firmware runtime<br/>[main.c]"]
  node_config["Setup and HTTP API<br/>[config_server.c]"]
  node_wifi["Wi-Fi network<br/>[wifi_network.c]"]
  node_sleep["Sleep and wake<br/>[sleep_mode.c]"]
end

subgraph group_vehicle["Vehicle data"]
  node_can["CAN driver<br/>[can.c]"]
  node_autopid["AutoPID profiles<br/>[autopid.c]"]
  node_expression["Expression evaluator"]
end

subgraph group_interfaces["Host interfaces"]
  node_ble["Bluetooth LE<br/>[ble.c]"]
  node_comm["TCP/UDP server<br/>[comm_server.c]"]
  node_slcan["slcan protocol<br/>[slcan.c]"]
  node_elm["ELM327 adapter<br/>[elm327.c]"]
  node_realdash["RealDash protocol<br/>[realdash.c]"]
  node_gvret["GVRET / SavvyCAN<br/>[gvret.c]"]
  node_ftp["FTP access<br/>[ftp.c]"]
end

subgraph group_reporting["Reporting and storage"]
  node_mqtt["MQTT reporting<br/>[mqtt.c]"]
  node_webhook["Home Assistant webhooks<br/>[ha_webhooks_http.c]"]
  node_webhook_config["Webhook configuration"]
  node_filesystem["Filesystem<br/>[filesystem.c]"]
end

node_driver(("Vehicle CAN bus"))
node_operator(("Device user"))
node_broker(("MQTT broker"))
node_ha(("Home Assistant"))
node_diagnostic_app(("Diagnostic apps"))

node_driver -->|"CAN frames"| node_can
node_app_main -->|"reads settings"| node_config
node_app_main -->|"configures and receives"| node_can
node_app_main -->|"starts server"| node_comm
node_app_main -->|"starts BLE"| node_ble
node_app_main -.->|"starts networking"| node_wifi
node_app_main -->|"initializes sleep"| node_sleep
node_app_main -->|"initializes reporting"| node_mqtt
node_app_main -->|"dispatches traffic"| node_slcan
node_app_main -->|"parses traffic"| node_realdash
node_app_main -->|"dispatches traffic"| node_gvret
node_app_main -->|"dispatches commands"| node_elm
node_app_main -->|"initializes polling"| node_autopid
node_autopid -->|"evaluates formulas"| node_expression
node_autopid -->|"publishes values"| node_mqtt
node_autopid -->|"updates status"| node_webhook_config
node_webhook -->|"manages settings"| node_webhook_config
node_webhook_config -->|"persists config"| node_filesystem
node_can -.->|"supplies vehicle data"| node_autopid
node_mqtt -->|"publishes messages"| node_broker
node_webhook -.->|"posts events"| node_ha
node_diagnostic_app -->|"connects over Wi-Fi"| node_comm
node_operator -->|"configures device"| node_config
node_operator -.->|"accesses files"| node_ftp

click node_app_main "https://github.com/meatpihq/wican-fw/blob/main/main/main.c"
click node_can "https://github.com/meatpihq/wican-fw/blob/main/main/can.c"
click node_config "https://github.com/meatpihq/wican-fw/blob/main/main/config_server.c"
click node_wifi "https://github.com/meatpihq/wican-fw/blob/main/main/wifi_network.c"
click node_ble "https://github.com/meatpihq/wican-fw/blob/main/main/ble.c"
click node_comm "https://github.com/meatpihq/wican-fw/blob/main/main/comm_server.c"
click node_slcan "https://github.com/meatpihq/wican-fw/blob/main/main/slcan.c"
click node_elm "https://github.com/meatpihq/wican-fw/blob/main/main/elm327.c"
click node_realdash "https://github.com/meatpihq/wican-fw/blob/main/main/realdash.c"
click node_gvret "https://github.com/meatpihq/wican-fw/blob/main/main/gvret.c"
click node_autopid "https://github.com/meatpihq/wican-fw/blob/main/main/autopid.c"
click node_expression "https://github.com/meatpihq/wican-fw/blob/main/main/expression_parser.c"
click node_mqtt "https://github.com/meatpihq/wican-fw/blob/main/main/mqtt.c"
click node_webhook "https://github.com/meatpihq/wican-fw/blob/main/components/ha_webhooks/ha_webhooks_http.c"
click node_webhook_config "https://github.com/meatpihq/wican-fw/blob/main/components/ha_webhooks/ha_webhooks_config.c"
click node_filesystem "https://github.com/meatpihq/wican-fw/blob/main/components/filesystem/filesystem.c"
click node_sleep "https://github.com/meatpihq/wican-fw/blob/main/main/sleep_mode.c"
click node_ftp "https://github.com/meatpihq/wican-fw/blob/main/main/ftp.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_main,node_config,node_wifi,node_sleep,node_operator toneBlue
class node_can,node_autopid,node_expression toneAmber
class node_ble,node_comm,node_slcan,node_elm,node_realdash,node_gvret,node_ftp toneMint
class node_mqtt,node_webhook,node_webhook_config,node_filesystem toneRose
class node_driver,node_broker,node_ha,node_diagnostic_app toneIndigo
```

## Components

### Device services

- [Firmware runtime](https://github.com/meatpihq/wican-fw/blob/main/main/main.c): `main/main.c`
- [Setup and HTTP API](https://github.com/meatpihq/wican-fw/blob/main/main/config_server.c): `main/config_server.c`
- [Wi-Fi network](https://github.com/meatpihq/wican-fw/blob/main/main/wifi_network.c): `main/wifi_network.c`
- [Sleep and wake](https://github.com/meatpihq/wican-fw/blob/main/main/sleep_mode.c): `main/sleep_mode.c`

### Vehicle data

- [CAN driver](https://github.com/meatpihq/wican-fw/blob/main/main/can.c): `main/can.c`
- [AutoPID profiles](https://github.com/meatpihq/wican-fw/blob/main/main/autopid.c): `main/autopid.c`
- [Expression evaluator](https://github.com/meatpihq/wican-fw/blob/main/main/expression_parser.c): `main/expression_parser.c`

### Host interfaces

- [Bluetooth LE](https://github.com/meatpihq/wican-fw/blob/main/main/ble.c): `main/ble.c`
- [TCP/UDP server](https://github.com/meatpihq/wican-fw/blob/main/main/comm_server.c): `main/comm_server.c`
- [slcan protocol](https://github.com/meatpihq/wican-fw/blob/main/main/slcan.c): `main/slcan.c`
- [ELM327 adapter](https://github.com/meatpihq/wican-fw/blob/main/main/elm327.c): `main/elm327.c`
- [RealDash protocol](https://github.com/meatpihq/wican-fw/blob/main/main/realdash.c): `main/realdash.c`
- [GVRET / SavvyCAN](https://github.com/meatpihq/wican-fw/blob/main/main/gvret.c): `main/gvret.c`
- [FTP access](https://github.com/meatpihq/wican-fw/blob/main/main/ftp.c): `main/ftp.c`

### Reporting and storage

- [MQTT reporting](https://github.com/meatpihq/wican-fw/blob/main/main/mqtt.c): `main/mqtt.c`
- [Home Assistant webhooks](https://github.com/meatpihq/wican-fw/blob/main/components/ha_webhooks/ha_webhooks_http.c): `components/ha_webhooks/ha_webhooks_http.c`
- [Webhook configuration](https://github.com/meatpihq/wican-fw/blob/main/components/ha_webhooks/ha_webhooks_config.c): `components/ha_webhooks/ha_webhooks_config.c`
- [Filesystem](https://github.com/meatpihq/wican-fw/blob/main/components/filesystem/filesystem.c): `components/filesystem/filesystem.c`

### Other components

- **Vehicle CAN bus**
- **Device user**
- **MQTT broker**
- **Home Assistant**
- **Diagnostic apps**

## Connections

- Vehicle CAN bus → CAN driver: CAN frames (evidence: `README.md`)
- Firmware runtime → Setup and HTTP API: reads settings (evidence: `main/main.c`)
- Firmware runtime → CAN driver: configures and receives (evidence: `main/main.c`)
- Firmware runtime → TCP/UDP server: starts server (evidence: `main/main.c`)
- Firmware runtime → Bluetooth LE: starts BLE (evidence: `main/main.c`)
- Firmware runtime → Wi-Fi network: starts networking (evidence: `main/main.c`)
- Firmware runtime → Sleep and wake: initializes sleep (evidence: `main/main.c`)
- Firmware runtime → MQTT reporting: initializes reporting (evidence: `main/main.c`)
- Firmware runtime → slcan protocol: dispatches traffic (evidence: `main/main.c`)
- Firmware runtime → RealDash protocol: parses traffic (evidence: `main/main.c`)
- Firmware runtime → GVRET / SavvyCAN: dispatches traffic (evidence: `main/main.c`)
- Firmware runtime → ELM327 adapter: dispatches commands (evidence: `main/main.c`)
- Firmware runtime → AutoPID profiles: initializes polling (evidence: `main/main.c`)
- AutoPID profiles → Expression evaluator: evaluates formulas (evidence: `main/autopid.c`)
- AutoPID profiles → MQTT reporting: publishes values (evidence: `main/autopid.c`)
- AutoPID profiles → Webhook configuration: updates status (evidence: `main/autopid.c`)
- Home Assistant webhooks → Webhook configuration: manages settings
- Webhook configuration → Filesystem: persists config (evidence: `components/ha_webhooks/ha_webhooks_config.c`)
- CAN driver → AutoPID profiles: supplies vehicle data
- MQTT reporting → MQTT broker: publishes messages (evidence: `README.md`)
- Home Assistant webhooks → Home Assistant: posts events (evidence: `README.md`)
- Diagnostic apps → TCP/UDP server: connects over Wi-Fi (evidence: `README.md`)
- Device user → Setup and HTTP API: configures device (evidence: `README.md`)
- Device user → FTP access: accesses files (evidence: `README.md`)
