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
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>
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.
110136enum 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
206265void btCallback (esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
207266 #define MAXSTRDATALENGTH 80
@@ -249,6 +308,10 @@ void checkBTReceive() {
249308void 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
291354void 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