Coder Social home page Coder Social logo

eqmod / rejsacan_obdweb Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 3.0 17.73 MB

A WEB Based OBDII Dongle Platform using the REJSACAN ESP32-S3 OBDII DONGLE

License: GNU General Public License v3.0

C++ 14.63% C 76.67% CSS 2.10% HTML 0.46% JavaScript 1.89% Batchfile 0.74% Assembly 3.51%
car esp32 obd obd-ii racing rejsacan web-obd web-server can-bus-communication canbus-communication

rejsacan_obdweb's Introduction

REJSACAN_OBDWEB

=== A WEB Based OBDII Dongle Platform using the REJSACAN ESP32-S3 OBDII DONGLE

A REJSACAN OBDII Dongle using the ESP32-S3 with built-in SPIFFF memory is used as a CAN BUS OBDII reader and the data is presented as WEB PAGE using a built-in webserver. The webpage code communicates to the dongle via WiFi and uses websockets to retrieve OBDII data. The platform is using an ESP32 microcontroller which is a dual core mcu with the first core handling the CAN Bus comunications part via SN65HVD230 CAN BUS Transceiver and the 2nd core handling the websocket part. OBDII data is pushed to the UI every 60ms to 100ms for critical data such as rpm and speed, and every 1000ms for not so critical data such as temp, voltage, etc.

The platform code is using ESP32 RTOS for the multi core multi tasking component. That's basically an OBDII with a webserver running inside that dongle which is attached to the car's obd port. And literally you can read every car metric data and show it on the car infotainment / Web browser / Phone app with customizable fancy UI stuff (gauges, graphs, etc.) using standard HTML/JS/CSS/JPG renders.

Any web browser client can connect to the dongle via WIFI with the OBD-II dongle acting as a Wifi Hotspot. Wifi credentials are embedded on the code.

You can add an OPTIONAL JDY08 BLE Module with its own embedded CC2541 micrcontroller ( CC2541 source code included in this repository) for other sensor data reception using BLE Advertisements. Simply drop the cc2541 binary file to the SD Card of the RejsaCAN and the built-in flash codes will burn it to the JDY08 module. Two sample JDY08 bin files are provided - one as VC601 BLE Tire Pressure Receiver/BM2 Battery Monitor (need to change IDs on the code) for TPMS Data and live battery stats (aside from the OBD Module voltage). The other cc2541.bin file is a HM10 BLE UART Bridge where you can use the JDY08 as an ELM327 to UART bridge for TORQUE app communications via BLE. Codes are also provided under the loop() function for a ELM327-WIFI based communication

Diagram_001 drawio

=== JDY08 and RejsaCAN v3.4 Board Connection Diagram

Diagram_002 drawio

=== Serial Console when a cc2541.bin file is present on the SD Card. File is flashed to the JDY08 module then deleted from the SD Card

image image

====================================

Webserver entry point / homepage is ;

http://192.168.0.10/index.html

The OBDII Dongle with the built-in ESP32-S3 micrcontroller is designed by Magnus Thome and details can be found here;

https://github.com/MagnusThome/RejsaCAN-ESP32

image

=== The WEB UI assets are stored on the REJSCAN Dongle's SD Card can be customized by a web designer/developer using HTML/JS/CSS/jpg assets;

Sample UIs;

image

image

Transparent UIs with a LIVE CAMERA FEED on the webpage background is also possible

image

image

=== Sample Browser side and Dongle Side SDCARD DocRoot files;

https://github.com/EQMOD/REJSACAN_OBDWEB/tree/main/Custom_USERS_WEBUI

https://github.com/EQMOD/REJSACAN_OBDWEB/tree/main/SDCARD

=== Compiling use the Arduino IDE;

REJSACAN_OBDWEB_DEV_ENVIRONMENT drawio

The codes is using the standard OBD-II Library (already included in this repository) with a little bit of customization from the original obdII Libraries-

Rewritten from sandeepmistry/arduino-OBD2 to instead depend on the ESP32 CAN libraries

https://github.com/collin80/esp32_can https://github.com/collin80/can_common

that support ESP32 with TWAI.

The code is also using the SDFat Library from Greiman. The SdFat library supports FAT16, FAT32, and exFAT file systems on Standard SD, SDHC, and SDXC cards.

https://github.com/greiman/SdFat

One Library file from SDFat needs to be modified in order for SDFat to work on the REJSACAN SD Card Slot;

image

This is a little bit tricky as you need to add the above entry on the SdFatConfig.h file each time you compile the above codes on the REJSACan Dongle and needs to be commented out if the above library will compiled with your other ESP32 based projects.

=== Suggested ARDUINO IDE settings for the compile and code upload/flashing which also include distributing the routines on the 2 cores;

image

PSRAM Size:

image

=== JDY08 Module customization

As mentioned you can add an OPTIONAL JDY08 mmodule with a Texas Instrument CC2541 BLE Chip. The CC2541 firmware can be customized (source code included here) using the IAR Development Environment which you will then create the cc2541.bin file for flashing to the JDY08 module. One sample use of the attached JDY08 is a realtime Serial Console Logger where you can monitor/debug your app on the dongle while attached to the car's OBD Port;

image

Sample Dongle codes here;

https://github.com/EQMOD/REJSACAN_OBDWEB/tree/main/src/RJA_OBDONLY_ESP32S3_JDY08_001

HM10 BLE UART Firmware file for the JDY-08

https://github.com/EQMOD/REJSACAN_OBDWEB/tree/main/JDY08_bin_src/HM10_BLE_UART

rejsacan_obdweb's People

Contributors

eqmod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rejsacan_obdweb's Issues

Cannot pass verification on new install

when I import the zip REJSACAN_OBDWEB-main.zip into Arduino 2.3.2 I get an Error: 13 INTERNAL: Library install failed: moving extracted archive to destination dir: library not valid

the file EQM_OBDWEB-main.zip imports without issues, not until sDfat is added does a base .ino file with only includes not show error about Sdfat. There are other errors so I ensure the device is configured in the settings and close out Arduino, I then copy all files from the REJSACAN_OBDWEB-main.zip into the directory where the library for EQM_OBDWEB-main.zip is located and now I'm here still without this running. Has all been updated on the .zip files?

this is no file

`

#include <WiFi.h>

#include "CANmod.h"
#include "OBD2_mod.h"

#define blinkDelay 50
#define numBlink 6

#define LEDPIN GPIO_NUM_2
#define CANRSPIN GPIO_NUM_4
#define CANRXPIN GPIO_NUM_36
//#define CANTXPIN GPIO_NUM_22

#define CANACTIVITYCOUNT 2
#define CANNOPACKETCOUNT 10

#define RXD2 GPIO_NUM_13 // ESP32 RX gpio for CC2541 TX pin
#define TXD2 GPIO_NUM_14 // ESP32 TX gpio for CC2541 RX pin (unused)
#define CC2541RST1 GPIO_NUM_27 // ESP32 gpio pin for CC2541 reset
#define CC2541Timeout 10 // Readtimeout per 100ms

#define OBDCMDSIZ 10
#define OBDREPSIZ 50

#define MILDUR_001 150
#define MILDUR_002 1000

const char* ssid = "RCSM_DB_OBD_DEBUG";
const char* password = "testpass";
WiFiServer wifiServer(35000);
WiFiClient client;

int clientflag = 0;

unsigned long prevmillis_001,prevmillis_002;

void store_BM2( float voltage);
void store_TPMS(unsigned long tireID, float pressure, float temperature, float voltage);
void startOBDServer();
void storePID(int pid, int ofst, int count, float val);
float GetPIDVal(int ofst);
void ws_timer();

// array of PID's to print values of
const int PIDS[] = {
ENGINE_RPM,
VEHICLE_SPEED,
THROTTLE_POSITION,
ENGINE_COOLANT_TEMPERATURE,
AIR_INTAKE_TEMPERATURE,
MAF_AIR_FLOW_RATE,
CALCULATED_ENGINE_LOAD,
CONTROL_MODULE_VOLTAGE,
RELATIVE_THROTTLE_POSITION,
CATALYST_TEMPERATURE_BANK_1_SENSOR_1
};

const int NUM_PIDS = sizeof(PIDS) / sizeof(PIDS[0]);

#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds /
#define TIME_TO_SLEEP 5 /
Time ESP32 will go to sleep (in seconds) */

const String ATE = "ATE"; // Echi
const String ATI = "ATI"; // Vid
const String ATZ = "ATZ"; // Reset
const String ATS = "ATS"; // Set proto
const String ATH0 = "ATH0"; // Headers OFF
const String ATH1 = "ATH1"; // Headers ON
const String ATL = "ATL"; // Linefeeds off/on
const String ATM = "ATM"; // Memory off/on
const String ATDPN = "ATDPN"; //Describe the Protocol by Number
const String ATDESC = "AT@1";
const String ATAT = "ATAT";
const String ATR = "ATR";
const String ATTP = "ATTP";

const char* LF = "\n";
const char* VERSION = "ELM327 v2.1";
const char* VERSION_DESC = "ESP32 ELM327 Interpreter";
const char* ATOK = "OK";
const char* PROMPT = ">";
const char* ISO15765_4 = "A6"; // ISO ISO 15765-4
const char* ATRVREP = "12.0"; // ISO ISO 15765-4

// Add a "Q" character in front to disable buffering (more realtime but with adapter readout delay vs cached)

const String REQ0100 = "Q0100";
const String REQ0120 = "Q0120";

const String REQ0105 = "0105";
const String REQ010C = "010C";
const String REQ010D = "010D";

const String REQ0111 = "0111";
const String REQ0142 = "0142";
const String REQ0143 = "0143";

String ELMClientStream = "";
String ELMClientStream_BLE = "";

QueueHandle_t queue_T0s;
QueueHandle_t queue_T0r;
QueueHandle_t queue_T1s;
QueueHandle_t queue_T1r;

uint8_t OBD_headerflag = 0;

void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();

switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}

void TimerTask(void * parameter){
for(;;){ // infinite loop
ws_timer();
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}

void blink_ok()
{
int i;

digitalWrite(LEDPIN, LOW);
delay(blinkDelay);
for(i=0;i<numBlink;i++)
{
    delay(blinkDelay);
    digitalWrite(LEDPIN, HIGH);
    delay(blinkDelay);
    digitalWrite(LEDPIN, LOW);
}

}

void ELM_AT(String command, int procID, char ptr[]) {

int i,j, numline;

uint32_t pidData;
uint8_t b1,b2,b3,b4;
char reply0[OBDREPSIZ];
char reply1[OBDREPSIZ];

ptr[0]=0;

if (command.equals(ATZ)) { ptr+=sprintf(ptr,VERSION);ptr+=sprintf(ptr,LF);ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATE)) { ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATI)) { ptr+=sprintf(ptr,VERSION);ptr+=sprintf(ptr,LF);ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATDESC)) { ptr+=sprintf(ptr,VERSION);ptr+=sprintf(ptr,LF);ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATL)) { ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATAT)) { ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATTP)) { ptr+=sprintf(ptr,ATOK);}
else if (command.startsWith(ATH0)) {
OBD_headerflag = 0;
ptr+=sprintf(ptr,ATOK);
}
else if (command.startsWith(ATH1)) {
OBD_headerflag = 1;
ptr+=sprintf(ptr,ATOK);
}
else if (command.startsWith(ATM)) { ptr+=sprintf(ptr,ATOK); }
else if (command.startsWith(ATR)) { ptr+=sprintf(ptr,ATRVREP); }
else if (command.startsWith(ATS)) { ptr+=sprintf(ptr,ATOK); }
else if (command.startsWith(ATDPN)) { ptr+=sprintf(ptr,ISO15765_4);}
else if (command.startsWith(REQ0143)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 04 ",0x7e8);
ptr+=sprintf(ptr,"41 43 00 %02x",(int)GetPIDVal(6) &0xff);
}
else if (command.startsWith(REQ010C)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 04 ",0x7e8);
ptr+=sprintf(ptr,"41 0C %02x %02x",((int)(GetPIDVal(0)*4) >> 8) & 0xff,((int)GetPIDVal(0)*4) &0xff);
}
else if (command.startsWith(REQ010D)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
ptr+=sprintf(ptr,"41 0D %02x",(int)GetPIDVal(1) &0xff);
}
else if (command.startsWith(REQ0105)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
ptr+=sprintf(ptr,"41 05 %02x",(int)(GetPIDVal(3)+40) &0xff) ;
}
else if (command.startsWith(REQ0142)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 04 ",0x7e8);
ptr+=sprintf(ptr,"41 42 %02x %02x",((int)(GetPIDVal(7)*1000) >> 8) & 0xff,((int)GetPIDVal(7)*4) &0xff) ;
}
else if (command.startsWith(REQ0111)) {
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
ptr+=sprintf(ptr,"41 11 %02x",(int)(GetPIDVal(2)*2.55) &0xff) ;
}
else if (command.startsWith("AT")) { ptr+=sprintf(ptr,ATOK); } // Reply with the rest of AT Commands to OK
else if (command.indexOf("AT") == -1) {

if ((command.length() > 2) && (command[0] >= 0x30))
{
if (procID)
{
xQueueSend(queue_T1s,&command,(TickType_t )0);
if ( xQueueReceive(queue_T1r,&reply1,(TickType_t )(3000/portTICK_PERIOD_MS)))
{
if (reply1[0] !=0 )
{
if (OBD_headerflag)
ptr+=sprintf(ptr,"%03x 04 ",0x7e8);
ptr+=sprintf(ptr,"41 %c%c ", command[2],command[3]);

                for(i=0;i<reply1[0];i++)    
                {
                  if((i+1)<reply1[0])
                      ptr+=sprintf(ptr,"%02x ", reply1[i+1]);
                  else
                     ptr+=sprintf(ptr,"%02x", reply1[i+1]);
                }
              }
              else
              {
                  if (OBD_headerflag)
                     ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
                  ptr+=sprintf(ptr,"41 %c%c 00",command[2],command[3]);
              }
        }
        else // If not response after 1000 ms, make a default reply
        {
          if (OBD_headerflag)
             ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
          ptr+=sprintf(ptr,"41 %c%c 00",command[2],command[3]);
        }
  }
  else
  {
        xQueueSend(queue_T0s,&command,(TickType_t )0);
        if ( xQueueReceive(queue_T0r,&reply0,(TickType_t )(3000/portTICK_PERIOD_MS)))
        {
              if (reply0[0] !=0 )
              {
                if (OBD_headerflag)
                  ptr+=sprintf(ptr,"%03x 04 ",0x7e8);
                ptr+=sprintf(ptr,"41 %c%c ", command[2],command[3]);
              
                for(i=0;i<reply0[0];i++)    
                {
                  if((i+1)<reply0[0])
                    ptr+=sprintf(ptr,"%02x ", reply0[i+1]);
                  else
                    ptr+=sprintf(ptr,"%02x", reply0[i+1]);
                }
              }
              else
              {
                  if (OBD_headerflag)
                     ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
                  ptr+=sprintf(ptr,"41 %c%c 00",command[2],command[3]);
              }
         }
        else // If not response after 1000 ms, make a default reply
        {
          if (OBD_headerflag)
             ptr+=sprintf(ptr,"%03x 03 ",0x7e8);
          ptr+=sprintf(ptr,"41 %c%c 00",command[2],command[3]);
        }
  }
}

}
ptr+=sprintf(ptr,LF);
ptr+=sprintf(ptr,PROMPT);
*ptr++ = 0;
}

void GetPIDs(int ofst) {

int pid;
pid = PIDS[ofst];

// Serial.print("_");
float pidValue = (float) OBD2mod.pidRead(pid);

//   Serial.print(".");

if (pid == 12)
{
if (isnan(pidValue))
{
delay(1000);
pidValue = (float) OBD2mod.pidRead(pid);
if (isnan(pidValue))
{
CANmod.end();
ESP.restart(); // Force boot

        }
   } 
}

if (!isnan(pidValue))
storePID(pid, ofst, NUM_PIDS, pidValue);
vTaskDelay(2 / portTICK_PERIOD_MS);
}

void obd_task(void * parameter){

unsigned long curmillis;
char cmd[OBDCMDSIZ];
char reply[OBDREPSIZ];
char * rrdata = reply;
char obdbuf[OBDREPSIZ];
int i,len;

char strval[5];

for(;;){ // infinite loop

curmillis = millis();
if ((curmillis - prevmillis_001)> MILDUR_001)
{
  GetPIDs(0);
  GetPIDs(1);
  GetPIDs(2);
  prevmillis_001 = curmillis;
}
if ((curmillis - prevmillis_002)> MILDUR_002)
{    
  digitalWrite(LEDPIN, HIGH);
  for (int i = 3; i < NUM_PIDS; i++)
      GetPIDs(i);
  prevmillis_002 = curmillis;
  digitalWrite(LEDPIN, LOW);
}

if (xQueueReceive(queue_T0s,&cmd,(TickType_t )(5/portTICK_PERIOD_MS)))
{
    sprintf(strval,"%c%c",cmd[0],cmd[1]);
    uint8_t pidmode = strtol(strval, NULL, 16);
    sprintf(strval,"%c%c",cmd[2],cmd[3]);
    uint8_t pidval = strtol(strval, NULL, 16);
  //  curmillis = millis();
    len = OBD2mod.pidReadPUB(pidmode, pidval, &obdbuf, 4);
   // Serial.printf("CAN Read:[%05d] Len: %02d Cmd: %s Reply: %02x %02x %02x %02x \n",millis()-curmillis,len,cmd, obdbuf[0],obdbuf[1],obdbuf[2],obdbuf[3]);
    reply[0] = len;
    for(i=0;i<len;i++)
       reply[i+1] = obdbuf[i];
    reply[i] = 0;
    xQueueSend(queue_T0r,&reply,(TickType_t )0);
}
if (xQueueReceive(queue_T1s,&cmd,(TickType_t )(5/portTICK_PERIOD_MS)))
{
    sprintf(strval,"%c%c",cmd[0],cmd[1]);
    uint8_t pidmode = strtol(strval, NULL, 16);
    sprintf(strval,"%c%c",cmd[2],cmd[3]);
    uint8_t pidval = strtol(strval, NULL, 16);
  //  curmillis = millis();
    len = OBD2mod.pidReadPUB(pidmode, pidval, &obdbuf, 4);
  //  Serial.printf("CAN Read:[%05d] Len: %02d Cmd: %s\n",millis()-curmillis,len,cmd);
    reply[0] = len;
    for(i=0;i<len;i++)
       reply[i+1] = obdbuf[i];
    reply[i] = 0;
    xQueueSend(queue_T1r,&reply,(TickType_t )0);
}
vTaskDelay(50 / portTICK_PERIOD_MS);

}
}

void elm_BLEtask(void * parameter){

static char buf[1024];
char c;
unsigned long curmillis;

for(;;){ // infinite loop

while (Serial2.available()) {
c = Serial2.read();
if ((c == '\n' || c == '\r') && ELMClientStream_BLE.length() > 0) {
ELMClientStream_BLE.toUpperCase();
// curmillis = millis();
ELM_AT(ELMClientStream_BLE, 0,(char *) buf );
// Serial.printf("Duration:[%05d] CMD: %s Reply: %s",millis()-curmillis,ELMClientStream_BLE,buf);
Serial2.print(buf);
ELMClientStream_BLE = "";
} else if (c != ' ' && c != '\n' && c !='\r') {
ELMClientStream_BLE += c;
}

 vTaskDelay(1 / portTICK_PERIOD_MS);

}

vTaskDelay(10 / portTICK_PERIOD_MS);

}
}

void Vc601_BLEtask(void * parameter){

char tbuf[30];
char inp;
int i,len;
int timout;

long tmpval,tmpval2,tmpval3,event;
double pressure;
double temperature;
double voltage;
double prevoltage = 0;
double prevoltage2 = 0;
int bm2count = 0;

for(;;){ // infinite loop

while (Serial2.available()) {
inp = Serial2.read();

if (inp == 0xfe)
{
    len = Serial2.read();
    if (len == 15)
    {
      for(i = 0;i<len;i++)
      {
          timout = 0;
          while ((!Serial2.available()) && (timout < CC2541Timeout))
          {
              timout++;
              vTaskDelay(100 / portTICK_PERIOD_MS);
          }
          if (timout >= CC2541Timeout)
          {
              Serial.println("CC2541 Timeout Error");
              goto skip;  // Abort Loop - This will happen only if we did not get the 15 byte data
          }
          tbuf[i] = Serial2.read();
          vTaskDelay(1 / portTICK_PERIOD_MS);
      }

      if ((tbuf[3] == 0xca) && (tbuf[4] == 0xEA))
      {

        tmpval = 0;
        tmpval2 = 0;
        tmpval3 = 0;
	
        memcpy(&tmpval,  tbuf+6, 4);
        memcpy(&tmpval2, tbuf+10,4);
        memcpy(&tmpval3, tbuf+14,1);
        pressure =    (double) ((tmpval / 100000.00) * 14.5);
        temperature = (double) (tmpval2 / 100.00);

        if ((tmpval3 >= 0) && (tmpval3 <= 4))
          voltage  = (((double) (((((((tmpval3 + 0) << 16) / 4) * 224) >> 16) + 1136) / 2)) / 1023.0) * 3.6;
        if ((tmpval3 >= 5) && (tmpval3 <= 28))
          voltage  = (((double) (((((((tmpval3 - 4) << 16) / 24) * 224) >> 16) + 1360) / 2)) / 1023.0) * 3.6;
        if ((tmpval3 >= 29) && (tmpval3 <= 100))
          voltage  = (((double) (((((((tmpval3 - 28) << 16) / 72) * 121) >> 16) + 1584) / 2)) / 1023.0) * 3.6;
            
//        Serial.printf("TPMS Broadcast - Sensor[%x]: ",tbuf[05] & 0xf);        
//        for(i=0;i<6;i++)
//          Serial.printf("%02x ",tbuf[i]);        
//        Serial.printf(" - Pressure: %5.2f psi, Temperature: %5.2f degC, Sensor Voltage: %4.2f V\n",pressure,temperature,voltage);

      store_TPMS( (tbuf[2] << 16)+(tbuf[1] << 8)+tbuf[0], pressure, temperature, voltage);

      }
      else
      {
        bm2count++;

        voltage = (double)(( (double)(tbuf[6]+(tbuf[7] << 8)) / 304.16) -7.1282 + 0.06);

        if (bm2count > 2)
        store_BM2(voltage);

  //      Serial.printf("BM2 Broadcast  -          : ");        
  //      for(i=0;i<6;i++)
  //        Serial.printf("%02x ",tbuf[i]);        
  //      Serial.printf(" - %02x%02x == %02f Volts\n",tbuf[7],tbuf[6],(voltage+prevoltage+prevoltage2)/3);

        prevoltage2 = prevoltage;
        prevoltage = voltage;

      }

    }
}
else
  Serial.print(inp);

skip:

vTaskDelay(10 / portTICK_PERIOD_MS);

}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
/*
void elm_WIFItask(void * parameter){

static char buf[1024];
char c;
unsigned long curmillis;

for(;;){ // infinite loop

client = wifiServer.available();

if (client) {

while (client.connected()) {
clientflag = 1;

while (client.available()) {
c = client.read();
if ((c == '\n' || c == '\r') && ELMClientStream.length() > 0) {
ELMClientStream.toUpperCase();
// curmillis = millis();
ELM_AT(ELMClientStream, 1,(char *) buf );
// Serial.printf("Duration:[%05d] CMD: %s Reply: %s",millis()-curmillis,ELMClientStream,buf);
client.print(buf);
ELMClientStream = "";
} else if (c != ' ' && c != '\n' && c !='\r') {
ELMClientStream += c;
}

vTaskDelay(1 / portTICK_PERIOD_MS);
}

  vTaskDelay(1 / portTICK_PERIOD_MS);
}
//else
if (clientflag)
{
  client.stop();
  Serial.println("Client disconnected");
  clientflag = 0;
}

}
vTaskDelay(1 / portTICK_PERIOD_MS);
}
}

*/

void CAN_Sniff()
{

int actv,noactv;

CANmod.begin(500E3);
CANmod.observe();
actv = 0;
noactv = 0;
do {

 if (CANmod.parsePacket() > 0)
 { 
    //Serial.println(CANmod.packetId(), HEX);
    while (CANmod.available()) {
       CANmod.read();
  }
    actv++;
    noactv = 0;
 }
else
{
   noactv++;
    if (noactv > CANNOPACKETCOUNT)
    {
        CANmod.end();
        Serial.printf("No OBD Activity -- ");
        esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // ESP32 wakes up every 5 seconds
        Serial.println("Sleeping for 5 seconds in POWER SAVE MODE ...");
        Serial.flush(); 
        esp_light_sleep_start();
        
        // Not sure really if this part is needed.
        // This is just to ensure that least power is consumed during the CAN Bus Polling
        
        pinMode(CANRSPIN,OUTPUT);
        digitalWrite(CANRSPIN, HIGH);
        
        pinMode(CC2541RST1, OUTPUT);
        digitalWrite(CC2541RST1, LOW);

        CANmod.begin(500E3);
        CANmod.observe();
        actv = 0;
        noactv = 0;

        //ESP.restart();
    }
}
  vTaskDelay(200 / portTICK_PERIOD_MS);

}
while(actv < CANACTIVITYCOUNT);
CANmod.end();
Serial.println("CAN BUS activity detected ... Starting OBD2 in 5secs ...");
delay(5000);
pinMode(CANRSPIN,INPUT);
digitalWrite(CC2541RST1, HIGH);

}

void setup() {

int actv,noactv;

// Put the CAN Transceiver in LISTEN MODE to avoid CAR ECU errors
pinMode(CANRSPIN,OUTPUT);
digitalWrite(CANRSPIN, HIGH);

pinMode(CC2541RST1, OUTPUT);
digitalWrite(CC2541RST1, LOW);

Serial.begin(115200);
//Serial.println("AT+BAUD8");

while (!Serial);
Serial.setDebugOutput(true);
pinMode(LEDPIN, OUTPUT);
digitalWrite(LEDPIN, LOW);
CANmod.setPins(CANRXPIN, CANTXPIN);

// blink_ok();

CAN_Sniff();

while (true) {
Serial.print(F("Attempting to connect to OBD2 CAN bus ... "));

if (!OBD2mod.begin()) {
      Serial.println(F("failed!"));
     // print_wakeup_reason();
      esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // ESP32 wakes up every 5 seconds
      Serial.println("Sleeping for 5 seconds in POWER SAVE MODE ...");
      Serial.flush(); 
      esp_light_sleep_start();
      //esp_deep_sleep_start();
      print_wakeup_reason(); //Print the wakeup reason for ESP32


} else
{
      Serial.println(F("success"));
      break;
}

}

Serial2.begin(115200,SERIAL_8N1,RXD2,TXD2);

//Serial2.print("AT+BAUD9");
// Serial2.print("AT+NAMERCS_BLE");
WiFi.softAPConfig(IPAddress(192, 168, 0, 10), IPAddress(192, 168, 0, 10), IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
wifiServer.begin();

Serial.println();
startOBDServer();

blink_ok();

Serial.printf("Total heap: %d\n", ESP.getHeapSize());
Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize());
Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());

Serial.print("OBDII Ready! Use 'http://");
Serial.print(IP);
Serial.println("' to connect");

// Create the the OBD Queues

queue_T0s = xQueueCreate(2,OBDCMDSIZ);
queue_T0r = xQueueCreate(2,OBDREPSIZ);
queue_T1s = xQueueCreate(2,OBDCMDSIZ);
queue_T1r = xQueueCreate(2,OBDREPSIZ);

// Create the tasks

xTaskCreatePinnedToCore(
TimerTask, // Function that should be called
"WsTimerTask", // Name of the task (for debugging)
5000, // Stack size (bytes)
NULL, // Parameter to pass
1 | portPRIVILEGE_BIT, // Task priority
NULL, // Task handle
1
);

prevmillis_001 = 0;
prevmillis_002 = 0;

xTaskCreatePinnedToCore(
obd_task, // Function that should be called
"OBDTimerTask", // Name of the task (for debugging)
7000, // Stack size (bytes)
NULL, // Parameter to pass
1 | portPRIVILEGE_BIT, // Task priority
NULL, // Task handle
1
);

// Uncomment Below to Activate ELm327 on BLE JDY08 with HM10 or JDY08 original firmware
// Need to comment Vc601_BLEtask below if ele_BLEtask is uncommented

/*
xTaskCreatePinnedToCore(
elm_BLEtask, // Function that should be called
"OBDBLETask", // Name of the task (for debugging)
7000, // Stack size (bytes)
NULL, // Parameter to pass
1 | portPRIVILEGE_BIT, // Task priority
NULL, // Task handle
1
);
*/

xTaskCreatePinnedToCore(
Vc601_BLEtask, // Function that should be called
"OBDBLETask", // Name of the task (for debugging)
7000, // Stack size (bytes)
NULL, // Parameter to pass
1 | portPRIVILEGE_BIT, // Task priority
NULL, // Task handle
1
);

/*
xTaskCreatePinnedToCore(
elm_WIFItask, // Function that should be called
"OBDWIFITask", // Name of the task (for debugging)
7000, // Stack size (bytes)
NULL, // Parameter to pass
1 | portPRIVILEGE_BIT, // Task priority
NULL, // Task handle
1
);

*/

// Reset the CC2541 at Serial initialization to allow the ESP32 to get the init message

delay(500);
digitalWrite(CC2541RST1, LOW);
delay(500);
digitalWrite(CC2541RST1, HIGH);

}

void loop() {

static char buf[1024];
char c;
unsigned long curmillis;

client = wifiServer.available();

if (client) {

while (client.connected()) {
clientflag = 1;

while (client.available()) {
c = client.read();
if ((c == '\n' || c == '\r') && ELMClientStream.length() > 0) {
ELMClientStream.toUpperCase();
// curmillis = millis();
ELM_AT(ELMClientStream, 1,(char *) buf );
// Serial.printf("Duration:[%05d] CMD: %s Reply: %s",millis()-curmillis,ELMClientStream,buf);
client.print(buf);
ELMClientStream = "";
} else if (c != ' ' && c != '\n' && c !='\r') {
ELMClientStream += c;
}

}
vTaskDelay(1 / portTICK_PERIOD_MS);
}

if (clientflag)
{
client.stop();
Serial.println("Client disconnected");
clientflag = 0;
}
}

vTaskDelay(1 / portTICK_PERIOD_MS);

}`

this is error
`D:\ser6MAX\Documents\Arduino\sketch_may20a\sketch_may20a.ino: In function 'void setup()':
D:\ser6MAX\Documents\Arduino\sketch_may20a\sketch_may20a.ino:14:18: error: 'GPIO_NUM_22' was not declared in this scope
#define CANTXPIN GPIO_NUM_22
^~~~~~~~~~~
D:\ser6MAX\Documents\Arduino\sketch_may20a\sketch_may20a.ino:649:28: note: in expansion of macro 'CANTXPIN'
CANmod.setPins(CANRXPIN, CANTXPIN);
^~~~~~~~
D:\ser6MAX\Documents\Arduino\sketch_may20a\sketch_may20a.ino:14:18: note: suggested alternative: 'GPIO_NUM_42'
#define CANTXPIN GPIO_NUM_22
^~~~~~~~~~~
D:\ser6MAX\Documents\Arduino\sketch_may20a\sketch_may20a.ino:649:28: note: in expansion of macro 'CANTXPIN'
CANmod.setPins(CANRXPIN, CANTXPIN);
^~~~~~~~

exit status 1

Compilation error: 'GPIO_NUM_22' was not declared in this scope`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.