Skip to content

Commit ce9a790

Browse files
committed
Additional values
Add support for - HV PTC heater current - Outside temperature - Inside temperature - Cruising range - Charging state - CO2 content interior - GPS time - GPS height - GPS latitude - GPS longitude
1 parent 4acb8ad commit ce9a790

File tree

6 files changed

+401
-44
lines changed

6 files changed

+401
-44
lines changed

id3esp32obd2.aia

5.4 KB
Binary file not shown.

id3esp32obd2.apk

-344 KB
Binary file not shown.

id3esp32obd2/UDS.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ bool sendUDSRequest(unsigned long canID, byte serviceID, byte parameterIDHighByt
165165
case UDS_ServiceNotSupported_0x11:
166166
Serial.println("0x11 service not supported");
167167
break;
168+
case UDS_ResponsePending_0x78:
169+
Serial.println("0x78 request correctly received but response pending");
170+
continue; // No error, response should be received later
171+
break;
168172
default:
169173
Serial.println(rxMessage.data[3],HEX);
170174
}
@@ -240,7 +244,7 @@ bool sendUDSRequest(unsigned long canID, byte serviceID, byte parameterIDHighByt
240244
fcMessage.data[5] = 0x00;
241245
fcMessage.data[6] = 0x00;
242246
fcMessage.data[7] = 0x00;
243-
Serial.print("Send ");
247+
Serial.print("Send ");
244248
showMessage(&fcMessage);
245249
Serial.println();
246250
error = can_transmit(&fcMessage, pdMS_TO_TICKS(CAN_SEND_TIMEOUT));

id3esp32obd2/dashboards.ino

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
// First/starting dashboard
77
void requestDefaultDashboard(byte boardID) {
8+
// VIN
9+
checkBTReceive();
10+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
11+
readAndSendVIN();
12+
813
// Driving mode position
914
checkBTReceive();
1015
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
@@ -20,10 +25,20 @@ void requestDefaultDashboard(byte boardID) {
2025
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
2126
readAndSendODOMETER();
2227

23-
// VIN
28+
// Outside temperature
2429
checkBTReceive();
2530
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
26-
readAndSendVIN();
31+
readAndSendTemperatureOutside();
32+
33+
// Inside temperature
34+
checkBTReceive();
35+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
36+
readAndSendTemperatureInside();
37+
38+
// CO2 content interior
39+
checkBTReceive();
40+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
41+
readAndSendCO2contentInterior();
2742

2843
// Voltage for 12V battery from analog pin
2944
readAndSendBAT12V();
@@ -39,22 +54,33 @@ void requestSpeedDashboard() {
3954
readAndSendSpeed();
4055
}
4156

57+
// GPS dashboard
58+
void requestGPSDashboard(byte boardID) {
59+
checkBTReceive();
60+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
61+
readAndSendGPSTime();
62+
63+
checkBTReceive();
64+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
65+
readAndSendGPSData();
66+
}
67+
4268
// HV dashboard
4369
void requestHVDashboard(byte boardID) {
4470
// SOC (BMS)
4571
checkBTReceive();
4672
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
4773
readAndSendSOCBMS();
4874

49-
// HV auxilary consumer power
75+
// Charging state
5076
checkBTReceive();
5177
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
52-
readAndSendHVAuxilaryPower();
78+
readAndSendChargingState();
5379

54-
// HV Battery main temperature
80+
// CruisingRange
5581
checkBTReceive();
5682
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
57-
readAndSendHVMainTemperature();
83+
readAndSendCruisingRange();
5884

5985
// Circulation pump HV battery
6086
checkBTReceive();
@@ -76,24 +102,34 @@ void requestHVDashboard(byte boardID) {
76102
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
77103
readAndSendHVDynamicChargeLimit();
78104

105+
// HV Battery main temperature
106+
checkBTReceive();
107+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
108+
readAndSendHVMainTemperature();
109+
79110
// HV total charge/discharge
80111
checkBTReceive();
81112
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
82113
readAndSendHVTotalChargeDischarge();
83114

84-
// HV capacity
115+
// HV auxilary consumer power
116+
checkBTReceive();
117+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
118+
readAndSendHVAuxilaryPower();
119+
120+
// PTC heater battery
121+
checkBTReceive();
122+
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
123+
readAndSendPTCHeaterCurrent();
124+
125+
// HV capacity
85126
checkBTReceive();
86127
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
87128
readAndSendHVCapacity();
88129
}
89130

90131
// Custom dashboard
91132
void requestMyDashboard(byte boardID) {
92-
// VIN
93-
checkBTReceive();
94-
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard
95-
readAndSendVIN();
96-
97133
// SOC (BMS)
98134
checkBTReceive();
99135
if (boardID != g_requestDashboard) return; // Bluetooth client changed dashboard

id3esp32obd2/id3esp32obd2.ino

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
* - HV Total charge
1818
* - HV Total discharge
1919
* - HV battery capacity
20+
* - HV PTC heater current
21+
* - Outside temperature
22+
* - Inside temperature
23+
* - Cruising range
24+
* - Charging state
25+
* - CO2 content interior
26+
* - GPS time
27+
* - GPS height
28+
* - GPS latitude
29+
* - GPS longitude
2030
*
2131
* License: 2-Clause BSD License
2232
* Copyright (c) 2023 codingABI
@@ -52,6 +62,11 @@
5262
* https://github.com/nickn17/evDash/blob/master/src/CarVWID3.cpp
5363
* https://github.com/spot2000/Volkswagen-MEB-EV-CAN-parameters/blob/main/VW%20MEB%20UDS%20PIDs%20list.csv
5464
* https://www.meinid.com/thread/1640-obd2-header-pid-liste/
65+
*
66+
* History:
67+
* 20230626, Initial version
68+
* 20230712, Add support for "PTC heater current", "Outside temperature", "Inside temperature", "Cruising range", "Charging state", "CO2 content interior"
69+
* 20230719, Add support for "GPS time", "GPS height", "GPS latitude" and "GPS longitude", Sync ESP32 time with "GPS Time"
5570
*/
5671

5772
#include <driver/gpio.h>
@@ -74,6 +89,7 @@
7489
#define UDS_DiagnosticSessionControl_0x10 0x10
7590
#define UDS_ExtendedDiagnosticSession_0x03 0x03
7691
#define UDS_RequestOutOfRange_0x31 0x31
92+
#define UDS_ResponsePending_0x78 0x78
7793
#define UDS_ServiceNotSupported_0x11 0x11
7894
#define UDS_NegativeResponse_0x7f 0x7f
7995
#define UDS_PositiveResponseOffset_0x40 0x40
@@ -103,17 +119,31 @@ enum dataIDs {
103119
idHVCHARGINGLIMIT,
104120
idHVTOTALCHARGE,
105121
idHVTOTALDISCHARGE,
106-
idHVCAPACITY
122+
idHVCAPACITY,
123+
idPTCHEATERCURRENT,
124+
idTEMPERATUREOUTSIDE,
125+
idTEMPERATUREINSIDE,
126+
idCRUISINGRANGE,
127+
idCHARGINGSTATE,
128+
idCO2CONTENTINTERIOR,
129+
idGPSTIME,
130+
idGPSELE,
131+
idGPSLAT,
132+
idGPSLON
107133
};
108134

109135
// A dashboard is a set of car parameters. A Bluetooth client can request a dashboard.
110136
enum dashboards {
111137
DEFAULTDASHBOARD,
112138
SPEEDDASHBOARD,
113139
HVDASHBOARD,
114-
MYDASHBOARD
140+
MYDASHBOARD,
141+
GPSDASHBOARD
115142
};
116143

144+
// Timezone for Germany
145+
#define TIMEZONE "CET-1CEST,M3.5.0/02,M10.5.0/03"
146+
117147
// Pin definitions
118148
#define LED_PIN 2
119149
#define MEASURE12V_PIN 4
@@ -202,6 +232,35 @@ void beep(int type=DEFAULTBEEP) {
202232
}
203233
}
204234

235+
// Set time of esp
236+
void setEspTime(char *strTime) {
237+
#define MAXSTRDATALENGTH 80
238+
char strData[MAXSTRDATALENGTH+1];
239+
struct tm t;
240+
struct tm *ptrTimeinfo;
241+
time_t now;
242+
243+
if (strTime == NULL) return;
244+
setenv("TZ", "UTC+0", 1); // New time is in UTC
245+
tzset();
246+
if (strptime(strTime,"%Y-%m-%d %H:%M:%S", &t) != NULL) {
247+
time_t t_of_day = mktime(&t);
248+
struct timeval epoch;
249+
epoch.tv_sec = t_of_day; // epoch time (seconds)
250+
epoch.tv_usec = 0; // microseconds
251+
settimeofday((const timeval*)&epoch, 0);
252+
}
253+
254+
setenv("TZ", TIMEZONE, 1); // Change TZ back to local TZ
255+
tzset();
256+
257+
time(&now);
258+
ptrTimeinfo = localtime( &now );
259+
strftime(strData, MAXSTRDATALENGTH+1, "%Y-%m-%d %H:%M:%S", ptrTimeinfo);
260+
Serial.print("ESP32 local time: ");
261+
Serial.println(strData);
262+
}
263+
205264
// Bluetooth callback function
206265
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
207266
#define MAXSTRDATALENGTH 80
@@ -249,6 +308,10 @@ void checkBTReceive() {
249308
void setup() {
250309
Serial.begin(115200);
251310

311+
// Timezone
312+
setenv("TZ", TIMEZONE, 1);
313+
tzset();
314+
252315
// Pin modes
253316
pinMode(LED_PIN,OUTPUT);
254317
pinMode(MEASURE12V_PIN,INPUT);
@@ -289,6 +352,7 @@ void setup() {
289352
}
290353

291354
void loop() {
355+
292356
// Check Bluetooth before checking g_btAuthenticated to process the receive queue anyway
293357
checkBTReceive();
294358
if (!g_SerialBT.hasClient() && g_btAuthenticated) {
@@ -314,6 +378,9 @@ void loop() {
314378
case MYDASHBOARD:
315379
requestMyDashboard(g_requestDashboard);
316380
break;
381+
case GPSDASHBOARD:
382+
requestGPSDashboard(g_requestDashboard);
383+
break;
317384
default:
318385
Serial.print("Unknown dashboard requested ");
319386
Serial.println(g_requestDashboard);

0 commit comments

Comments
 (0)