node-red-contrib-cardata 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gabe Mensinga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,173 @@
1
- # Temporary Holding Version
1
+ # node-red-contrib-cardata
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Node-RED nodes for **MINI/BMW CarData**: stream the car's state (charge level, range,
4
+ charging status, position) and its charge target into a virtual EV device — e.g. for
5
+ Victron VRM/Dynamic ESS — plus trip tracking built from the car's own odometer and
6
+ position, since CarData itself keeps no trip history.
7
+
8
+ *[Nederlandse versie van deze pagina](README.nl.md).*
9
+
10
+ ## Requirements
11
+
12
+ | | |
13
+ | --- | --- |
14
+ | Node-RED | 3.0 or newer |
15
+ | Node.js | 18 or newer |
16
+ | CarData | a client created in the [CarData portal](https://www.bmw.com/cardata), subscribed to "stream" |
17
+ | Victron VRM (optional) | `@victronenergy/node-red-contrib-victron` (preinstalled on Venus OS; not on npm) for the `victron-virtual` (EV device) node this package's output is meant to feed |
18
+
19
+ ## Nodes
20
+
21
+ | Node | What it does |
22
+ | --- | --- |
23
+ | `cardata-account` | Config node: client ID, VIN, login (device-code flow, button in the editor), container ID (also a button), home location. Shares one client — and its token refresh — with every node below. |
24
+ | `cardata-stream` | Connects to the CarData MQTT stream, parses it into flat paths, and sends the full current state — ready to wire into `victron-virtual`. Reconnects automatically on token refresh, and restores state after a Node-RED restart. |
25
+ | `cardata-target` | Polls the charge target through the REST API (not every vehicle streams it) — hourly by default. |
26
+ | `cardata-trips` | Builds trips (distance, duration, pauses) from `cardata-stream`'s state output. Optional; wire it in only if you want trip history. |
27
+
28
+ ## Set up CarData first
29
+
30
+ Do this **before** installing the nodes, otherwise there is nothing for them to connect to:
31
+
32
+ 1. In the MyBMW / MyMINI web portal (not the app), create a CarData client
33
+ ("Create CarData Client"), authorize both scopes `cardata:api:read` and
34
+ `cardata:streaming:read`, and switch on **CarData API** and **CarData Stream**. Note the
35
+ client ID.
36
+ 2. Tick the data points below and save the selection.
37
+
38
+ Official pages: [BMW Group CarData](https://www.bmwgroup.com/en/innovation/connected-car/cardata.html)
39
+ and [MINI CarData FAQ](https://www.mini.co.uk/en-gb/utilities/mini/api/assets/cardata/CarDataFAQ_mini_gb_en.pdf)
40
+ (UK; menu names differ per market). A step-by-step guide by the community:
41
+ [BavarianData portal setup](https://github.com/JustChr/BavarianData/wiki/Getting-Started-1-BMW-Portal-Setup).
42
+
43
+ ## Data points to enable in the CarData portal
44
+
45
+ When you configure the datastream for your client, tick these technical descriptors.
46
+ They are the ones `cardata-stream` recognizes (names as listed in the CarData portal; BMW
47
+ notes that availability can vary by vehicle model):
48
+
49
+ | Field | Technical descriptor | Used for |
50
+ | --- | --- | --- |
51
+ | `/Soc` | `vehicle.powertrain.electric.battery.stateOfCharge.displayed` | State of charge as shown in the car. `vehicle.drivetrain.batteryManagement.header` (the high-voltage battery's own figure) is accepted too; if both are on, the latest one received wins. |
52
+ | `/RangeToGo` | `vehicle.drivetrain.electricEngine.kombiRemainingElectricRange` | Remaining electric range in km. |
53
+ | `/ChargingState` | `vehicle.drivetrain.electricEngine.charging.status` | `NOCHARGING`, `INITIALIZATION`, `CHARGINGPAUSED` and `CHARGINGENDED` count as not charging, `CHARGINGACTIVE` as charging, `CHARGINGERROR` as an error. |
54
+ | `/Ac/Power` | `vehicle.powertrain.electric.battery.charging.power` | Current charging power. BMW documents it in watt and says it is only valid for its own timestamp: it is not reset when charging stops, so the package sets it to 0 as soon as the charging status says "not charging". |
55
+ | `/Odometer` | `vehicle.vehicle.travelledDistance` | Odometer in km; the basis of `cardata-trips`. |
56
+ | `/Position/Latitude` | `vehicle.cabin.infotainment.navigation.currentLocation.latitude` | Position (BMW sends it whether or not GPS positioning is switched on in the car's menu); used for `/AtSite` and for trip start/end/pauses. |
57
+ | `/Position/Longitude` | `vehicle.cabin.infotainment.navigation.currentLocation.longitude` | Same. |
58
+
59
+ The charge target is not part of the stream: it comes from the REST container, which
60
+ `cardata-target` polls. That container (made by the "Create container" button) always asks
61
+ for exactly these three descriptors, regardless of what you enable for the stream:
62
+
63
+ ```
64
+ vehicle.powertrain.electric.battery.stateOfCharge.target
65
+ vehicle.powertrain.electric.battery.stateOfCharge.displayed
66
+ vehicle.powertrain.electric.battery.charging.acLimit.selected
67
+ ```
68
+
69
+ BMW also rate-limits the REST side to 50 calls/day per account — `cardata-target`'s
70
+ hourly default uses 24 of those — and allows only **one streaming connection per
71
+ account** at a time, regardless of which client/app opens it (so `cardata-stream` and,
72
+ say, the CarData app or another tool can't both hold the stream at once).
73
+
74
+ ## Install
75
+
76
+ 1. From the Node-RED editor: **Menu → Manage palette → Install**, search for
77
+ `node-red-contrib-cardata`. Restart Node-RED afterwards; the nodes appear under
78
+ **cardata** in the palette.
79
+ 2. In Node-RED: **Import → Examples → node-red-contrib-cardata → cardata-victron**: the
80
+ complete flow, with the virtual EV device already wired up (it needs
81
+ `@victronenergy/node-red-contrib-victron`; without Victron use `cardata-basic`, which ends in debug
82
+ nodes). Open the `cardata-account` node, fill in the client ID and VIN, and deploy
83
+ once.
84
+ 3. Click **Log in** on the account node: it shows a link and a code. The link goes to the BMW or MINI
85
+ login page, whichever belongs to your account. Open it, enter the code, confirm with your MINI/BMW account. The node polls automatically and
86
+ shows "logged in" once done.
87
+ 4. Click **Create container** (needed for the charge target) — fills in the container ID
88
+ itself, or paste one you already created with the CarData API.
89
+ 5. Open the **Electric vehicle** node (`victron-virtual`) and fill in the same VIN and the
90
+ battery capacity in kWh — CarData has no capacity field. Check the brand, and pick your
91
+ **EV Charger** if you have one on the same system (that links the car to the charger,
92
+ so Dynamic ESS knows which charger charges which car; it's the one setting the example
93
+ can't pre-fill, because the instance differs per installation). The device then shows
94
+ up in VRM as an EV, fed by `cardata-stream` (state) and `cardata-target` (charge target).
95
+
96
+ The virtual device's node ID is kept stable in the example: a Victron virtual device's
97
+ instance is tied to that ID, so a new ID means a second device in VRM.
98
+
99
+ ## MQTT settings: tuned on the actual hardware, don't change lightly
100
+
101
+ | | | |
102
+ | --- | --- | --- |
103
+ | Keepalive | 25 s | BMW's broker closes an idle connection after ~60 s. At 60 the first ping lands exactly on that edge and the connection drops every minute. |
104
+ | Protocol version | MQTT v5 | v3.1.1 gives no reason on disconnect; v5 does. |
105
+ | Session | clean (no session expiry set) | A high session-expiry value keeps every dropped session counting and blocks new connections. |
106
+
107
+ `cardata-stream` reconnects (and resubscribes) on every real connect, including after a
108
+ token refresh — the previous connection's password (the ID token) stops working the
109
+ moment a new one is issued, and the broker only checks credentials at connect time.
110
+
111
+ ## What the car can tell you, and what it can't
112
+
113
+ `cardata-stream`'s state only ever reflects what the *car* reports: charge level, range,
114
+ charging status, current, position, and (if a home location is set) whether it's at that
115
+ site. It knows nothing about your home battery or grid connection — pair it with an
116
+ energy manager (Dynamic ESS, or your own) for that.
117
+
118
+ The charge target (`stateOfCharge.target`) isn't streamable for every vehicle, which is
119
+ why `cardata-target` polls the REST API instead (see [Data points](#data-points-to-enable-in-the-cardata-portal)
120
+ for its rate limit).
121
+
122
+ ## Trips
123
+
124
+ `cardata-trips` has no fixed idea of "the car is parked" — CarData doesn't expose an
125
+ ignition or parked signal. It weighs how long the car has been stationary against where
126
+ it is and whether it's charging: 3 minutes at the configured home location is enough,
127
+ 90 minutes while charging (a fast-charging stop shouldn't end a trip), 45 minutes
128
+ anywhere else. A stop of 10 minutes or more gets recorded as a pause inside the trip
129
+ (so a fuel/coffee stop or a charging session shows up, rather than silently extending
130
+ the trip), with its own duration, location and whether the car was charging.
131
+
132
+ A trip still open in memory does not survive a Node-RED restart; the odometer keeps
133
+ counting from where it left off, so the next trip starts from the right distance even
134
+ though the interrupted one is lost. Completed trips are appended as one JSON line per
135
+ trip to the trips file (default: `<Node-RED userDir>/cardata/trips-<node-id>.jsonl`,
136
+ or set your own path on the node) — read them back with:
137
+
138
+ ```sh
139
+ cat <path> | python3 -m json.tool --json-lines
140
+ ```
141
+
142
+ ## Privacy
143
+
144
+ The account node's tokens (access/refresh/ID token, your CarData account ID) live in two
145
+ places. Node-RED's own credential store keeps them encrypted in `flows_cred.json` (never in
146
+ a flow export), but Node-RED only writes that file on a deploy. Token refreshes happen
147
+ in between, and the refresh token you logged in with is replaced after the first one, so
148
+ the latest tokens are also kept in `<Node-RED userDir>/cardata/<account-id>.tokens.json`
149
+ (permissions 600, **not** encrypted — the same trade-off the old `tokens.json` made). On
150
+ startup the newest of the two wins. Latitude/longitude and VIN-like field names are masked in
151
+ `cardata-stream`'s "unknown fields" debug output (`(value hidden)`), so a debug sidebar
152
+ screenshot doesn't leak your location.
153
+
154
+ ## Development
155
+
156
+ ```sh
157
+ npm test # unit tests: parsing, trip logic, OAuth/REST against a fake BMW, node loading, locale keys
158
+ ```
159
+
160
+ `CardataClient` takes optional `authBase`/`apiBase` URLs, which is how the tests point it at
161
+ the fake BMW in `test/fake-cardata-auth.js`.
162
+
163
+ ## Sources
164
+
165
+ Technical descriptors as listed in the CarData portal, cross-checked against
166
+ [evcc's CarData page](https://docs.evcc.io/en/vehicles/bmw-cardata). The MQTT settings
167
+ above were found by trial on real hardware, and the field mapping was checked against the
168
+ stream of a MINI Aceman SE (including that `stateOfCharge.target`, not `targetMin`, is the
169
+ charge target).
170
+
171
+ ## License
172
+
173
+ MIT — see [LICENSE](LICENSE).
package/README.nl.md ADDED
@@ -0,0 +1,177 @@
1
+ # node-red-contrib-cardata
2
+
3
+ Node-RED-nodes voor **MINI/BMW CarData**: de toestand van de auto (accustand, bereik,
4
+ laadstatus, positie) en het laaddoel naar een virtueel EV-apparaat sturen — bijvoorbeeld
5
+ voor Victron VRM/Dynamic ESS — plus ritten bijhouden uit de kilometerstand en positie van
6
+ de auto zelf, want CarData houdt zelf geen ritgeschiedenis bij.
7
+
8
+ *[English version of this page](README.md).*
9
+
10
+ ## Eisen
11
+
12
+ | | |
13
+ | --- | --- |
14
+ | Node-RED | 3.0 of nieuwer |
15
+ | Node.js | 18 of nieuwer |
16
+ | CarData | een client aangemaakt in het [CarData-portaal](https://www.bmw.com/cardata), geabonneerd op "stream" |
17
+ | Victron VRM (optioneel) | `@victronenergy/node-red-contrib-victron` (standaard aanwezig op Venus OS; staat niet op npm) voor de `victron-virtual`-node (EV-apparaat) waar dit pakket zijn uitvoer voor bedoelt |
18
+
19
+ ## Nodes
20
+
21
+ | Node | Doet |
22
+ | --- | --- |
23
+ | `cardata-account` | Config-node: client-ID, VIN, inloggen (device-code flow, knop in de editor), container-ID (ook een knop), thuislocatie. Deelt één client — en de tokenvernieuwing — met alle nodes hieronder. |
24
+ | `cardata-stream` | Verbindt met de CarData MQTT-stream, parseert naar vlakke paden, en stuurt de volledige actuele toestand — klaar om op `victron-virtual` aan te sluiten. Herverbindt automatisch bij tokenvernieuwing, en herstelt de toestand na een herstart van Node-RED. |
25
+ | `cardata-target` | Haalt het laaddoel op via de REST-API (niet elke auto streamt dit) — standaard elk uur. |
26
+ | `cardata-trips` | Bouwt ritten (afstand, duur, pauzes) uit de toestand die `cardata-stream` stuurt. Optioneel; alleen aansluiten als je ritgeschiedenis wilt. |
27
+
28
+ ## Eerst CarData instellen
29
+
30
+ Doe dit **voordat** je de nodes installeert, anders hebben ze niets om mee te verbinden:
31
+
32
+ 1. Maak in het MyBMW- of MyMINI-webportaal (niet de app) een CarData-client aan
33
+ ("Create CarData Client"), autoriseer beide scopes `cardata:api:read` en
34
+ `cardata:streaming:read`, en zet **CarData API** en **CarData Stream** aan. Noteer het
35
+ client-ID.
36
+ 2. Vink de datapunten hieronder aan en bewaar de selectie.
37
+
38
+ Officiële pagina's: [BMW Group CarData](https://www.bmwgroup.com/en/innovation/connected-car/cardata.html)
39
+ en de [MINI CarData FAQ](https://www.mini.co.uk/en-gb/utilities/mini/api/assets/cardata/CarDataFAQ_mini_gb_en.pdf)
40
+ (Verenigd Koninkrijk; menunamen verschillen per markt). Een stapsgewijze gids van de community:
41
+ [BavarianData portal setup](https://github.com/JustChr/BavarianData/wiki/Getting-Started-1-BMW-Portal-Setup).
42
+
43
+ ## Datapunten aanzetten in het CarData-portaal
44
+
45
+ Vink bij het instellen van de datastream voor je client deze technical descriptors aan.
46
+ Dit zijn de velden die `cardata-stream` herkent (de namen zoals het CarData-portaal ze
47
+ toont; BMW vermeldt dat de beschikbaarheid per automodel kan verschillen):
48
+
49
+ | Veld | Technical descriptor | Gebruikt voor |
50
+ | --- | --- | --- |
51
+ | `/Soc` | `vehicle.powertrain.electric.battery.stateOfCharge.displayed` | Laadstatus zoals die in de auto wordt getoond. `vehicle.drivetrain.batteryManagement.header` (het cijfer van de hoogspanningsaccu zelf) wordt ook geaccepteerd; staan beide aan, dan wint de laatst ontvangen. |
52
+ | `/RangeToGo` | `vehicle.drivetrain.electricEngine.kombiRemainingElectricRange` | Resterende elektrische actieradius in km. |
53
+ | `/ChargingState` | `vehicle.drivetrain.electricEngine.charging.status` | `NOCHARGING`, `INITIALIZATION`, `CHARGINGPAUSED` en `CHARGINGENDED` tellen als niet laden, `CHARGINGACTIVE` als laden, `CHARGINGERROR` als fout. |
54
+ | `/Ac/Power` | `vehicle.powertrain.electric.battery.charging.power` | Huidig laadvermogen. BMW documenteert het in watt en zegt dat het alleen geldt voor zijn eigen tijdstempel: het wordt niet teruggezet als het laden stopt, dus het pakket zet het op 0 zodra de laadstatus "niet laden" meldt. |
55
+ | `/Odometer` | `vehicle.vehicle.travelledDistance` | Kilometerstand; de basis van `cardata-trips`. |
56
+ | `/Position/Latitude` | `vehicle.cabin.infotainment.navigation.currentLocation.latitude` | Positie (BMW stuurt die ook als plaatsbepaling in het menu van de auto uit staat); voor `/AtSite` en voor begin, einde en pauzes van ritten. |
57
+ | `/Position/Longitude` | `vehicle.cabin.infotainment.navigation.currentLocation.longitude` | Idem. |
58
+
59
+ Het laaddoel zit niet in de stream: dat komt uit de REST-container, die `cardata-target`
60
+ polt. Die container (via de knop "Container aanmaken") vraagt altijd precies deze drie
61
+ descriptors, los van wat je voor de stream aanzet:
62
+
63
+ ```
64
+ vehicle.powertrain.electric.battery.stateOfCharge.target
65
+ vehicle.powertrain.electric.battery.stateOfCharge.displayed
66
+ vehicle.powertrain.electric.battery.charging.acLimit.selected
67
+ ```
68
+
69
+ BMW begrenst de REST-kant ook op 50 aanroepen/dag per account — het standaard-interval
70
+ van `cardata-target` (elk uur) gebruikt er 24 — en staat maar **één streamverbinding per
71
+ account** tegelijk toe, ongeacht via welke client/app die loopt (dus `cardata-stream` en
72
+ bijvoorbeeld de CarData-app of een andere tool kunnen niet allebei tegelijk de stream
73
+ vasthouden).
74
+
75
+ ## Installeren
76
+
77
+ 1. Vanuit de Node-RED-editor: **Menu → Manage palette → Install**, zoek op
78
+ `node-red-contrib-cardata`. Herstart Node-RED daarna; de nodes staan dan onder
79
+ **cardata** in het palet.
80
+ 2. In Node-RED: **Import → Examples → node-red-contrib-cardata → cardata-victron**: de
81
+ complete flow, met het virtuele EV-apparaat al aangesloten (daarvoor is
82
+ `@victronenergy/node-red-contrib-victron` nodig; zonder Victron gebruik je `cardata-basic`, die eindigt
83
+ in debug-nodes). Open de `cardata-account`-node, vul het client-ID en het VIN in, en
84
+ deploy eenmalig.
85
+ 3. Klik op **Inloggen** op de account-node: die toont een link en een code. De link gaat naar de BMW- of
86
+ MINI-inlogpagina, afhankelijk van je account. Open hem, vul de code in, bevestig met je MINI/BMW-account. De node pollt automatisch en
87
+ toont "ingelogd" zodra het gelukt is.
88
+ 4. Klik op **Container aanmaken** (nodig voor het laaddoel) — vult het container-ID zelf
89
+ in, of plak er een die je al eerder met de CarData-API hebt gemaakt.
90
+ 5. Open de **Electric vehicle**-node (`victron-virtual`) en vul hetzelfde VIN in en de
91
+ accucapaciteit in kWh — CarData heeft daar geen veld voor. Controleer het merk en kies
92
+ je **EV Charger** als je er een op hetzelfde systeem hebt (dat koppelt de auto aan de
93
+ lader, zodat Dynamic ESS weet welke lader welke auto laadt; het enige veld dat het
94
+ voorbeeld niet kan voorinvullen, want het instance verschilt per installatie). Het
95
+ apparaat verschijnt dan in VRM als EV, gevoed door `cardata-stream` (toestand) en
96
+ `cardata-target` (laaddoel).
97
+
98
+ Het node-ID van het virtuele apparaat staat in het voorbeeld bewust vast: het device-instance
99
+ van een Victron virtual device hangt aan dat ID, dus een nieuw ID betekent een tweede
100
+ apparaat in VRM.
101
+
102
+ ## MQTT-instellingen: uitgezocht op het echte toestel, niet zomaar aanpassen
103
+
104
+ | | | |
105
+ | --- | --- | --- |
106
+ | Keepalive | 25 s | BMW's broker sluit een idle verbinding na ~60 s. Op 60 valt de eerste ping precies op die grens en ligt de verbinding er elke minuut uit. |
107
+ | Protocolversie | MQTT v5 | v3.1.1 geeft bij een verbreking geen reden; v5 wel. |
108
+ | Sessie | schoon (geen sessie-verlooptijd ingesteld) | Een hoge waarde laat elke afgebroken sessie meetellen en blokkeert nieuwe verbindingen. |
109
+
110
+ `cardata-stream` herverbindt (en abonneert opnieuw) bij elke echte verbinding, ook na een
111
+ tokenvernieuwing — het wachtwoord (het ID-token) van de vorige verbinding werkt vanaf dat
112
+ moment niet meer, en de broker controleert dat alleen bij het verbinden zelf.
113
+
114
+ ## Wat de auto wél en niet kan vertellen
115
+
116
+ De toestand van `cardata-stream` is altijd wat de *auto* meldt: accustand, bereik,
117
+ laadstatus, stroom, positie, en (met een ingestelde thuislocatie) of hij daar staat. Hij
118
+ weet niets van je thuisbatterij of aansluiting — daarvoor zet je er een energiemanager
119
+ naast (Dynamic ESS, of je eigen oplossing).
120
+
121
+ Het laaddoel (`stateOfCharge.target`) is niet voor elke auto streambaar, vandaar dat
122
+ `cardata-target` de REST-API polt (zie [Datapunten](#datapunten-aanzetten-in-het-cardata-portaal)
123
+ voor het quotum).
124
+
125
+ ## Ritten
126
+
127
+ `cardata-trips` heeft geen vast idee van "de auto staat geparkeerd" — CarData heeft geen
128
+ contactslot- of geparkeerd-veld. Het weegt hoe lang de auto stilstaat tegen waar hij
129
+ staat en of hij laadt: 3 minuten op de ingestelde thuislocatie is genoeg, 90 minuten
130
+ tijdens het laden (een snellaadsessie mag een rit niet beëindigen), 45 minuten overal
131
+ elders. Een stilstand vanaf 10 minuten komt als pauze in de rit te staan (zo blijft een
132
+ tank- of koffiestop, of een laadsessie, zichtbaar in plaats van de rit stilletjes te
133
+ verlengen), met eigen duur, plek en of er geladen werd.
134
+
135
+ Een rit die nog in het geheugen loopt overleeft een herstart van Node-RED niet; de
136
+ kilometerstand loopt gewoon door, dus de volgende rit begint bij de juiste afstand, ook al
137
+ is die ene onderbroken rit kwijt. Afgeronde ritten komen als één JSON-regel per rit in het
138
+ rittenbestand (standaard: `<Node-RED userDir>/cardata/trips-<node-id>.jsonl`, of zet je
139
+ eigen pad op de node) — uitlezen met:
140
+
141
+ ```sh
142
+ cat <pad> | python3 -m json.tool --json-lines
143
+ ```
144
+
145
+ ## Privacy
146
+
147
+ De tokens van de account-node (access/refresh/ID-token, je CarData-account-ID) staan op
148
+ twee plekken. Node-RED's eigen credential-opslag bewaart ze versleuteld in
149
+ `flows_cred.json` (nooit in een flow-export), maar schrijft dat bestand alleen bij een
150
+ deploy. Tokenvernieuwingen gebeuren daartussen, en de refresh-token waarmee je inlogde is
151
+ na de eerste vernieuwing vervangen, dus de laatste tokens staan ook in
152
+ `<Node-RED userDir>/cardata/<account-id>.tokens.json` (rechten 600, **niet** versleuteld —
153
+ dezelfde afweging als de oude `tokens.json`). Bij het starten wint de nieuwste van de twee.
154
+ Breedte-/lengtegraad en VIN-achtige veldnamen worden verborgen
155
+ in de "unknown fields"-debuguitvoer van `cardata-stream` (`(waarde verborgen)`), zodat een
156
+ screenshot van de debug-sidebar je locatie niet lekt.
157
+
158
+ ## Ontwikkelen
159
+
160
+ ```sh
161
+ npm test # unit tests: parsen, ritlogica, OAuth/REST tegen een nep-BMW, nodes laden, vertaalsleutels
162
+ ```
163
+
164
+ `CardataClient` accepteert optioneel `authBase`/`apiBase`-URL's; zo wijzen de tests hem naar
165
+ de nep-BMW in `test/fake-cardata-auth.js`.
166
+
167
+ ## Bronnen
168
+
169
+ Technical descriptors zoals ze in het CarData-portaal staan, gecontroleerd tegen
170
+ [evcc's CarData-pagina](https://docs.evcc.io/en/vehicles/bmw-cardata). De MQTT-instellingen
171
+ hierboven zijn door uitproberen op echte hardware gevonden, en de veldkoppeling is
172
+ gecontroleerd aan de stream van een MINI Aceman SE (waaronder dat `stateOfCharge.target`,
173
+ niet `targetMin`, het laaddoel is).
174
+
175
+ ## Licentie
176
+
177
+ MIT — zie [LICENSE](LICENSE).
@@ -0,0 +1,136 @@
1
+ [
2
+ {
3
+ "id": "cardata-basic-tab",
4
+ "type": "tab",
5
+ "label": "CarData basic",
6
+ "disabled": false,
7
+ "info": "Fill in the account node (client ID, VIN), deploy once, then click \"Log in\" on it. Wire cardata-stream's first output (and cardata-target's output) into a victron-virtual (EV device) node for real VRM integration — see README."
8
+ },
9
+ {
10
+ "id": "cardata-basic-account",
11
+ "type": "cardata-account",
12
+ "name": "",
13
+ "clientId": "",
14
+ "vin": "",
15
+ "containerId": "",
16
+ "homeLat": "",
17
+ "homeLon": "",
18
+ "homeRadiusM": 150
19
+ },
20
+ {
21
+ "id": "cardata-basic-stream",
22
+ "type": "cardata-stream",
23
+ "z": "cardata-basic-tab",
24
+ "name": "",
25
+ "account": "cardata-basic-account",
26
+ "x": 240,
27
+ "y": 120,
28
+ "wires": [["cardata-basic-dbg-state", "cardata-basic-trips"], ["cardata-basic-dbg-unknown"]]
29
+ },
30
+ {
31
+ "id": "cardata-basic-dbg-state",
32
+ "type": "debug",
33
+ "z": "cardata-basic-tab",
34
+ "name": "state (wire this into victron-virtual)",
35
+ "active": true,
36
+ "tosidebar": true,
37
+ "console": false,
38
+ "tostatus": false,
39
+ "complete": "payload",
40
+ "targetType": "msg",
41
+ "statusVal": "",
42
+ "statusType": "auto",
43
+ "x": 520,
44
+ "y": 100,
45
+ "wires": []
46
+ },
47
+ {
48
+ "id": "cardata-basic-dbg-unknown",
49
+ "type": "debug",
50
+ "z": "cardata-basic-tab",
51
+ "name": "unknown fields",
52
+ "active": true,
53
+ "tosidebar": true,
54
+ "console": false,
55
+ "tostatus": false,
56
+ "complete": "payload",
57
+ "targetType": "msg",
58
+ "statusVal": "",
59
+ "statusType": "auto",
60
+ "x": 490,
61
+ "y": 160,
62
+ "wires": []
63
+ },
64
+ {
65
+ "id": "cardata-basic-target",
66
+ "type": "cardata-target",
67
+ "z": "cardata-basic-tab",
68
+ "name": "",
69
+ "account": "cardata-basic-account",
70
+ "intervalMinutes": 60,
71
+ "x": 240,
72
+ "y": 220,
73
+ "wires": [["cardata-basic-dbg-target"]]
74
+ },
75
+ {
76
+ "id": "cardata-basic-dbg-target",
77
+ "type": "debug",
78
+ "z": "cardata-basic-tab",
79
+ "name": "target SoC (wire this into victron-virtual too)",
80
+ "active": true,
81
+ "tosidebar": true,
82
+ "console": false,
83
+ "tostatus": false,
84
+ "complete": "payload",
85
+ "targetType": "msg",
86
+ "statusVal": "",
87
+ "statusType": "auto",
88
+ "x": 530,
89
+ "y": 220,
90
+ "wires": []
91
+ },
92
+ {
93
+ "id": "cardata-basic-trips",
94
+ "type": "cardata-trips",
95
+ "z": "cardata-basic-tab",
96
+ "name": "",
97
+ "filePath": "",
98
+ "x": 240,
99
+ "y": 300,
100
+ "wires": [["cardata-basic-dbg-trip"], ["cardata-basic-dbg-inprogress"]]
101
+ },
102
+ {
103
+ "id": "cardata-basic-dbg-trip",
104
+ "type": "debug",
105
+ "z": "cardata-basic-tab",
106
+ "name": "completed trip",
107
+ "active": true,
108
+ "tosidebar": true,
109
+ "console": false,
110
+ "tostatus": true,
111
+ "complete": "payload",
112
+ "targetType": "msg",
113
+ "statusVal": "payload.km",
114
+ "statusType": "jsonata",
115
+ "x": 500,
116
+ "y": 280,
117
+ "wires": []
118
+ },
119
+ {
120
+ "id": "cardata-basic-dbg-inprogress",
121
+ "type": "debug",
122
+ "z": "cardata-basic-tab",
123
+ "name": "trip in progress",
124
+ "active": false,
125
+ "tosidebar": true,
126
+ "console": false,
127
+ "tostatus": false,
128
+ "complete": "payload",
129
+ "targetType": "msg",
130
+ "statusVal": "",
131
+ "statusType": "auto",
132
+ "x": 500,
133
+ "y": 320,
134
+ "wires": []
135
+ }
136
+ ]