Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ per ESP-NOW an ein LilyGO T-Display S3 im Auto.
- **Display** (`env:display`): flackerfreie Anzeige mit 4 Fahrseiten und
4 Diagnoseseiten, Weboberfläche.

Stand: `V2.1.0-beta.2`, Telemetrie-Protokoll 3.
Stand: `V2.1.0-beta.3`, Telemetrie-Protokoll 3.

## Schnellstart

Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V2.1.0-beta.2
V2.1.0-beta.3
8 changes: 6 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ Gemeinsamer Code liegt in `lib/` und wird nativ getestet (`env:native`).
## Datenfluss Livewerte

1. `Obd::PidPollPlanner` wählt pro Durchlauf den PID, der relativ zu seinem
Sollintervall am stärksten überfällig ist (schnelle Werte 200 ms, langsame
2 s). Nicht unterstützte PIDs (laut ECU-Maske) werden übersprungen.
Sollintervall am stärksten überfällig ist (schnell 200 ms: Drehzahl, Tempo,
Last, Luftmasse; langsam 2 s: Temperaturen, Spannung, Tank …). Nicht
unterstützte PIDs (laut Maske des Motorsteuergeräts 0x7E8) werden übersprungen.
Antworten anderer Steuergeräte (z. B. Getriebe 0x7E9) werden für Mode 01/09 verworfen.
Der Verbrauch wird aus der Luftmasse berechnet (PID 0x5E ist bei VW unzuverlässig).
2. `OBD2Handler` dekodiert die Antwort und schreibt sie in die
`LiveData::LiveValueTable` (`SenderLiveData`). Abgeleitete Werte
(Ladedruck, Verbrauch) und die Bordspannung landen in derselben Tabelle.
Expand Down Expand Up @@ -51,6 +54,7 @@ Heartbeat) sind selten und bleiben Textpakete.
| `lib/update/` | GitHub-Manifest, SemVer, `OtaSession` (signierte Installation), Boot-Validierung |
| `lib/firmware_signing/`, `lib/monocypher/` | Ed25519-Prüfung der Firmware |
| `lib/security/` | Gerätezugangsdaten im NVS |
| `lib/diagnostics/` | Neustartgrund, Absturzbericht (Coredump), Loop-Watchdog |
| `lib/web/` | Gemeinsamer Management-Webserver, Authentifizierung, HTML-Assets |
| `lib/simulation/`, `lib/capabilities/`, `lib/can_router/` | Entwicklerwerkzeuge (nur `*_dev`-Builds aktiv) |
| `include/config/` | Konfiguration je Bereich (keine Zugangsdaten) |
Expand Down
29 changes: 29 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ python scripts/ota_upload.py --host 192.168.4.1 output/sender.bin
python scripts/ota_upload.py --sign-key ~/canobd2-signing.pem .pio/build/sender/firmware.bin
```

## Logs per USB auslesen

Ohne WLAN, direkt über USB (nur lesend). Das Board kann am selben Rechner oder
an einem per SSH erreichbaren Linux-Rechner hängen:

```bash
python scripts/read_device_logs.py sender --remote kalipi --out ~/canobd2-logs
python scripts/read_device_logs.py display --remote kalipi --out ~/canobd2-logs
```

Geräte mit dem alten Layout (bis V2.1.0-beta.2): zusätzlich `--layout legacy`.
**Vor** einem Layout-Wechsel auslesen, sonst ist das alte Log weg. Die Logs
können die Fahrgestellnummer enthalten, also nicht ins Repository übernehmen.

## Abstürze analysieren

Jeder Start schreibt den Grund ins Diagnose-Log (`[BOOT] … reset=PANIC|TASK_WDT|…`).
Nach einem Absturz liegt ein Absturzbericht (Coredump, ELF) im Flash. Man lädt
ihn in der Weboberfläche oder per `GET /api/coredump` herunter und wertet ihn
mit der `firmware.elf` **genau dieses Builds** aus (CI-Artefakt bzw. lokaler
Build mit gleichem Commit):

```bash
pip install esp-coredump
esp-coredump info_corefile -t raw -c CANOBD2_sender_…_coredump.bin .pio/build/sender/firmware.elf
```

Danach den Bericht in der Weboberfläche löschen (`POST /api/coredump/clear`).

## Release

GitHub → Actions → **Release** → Version (z. B. `2.1.0-beta.1`) und Kanal
Expand Down
17 changes: 14 additions & 3 deletions docs/HARDWARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
| CAN TX / RX (TWAI) | 5 / 4 |
| LED grün / Fehler | 26 / 27 |
| Taster (LED-Test) | 25 |
| Spannungsteiler Bordnetz | 32 (Faktor 4,81) |
| Spannungsteiler Bordnetz | 32 (Faktor 4,62, abgeglichen mit PID 0x42) |

Partitionslayout `partitions/sender_4mb.csv`: 2 × 1,81 MB Firmware, 64 KB
Absturzbericht, 256 KB Log.

CAN: 500 kbit/s, OBD-Anfragen funktional an `0x7DF`, nach wiederholten
Timeouts physisch an `0x7E0`. Nach Bus-Off startet der Treiber automatisch neu.
Expand All @@ -30,7 +33,8 @@ sendet der Sender nur noch ein Paket pro Sekunde, bis es wieder quittiert.
## Display – LilyGO T-Display S3

ST7789 170×320 an 8-Bit-Parallelbus (Pins in `platformio.ini`), Hintergrundbeleuchtung GPIO 38,
Displayversorgung GPIO 15, Tasten GPIO 0 (BOOT) und GPIO 14.
Partitionslayout `partitions/display_16mb.csv`: 2 × 4 MB Firmware, 128 KB
Absturzbericht, 1 MB Log, Rest frei. Displayversorgung GPIO 15, Tasten GPIO 0 (BOOT) und GPIO 14.

Tasten: BOOT (GPIO 0) kurz = nächste Seite, zweite Taste (GPIO 14) kurz = vorherige
Seite, eine der beiden lang (1,2 s) = Hauptseite, BOOT sehr lang (3 s) = Diagnoseseiten ein/aus.
Expand All @@ -52,7 +56,14 @@ VW-MQB-Evo-Fahrzeuge halten Steuergeräte nach Zündung-aus minutenlang wach und
nutzen Start-Stopp intensiv. Der Power-Manager (`lib/power/ActivityMonitor`)
bewertet deshalb Drehzahl, Tempo, Last, Drosselklappe, Spannung und Busaktivität.
Ohne CAN-/OBD-Aktivität gilt das Fahrzeug nach 5 min als geparkt; 10 min danach schickt er dem Display
`Sleep`, beim Aufwachen `Wakeup`.
`Sleep`, beim Aufwachen `Wakeup`. Das Display folgt dem jede Sekunde gesendeten
Zustand (`DisplaySleep`), ein verlorenes Paket hält es also nicht wach.

**Fahrzeug schlafen lassen:** Antwortet das Motorsteuergerät nicht (Zündung aus),
sendet der Sender nichts mehr auf den Diagnose-CAN. Anfragen würden das
VW-Gateway wecken und das Bordnetz wach halten. Die Abfrage startet erst wieder,
wenn die Bordspannung ≥ 13,0 V zeigt (Lichtmaschine lädt, Motor läuft). Mit
Zündung an, aber Motor aus, bleiben die Werte deshalb leer.

## Inbetriebnahme-Check

Expand Down
16 changes: 16 additions & 0 deletions docs/PROVISIONING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ Paket kopieren (z. B. `scp -r`), Board per USB anschließen, dann:
5. Optional: unter „Firmware-Update“ eine unsignierte Datei hochladen – sie muss
abgelehnt werden.

## Partitionslayout ändern (Zugangsdaten bleiben)

Eine neue Partitionstabelle lässt sich nicht per WLAN einspielen. Für diesen
Fall gibt es den Befehl `layout`: Er schreibt Bootloader, Partitionstabelle,
Startauswahl und Firmware, **ohne** den Flash zu löschen. Der NVS-Bereich mit
den Zugangsdaten liegt in allen Layouts bei `0x9000` und bleibt erhalten. Nur
das Diagnose-Log wird beim ersten Start neu angelegt.

```bash
./flash.sh pruefen sender && ./flash.sh layout sender
./flash.sh pruefen display && ./flash.sh layout display
```

Aktuelle Layouts: `partitions/sender_4mb.csv` (ESP32, 4 MB) und
`partitions/display_16mb.csv` (ESP32-S3, 16 MB), jeweils mit Coredump-Bereich.

## Spätere Updates

Unter **Firmware-Update** (`/github-update`): WLAN/Hotspot eintragen, Kanal
Expand Down
4 changes: 4 additions & 0 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Zugriff auf die Platine das NVS auslesen.
als bestätigt (`lib/update/BootValidation`). Stürzt sie vorher ab, startet
der Bootloader wieder die vorherige Version.

* **Watchdog:** Hängt `loop()` länger als 30 s, startet das Gerät neu. Passiert
das mit einer frisch installierten Firmware innerhalb der ersten 30 s, greift
ebenfalls der Rollback.

### Schlüsselverwaltung

* Öffentliche Schlüssel: `include/config/FirmwareSigningKeys.h` (im Repo).
Expand Down
24 changes: 16 additions & 8 deletions include/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ namespace Logger {
if (sink) sink(msg);
}

// Per-frame/per-request trace (debug, ISO-TP, OBD values). Writing every
// line to the flash log slowed polling down to ~5 requests/s in the
// vehicle; it only goes to the sink (web console + flash log) when
// explicitly enabled for a debugging session.
inline void emitTrace(const char* msg) {
if (LoggingConfig::PersistTraceToDiagnosticLog && sink) sink(msg);
}

// ======== Initialisierung ========
inline void initDebug() {
if (LoggingConfig::SerialEnabled) {
Expand All @@ -37,7 +45,7 @@ namespace Logger {

// ======== Allgemeines Debug ========
inline void debug(const char* msg) {
emit(msg);
emitTrace(msg);
if (LoggingConfig::GeneralDebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[DEBUG] ");
Serial.println(msg);
Expand All @@ -55,7 +63,7 @@ namespace Logger {

Serial.print("[DEBUG] ");
Serial.println(buf);
emit(buf);
emitTrace(buf);
}

template<typename T>
Expand All @@ -72,7 +80,7 @@ namespace Logger {
Serial.println();
char buf[128];
snprintf(buf, sizeof(buf), "%s: %s%s", label, String(value).c_str(), unit && unit[0] ? unit : "");
emit(buf);
emitTrace(buf);
}
}

Expand Down Expand Up @@ -110,7 +118,7 @@ namespace Logger {
}

inline void can(const char* msg) {
emit(msg);
emitTrace(msg);
if (LoggingConfig::CanDebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[CAN] ");
Serial.println(msg);
Expand All @@ -125,7 +133,7 @@ namespace Logger {
for (int i = 0; i < message.data_length_code && used > 0 && used < static_cast<int>(sizeof(buf)); i++) {
used += snprintf(buf + used, sizeof(buf) - used, " %02X", message.data[i]);
}
emit(buf);
emitTrace(buf);

if (LoggingConfig::CanDebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[CAN] ID=0x");
Expand All @@ -144,7 +152,7 @@ namespace Logger {

// ======== OBD2 Debug ========
inline void obd(const char* msg) {
emit(msg);
emitTrace(msg);
if (LoggingConfig::Obd2DebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[OBD2] ");
Serial.println(msg);
Expand All @@ -157,7 +165,7 @@ namespace Logger {
for (uint8_t i = 0; i < len && used > 0 && used < static_cast<int>(sizeof(buf)); i++) {
used += snprintf(buf + used, sizeof(buf) - used, " %02X", data[i]);
}
emit(buf);
emitTrace(buf);

if (LoggingConfig::Obd2DebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[OBD2] PID 0x");
Expand All @@ -180,7 +188,7 @@ namespace Logger {
String(value).c_str(),
unit && unit[0] ? " " : "",
unit && unit[0] ? unit : "");
emit(buf);
emitTrace(buf);

if (LoggingConfig::Obd2DebugEnabled && LoggingConfig::SerialEnabled) {
Serial.print("[OBD2] ");
Expand Down
14 changes: 8 additions & 6 deletions include/config/DisplayConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ constexpr uint32_t ButtonDebounceMs = 30;
constexpr std::size_t TelemetryQueueLength = 16;
constexpr std::size_t TelemetryValueCapacity = 64;

constexpr float CoolantWarnC = 95.0f;
constexpr float CoolantCriticalC = 105.0f;
constexpr float OilWarnC = 115.0f;
constexpr float OilCriticalC = 125.0f;
// VW engines run 90-105 C coolant (eco mode up to ~110) and oil up to ~120 C.
constexpr float CoolantWarnC = 110.0f;
constexpr float CoolantCriticalC = 118.0f;
constexpr float OilWarnC = 130.0f;
constexpr float OilCriticalC = 140.0f;
constexpr float VoltageWarnLow = 11.8f;
constexpr float VoltageCriticalLow = 11.2f;
constexpr float VoltageWarnHigh = 14.8f;
constexpr float VoltageCriticalHigh = 15.2f;
// VW energy management charges up to ~15 V when cold; above that is suspicious.
constexpr float VoltageWarnHigh = 15.5f;
constexpr float VoltageCriticalHigh = 16.0f;
constexpr uint16_t RpmWarn = 4200;
constexpr uint16_t RpmCritical = 5000;
constexpr uint16_t RpmMax = 6000;
Expand Down
5 changes: 4 additions & 1 deletion include/config/LoggingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
namespace LoggingConfig {

constexpr bool SerialEnabled = true;
constexpr bool GeneralDebugEnabled = true;
// Serial debug output per CAN frame / OBD request costs loop time; enable only for bench debugging.
constexpr bool GeneralDebugEnabled = false;
constexpr bool TwaiDebugEnabled = false;
constexpr bool PowerDebugEnabled = false;
constexpr bool CanDebugEnabled = false;
Expand All @@ -16,6 +17,8 @@ constexpr uint32_t TraceSummaryIntervalMs = 1000;

constexpr bool EnablePersistentDiagnosticLog = true;
constexpr bool PersistTelemetryPayloadsToDiagnosticLog = false;
// Write per-request OBD/ISO-TP trace lines to the flash log (debug only).
constexpr bool PersistTraceToDiagnosticLog = false;
constexpr std::size_t DiagnosticLogMaxBytes = 64U * 1024U;

constexpr const char* SenderDiagnosticLogPath = "/sender_diagnostic.log";
Expand Down
22 changes: 14 additions & 8 deletions include/config/ObdConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ inline constexpr uint8_t RequestedPids[] = {
RUN_TIME_SINCE_ENGINE_START,
CONTROL_MODULE_VOLTAGE,
AMBIENT_AIR_TEMP,
ENGINE_OIL_TEMP,
ENGINE_FUEL_RATE
ENGINE_OIL_TEMP
};

inline constexpr std::size_t ObdPidCount = sizeof(RequestedPids) / sizeof(RequestedPids[0]);
Expand All @@ -34,28 +33,35 @@ inline constexpr std::size_t ObdPidCount = sizeof(RequestedPids) / sizeof(Reques
inline constexpr uint8_t FastLivePids[] = {
ENGINE_RPM,
VEHICLE_SPEED,
CONTROL_MODULE_VOLTAGE,
ENGINE_COOLANT_TEMP,
ENGINE_LOAD
ENGINE_LOAD,
MAF_FLOW_RATE // fuel consumption is derived from it
};
inline constexpr std::size_t FastLivePidCount = sizeof(FastLivePids) / sizeof(FastLivePids[0]);

// Slow live values still update regularly, but they are less important while
// driving and are often unsupported on some vehicles.
inline constexpr uint8_t SlowLivePids[] = {
ENGINE_COOLANT_TEMP,
CONTROL_MODULE_VOLTAGE,
INTAKE_MANIFOLD_ABS_PRESSURE,
INTAKE_AIR_TEMP,
ABS_BAROMETRIC_PRESSURE,
MAF_FLOW_RATE,
THROTTLE_POSITION,
FUEL_TANK_LEVEL_INPUT,
RUN_TIME_SINCE_ENGINE_START,
AMBIENT_AIR_TEMP,
ENGINE_OIL_TEMP,
ENGINE_FUEL_RATE
ENGINE_OIL_TEMP
};
inline constexpr std::size_t SlowLivePidCount = sizeof(SlowLivePids) / sizeof(SlowLivePids[0]);

// PID 0x5E (engine fuel rate) is unreliable on VW TSI engines (first vehicle
// test: 2.2 L/h reported vs. ~7.7 L/h from the air mass). For petrol engines
// the rate is derived from MAF: fuel = air / AFR, zero in overrun (load ~0).
constexpr bool FuelRateFromMaf = true;
constexpr float StoichiometricAfr = 14.7f; // petrol
constexpr float FuelDensityGramPerLitre = 745.0f; // petrol E5/E10
constexpr float OverrunLoadPercent = 2.0f;

constexpr float DefaultBarometricPressureKpa = SenderConfig::DefaultBarometricPressureKpa;
constexpr uint32_t DtcQueryIntervalMs = SenderConfig::DtcQueryIntervalMs;
constexpr uint32_t VinQueryIntervalMs = SenderConfig::VinQueryIntervalMs;
Expand Down
3 changes: 3 additions & 0 deletions include/config/PowerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ constexpr float MovingSpeedKph = 1.0f;
constexpr float ActiveEngineLoadPercent = 5.0f;
constexpr float ActiveThrottlePercent = 2.0f;
constexpr float BoardVoltageAwakeMin = 12.0f;
// With the ECU silent, OBD polling (re)starts only above this board voltage
// (alternator charging = engine running). See SenderApp vehicleBusMayBeUsed().
constexpr float ResumePollingVoltage = 13.0f;

} // namespace PowerConfig
3 changes: 2 additions & 1 deletion include/config/SenderConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ constexpr const char* DiagnosticLogArchivePath = LoggingConfig::SenderDiagnostic
constexpr uint32_t TwaiStatusLogIntervalMs = LoggingConfig::TwaiStatusLogIntervalMs;
constexpr std::size_t MaxCanFramesPerTick = 16;

constexpr float VoltageCalcFactor = 4.81f;
// Calibrated 01.11.2026 against the engine ECU (PID 0x42: 14.62 V, ADC read ~15.3 V).
constexpr float VoltageCalcFactor = 4.62f;
constexpr float DefaultBarometricPressureKpa = 101.3f;

constexpr std::size_t CanRxQueueLength = 32;
Expand Down
Loading
Loading