Giter Club home page Giter Club logo

esp32-obd2-emulator's Introduction

ESP32 OBD-II Emulator

Open-source OBD-II emulator based on an ESP32 + CAN transceiver IC, controllable via WiFi through a simple web UI (or via API).

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

Supported protocols

  • ISO 15765-4 CAN (11 bit, 500 Kbps)

Supported modes & PIDs

Mode PID Description
0x01 0x0C RPM
0x01 0x0D Vehicle speed
0x01 0x11 Throttle position
0x09 0x02 Vehicle Identification Number (VIN)

Usage

  1. Connect to the WiFi network ESP32-OBD2 (with password 88888888)
  2. Navigate to 192.168.4.1
  3. Enjoy :)

Hardware

  • ESP32-WROOM-32
  • SN65HVD230 (or any other CAN transceiver IC)
  • Serial->USB adapter
  • Power supply (3.3V)

ESP32-WROOM-32 SN65HVD230 Schematic

Connections

  • IO 4 -> CAN RX
  • IO 5 -> CAN TX

Flash / Install (via esptool)

  1. Download the latest release binaries
  2. Flash (app, bootloader, FAT filesystem): esptool.py write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x10000 obd2-emu.bin 0x8000 partitions.bin 0x110000 fatfs_image.img

Build

  1. Install the Espressif IoT Development Framework
  2. Clone this repo: git clone ...
  3. (Optional) Configure: make menuconfig
  4. Build: make all
  5. Flash: make flash
  6. Build & flash FAT image: make flashfatfs

Note: You might want to change some config values, for example: serial flasher, baud rate, pins, etc.

API

PATCH /api/vehicle

  • Content-Type: x-www-form-urlencoded
  • Data:
    • name
      • speed
      • rpm
      • throttle
      • vin
    • value
  • Example (CURL): curl -XPATCH -H 'Content-Type: application/x-www-form-urlencoded' -d 'name=speed&value=50' '/api/vehicle'

Acknowledgements

esp32-obd2-emulator's People

Contributors

limiter121 avatar

Stargazers

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

Watchers

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

esp32-obd2-emulator's Issues

How to read the logs?

Hello guys! Amazing project! One bullet point which I just can't get is: how to read the logs? I've deployed it at ESP32 microcontroller but unfortunately, I'm not able to read its data. Some unknown issue is happening.

How can I check if the data is being transmitted properly?

Thanks!

Problem with http_server.h and type definitions

Hi, I found something that could be a problem to others (I spent all my afternoon in order to fix this), which is: Running the makefile all everything worked fine until a warning appeared saying: http_server.h has been renamed to esp_http_server.h. Then several errors showed various unknow types that supposed to be defined in http_server.h. I figured out that, for some reason, instead of including http_server.h from .../project_file/components/http/http_server.h it included the http_server.h from ~/esp/esp-idf/components/esp_http_server/include/http_server.h. Thus, it could not recognize the types defined in this header file (http_server.h). I attached the output errors below.

Error_makefile_all.txt

The way that I found to solve the problem was copying the folder http from .../project_file/components/ to .../project_file/main/ and editing line 11 of can_demo_main.c from #include "http_server.h" to #include "http/http_server.h"

Maybe redefining the includes in some way can solve the problem, but I don't have the knowledge to do so (still learning how to program properly).

Build error

C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c: In function 'respondToOBD1':
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:123:34: warning: passing argument 2 of 'obdRevC                           onvert_0C' from incompatible pointer type [-Wincompatible-pointer-types]
    obdRevConvert_0C(vehicle_rpm, &response.data.u8[3], &response.data.u8[4], 0, 0);
                                  ^
In file included from C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:13:0:
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/obd.h:51:5: note: expected 'unsigned int *' but argument is of                            type 'uint8_t * {aka unsigned char *}'
 int obdRevConvert_0C    (float val, unsigned int *A, unsigned int *B, unsigned int *C, unsigned int *D);
     ^
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:123:56: warning: passing argument 3 of 'obdRevC                           onvert_0C' from incompatible pointer type [-Wincompatible-pointer-types]
    obdRevConvert_0C(vehicle_rpm, &response.data.u8[3], &response.data.u8[4], 0, 0);
                                                        ^
In file included from C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:13:0:
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/obd.h:51:5: note: expected 'unsigned int *' but argument is of                            type 'uint8_t * {aka unsigned char *}'
 int obdRevConvert_0C    (float val, unsigned int *A, unsigned int *B, unsigned int *C, unsigned int *D);
     ^
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:127:36: warning: passing argument 2 of 'obdRevC                           onvert_0D' from incompatible pointer type [-Wincompatible-pointer-types]
    obdRevConvert_0D(vehicle_speed, &response.data.u8[3], 0, 0, 0);
                                    ^
In file included from C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:13:0:
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/obd.h:52:5: note: expected 'unsigned int *' but argument is of                            type 'uint8_t * {aka unsigned char *}'
 int obdRevConvert_0D    (float val, unsigned int *A, unsigned int *B, unsigned int *C, unsigned int *D);
     ^
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:131:39: warning: passing argument 2 of 'obdRevC                           onvert_11' from incompatible pointer type [-Wincompatible-pointer-types]
    obdRevConvert_11(vehicle_throttle, &response.data.u8[3], 0, 0, 0);
                                       ^
In file included from C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:13:0:
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/obd.h:56:5: note: expected 'unsigned int *' but argument is of                            type 'uint8_t * {aka unsigned char *}'
 int obdRevConvert_11    (float val, unsigned int *A, unsigned int *B, unsigned int *C, unsigned int *D);
     ^
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c: In function 'get_type_for_filename_ext':
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:270:14: warning: initialization discards 'const                           ' qualifier from pointer target type [-Wdiscarded-qualifiers]
  char *ext = get_filename_ext(filename);
              ^
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c: In function 'app_main':
C:/msys32/home/X220/esp/esp-idf/examples/esp32-obd2-emulator/main/can_demo_main.c:389:12: warning: unused variable 'res' [-Wunuse                           d-variable]
  esp_err_t res;
            ^

Possibly due to new version of IDF?

Install problem

/home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:282:25: error: unknown type name 'http_context_t'; did you mean 'httpd_config_t'? static void cb_GET_file(http_context_t http_ctx, void *ctx) ^~~~~~~~~~~~~~ httpd_config_t /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:297:30: error: unknown type name 'http_context_t'; did you mean 'httpd_config_t'? static void cb_PATCH_vehicle(http_context_t http_ctx, void* ctx) ^~~~~~~~~~~~~~ httpd_config_t /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c: In function 'wifi_init_softap': /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:331:2: warning: 'esp_event_loop_init' is deprecated [-Wdeprecated-declarations] ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL)); ^~~~~~~~~~~~~~~ In file included from /home/user/esp/esp-idf/components/esp_event/include/esp_event.h:26, from /home/user/esp/esp-idf/components/esp_wifi/include/esp_wifi.h:64, from /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:3: /home/user/esp/esp-idf/components/esp_event/include/esp_event_legacy.h:227:11: note: declared here esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated)); ^~~~~~~~~~~~~~~~~~~ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c: In function 'app_main': /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:387:2: error: unknown type name 'http_server_t'; did you mean 'http_parser_h'? http_server_t server; ^~~~~~~~~~~~~ http_parser_h /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:388:2: error: unknown type name 'http_server_options_t'; did you mean 'dhcps_options_t'? http_server_options_t http_options = HTTP_SERVER_OPTIONS_DEFAULT(); ^~~~~~~~~~~~~~~~~~~~~ dhcps_options_t /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:388:39: error: implicit declaration of function 'HTTP_SERVER_OPTIONS_DEFAULT' [-Werror=implicit-function-declaration] http_server_options_t http_options = HTTP_SERVER_OPTIONS_DEFAULT(); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/user/esp/esp-idf/components/esp_common/include/esp_timer.h:44, from /home/user/esp/esp-idf/components/freertos/include/freertos/portmacro.h:84, from /home/user/esp/esp-idf/components/freertos/include/freertos/portable.h:94, from /home/user/esp/esp-idf/components/freertos/include/freertos/FreeRTOS.h:105, from /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:1: /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:391:18: error: implicit declaration of function 'http_server_start'; did you mean 'httpd_start'? [-Werror=implicit-function-declaration] ESP_ERROR_CHECK(http_server_start(&http_options, &server)); ^~~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:392:18: error: implicit declaration of function 'http_register_handler'; did you mean 'httpd_register_err_handler'? [-Werror=implicit-function-declaration] ESP_ERROR_CHECK(http_register_handler(server, "/", HTTP_GET, HTTP_HANDLE_RESPONSE, &cb_GET_file, "/spiflash/index.html")); ^~~~~~~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:392:63: error: 'HTTP_HANDLE_RESPONSE' undeclared (first use in this function); did you mean 'HTTP_RESPONSE'? ESP_ERROR_CHECK(http_register_handler(server, "/", HTTP_GET, HTTP_HANDLE_RESPONSE, &cb_GET_file, "/spiflash/index.html")); ^~~~~~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:392:63: note: each undeclared identifier is reported only once for each function it appears in ESP_ERROR_CHECK(http_register_handler(server, "/", HTTP_GET, HTTP_HANDLE_RESPONSE, &cb_GET_file, "/spiflash/index.html")); ^~~~~~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:392:86: error: 'cb_GET_file' undeclared (first use in this function) ESP_ERROR_CHECK(http_register_handler(server, "/", HTTP_GET, HTTP_HANDLE_RESPONSE, &cb_GET_file, "/spiflash/index.html")); ^~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:395:18: error: implicit declaration of function 'http_register_form_handler'; did you mean 'httpd_register_err_handler'? [-Werror=implicit-function-declaration] ESP_ERROR_CHECK(http_register_form_handler(server, "/api/vehicle", HTTP_PATCH, HTTP_HANDLE_RESPONSE, &cb_PATCH_vehicle, NULL)); ^~~~~~~~~~~~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:395:104: error: 'cb_PATCH_vehicle' undeclared (first use in this function) ESP_ERROR_CHECK(http_register_form_handler(server, "/api/vehicle", HTTP_PATCH, HTTP_HANDLE_RESPONSE, &cb_PATCH_vehicle, NULL)); ^~~~~~~~~~~~~~~~ /home/user/esp/esp-idf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK' esp_err_t __err_rc = (x); \ ^ /home/user/esp/obd/esp32-obd2-emulator/main/can_demo_main.c:389:12: warning: unused variable 'res' [-Wunused-variable] esp_err_t res; ^~~ cc1: some warnings being treated as errors make[1]: *** [/home/user/esp/esp-idf/make/component_wrapper.mk:292: can_demo_main.o] Ошибка 1 make: *** [/home/user/esp/esp-idf/make/project.mk:609: component-main-build] Ошибка 2

Can't build code

Hi, I am unable to build code, always getting the following error

C:\Users\edvar\Desktop\esp-idf-2\examples\emu>idf.py build
Checking Python dependencies...
Python requirements from C:\Users\edvar\Desktop\esp-idf-2\requirements.txt are satisfied.
Executing action: all (aliases: build)
Running ninja in directory c:\users\edvar\desktop\esp-idf-2\examples\emu\build
Executing "ninja all"...
[1/5] Performing build step for 'bootloader'
ninja: no work to do.
[2/3] Linking CXX executable emu.elf
FAILED: emu.elf
cmd.exe /C "cd . && C:\Users\edvar.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address -nostdlib @CMakeFiles\emu.elf.rsp -o emu.elf && cd ."
c:/users/edvar/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/esp32/libesp32.a(cpu_start.c.obj):(.literal.main_task+0x18): undefined reference to app_main' c:/users/edvar/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/esp32/libesp32.a(cpu_start.c.obj): in function main_task':
C:/Users/edvar/Desktop/esp-idf-2/components/esp32/cpu_start.c:539: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

Adding new PID's

Hi,
i really like your implementation, i'm currently trying to add some more features, like the engine load and some temperatures. But somehow it's still just showing the 3 supported PID's.
Can you give me a sample on which places i have to add the supported PID's?
I've currently tried to adjusted these places and extended some PID's, but these places doesn't change something at all:
https://github.com/limiter121/esp32-obd2-emulator/blob/master/main/can_demo_main.c#L114**
https://github.com/limiter121/esp32-obd2-emulator/blob/master/main/can_demo_main.c#L146

Can you help me somehow please?
I would like to push my changes later to your project :)
BTW: I've also updated the project to be compatible to IDF v4.x

Problem to read transmitted data

Hi guys!! I've followed your instructions to deploy the program at ESP32 microcontroller. Everything worked fine, I was able to connect to it using my phone and also was able to track the log of TX using terminal. However, I was not able to read the transmitted data using a CAN Module MCP2515 Module with arduino UNO.
The receiver end is working fine as well, since I tested it in a car using the code at the end of this post (some comments are in portuguese, sorry for that) and was able to get RPM data. Thus, I think that maybe the problem is in the connection that I did, which is the following:
Instead of using the WROOM32 alone I used the ESP32 DEVKIT V1. Also, I was not able to find SN65HVD230, so I used MCP2551 Module.
The voltage supply of this module is 5V, so it was necessary to interface the communication using this logic level converter.
So, the connections are as follows:

  • Data between ESP32 and Logic Level Converter:

D4 (GPIO4 from ESP32 module) -> LV4 (logic level converter)
D5 (GPIO5 from ESP32 module) -> LV3 (logic level converter)

  • Data between Logic Level Converter and MCP2551 Module:

HV4 (logic level converter) -> CRX (MCP2551 Module)
HV3 (logic level converter) -> CTX (MCP2551 Module)

  • Data between MCP2551 Module and MCP2515 Module:

CANH (MCP2551 Module) -> CANH (MCP2515 Module)
CANL (MCP2551 Module) -> CANL (MCP2515 Module)

POWER SUPPLY:
-Logic Level Converter

VIN (ESP32 Module) -> HV (Logic Level Converter)
GND (ESP32 Module) -> Both GND (Logic Level Converter)
3V3 (ESP32 Module) -> LV (Logic Level Converter)

-MCP2551 Module

VIN (ESP32 Module) -> VCC (MCP2551 Module)
GND (ESP32 Module) -> GND (MCP2551 Module)

Am I missing something?
I do not have oscilloscope here to see if the data is arriving at the logic converter or at the MCP2551 module.
Do you have any suggestion?
I thing that maybe the VIN voltage (which comes directly from USB VDD) is not sufficient to run the MCP2551.

P.S.: I've checked dozen times the above connections using a multimeter (continuity test) to avoid any faulty wiring.

P.P.S.: I've maintained the default values in menuconfig (pins, etc). I only needed to change the flash memory to a higher value.

/* CAN OBD & UDS Simple PID Request
*

  • Currently requests PID 0x00 at a 1 second interval and
  • displays all received CAN traffic to the terminal at 115200.
  • Written By: Cory J. Fowler April 5th, 2017
  • (Disclaimer: Standard IDs are currently UNTESTED against a vehicle)
  • Hiya, Claudio here. I made some modifications in this code to make
  • it work on a Renault Sandero in Brazil. So, I tested the Standard IDs
  • and they are working pretty fine. I also changed the txData in order
  • to request the RPM of the vechicle. Changed the frequency of the
  • oscillator as well, since the MCP2515 module that I'm using is a chinese
  • version with 8MHz crystal. And finally, I've added a function to convert
  • the data received from the car to a readable RPM value on serial screen.

*/

// Codigos retirados de:
//http://forum.arduino.cc/index.php?topic=402018.0
//https://forum.arduino.cc/index.php?topic=476862.0

#include <mcp_can.h>
#include <SPI.h>

// Standard igual a 1 pois trabalhando com 11 bits, n eh extended (29 bits)
#define standard 1
// 7E0/8 = Engine ECM
// 7E1/9 = Transmission ECM
#if standard == 1
#define LISTEN_ID 0x7EA
#define REPLY_ID 0x7E0
#define FUNCTIONAL_ID 0x7DF
#else
#define LISTEN_ID 0x98DAF101
#define REPLY_ID 0x98DA01F1
#define FUNCTIONAL_ID 0x98DB33F1
#endif

// Variaveis TX do CAN
unsigned long prevTx = 0;
unsigned int invlTx = 1000;
//byte txData[] = {0x02,0x01,0x00,0x55,0x55,0x55,0x55,0x55}; // Requisita quais os PIDs suportados
byte txData[] = {0x02,0x01,0x0C,0x55,0x55,0x55,0x55,0x55}; // Requisita o RPM do veiculo
//byte txData[] = {0x02,0x01,0x0C}; // Requisita o RPM do veiculo
//byte txData[] = {0x02,0x01,0x0D,0x55,0x55,0x55,0x55,0x55}; // Requisita a velocidade do veiculo
//byte txData[] = {0x02,0x01,0x11,0x55,0x55,0x55,0x55,0x55}; // Requisita o Throttle do veiculo

// Variaveis RX do CAN
unsigned long rxID;
byte dlc;
byte rxBuf[8];
char msgString[128]; // Vetor para armazenar a string serial
float DisplayValue = 0.0;

// Pinos Interrupt e Chip Select
#define CAN0_INT 2 /* INT no Pino 2 /
MCP_CAN CAN0(10); /
CS no Pino 10 */

void setup(){

Serial.begin(115200);
while(!Serial);

// Inicializa o MCP2515 rodando a 8MHz com baudrate de 500kb/s e com as mascaras e filtros desativados.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("MCP2515 Iniciado com Sucesso!");
else{
Serial.println("Erro ao inicializar o MCP2515... Falha permanente! Por favor checar o código e conexoes");
while(1);
}

//
// // Allow all Standard IDs
// CAN0.init_Mask(0,0x00000000); // Init first mask...
// CAN0.init_Filt(0,0x00000000); // Init first filter...
// CAN0.init_Filt(1,0x00000000); // Init second filter...
// // Allow all Extended IDs
// CAN0.init_Mask(1,0x80000000); // Init second mask...
// CAN0.init_Filt(2,0x80000000); // Init third filter...
// CAN0.init_Filt(3,0x80000000); // Init fouth filter...
// CAN0.init_Filt(4,0x80000000); // Init fifth filter...
// CAN0.init_Filt(5,0x80000000); // Init sixth filter...

#if standard == 1
// Filtros de ID standard
CAN0.init_Mask(0,0x7F00000); // Init first mask...
CAN0.init_Filt(0,0x7DF0000); // Init first filter...
CAN0.init_Filt(1,0x7E10000); // Init second filter...

CAN0.init_Mask(1,0x7F00000); // Init second mask...
CAN0.init_Filt(2,0x7DF0000); // Init third filter...
CAN0.init_Filt(3,0x7E10000); // Init fouth filter...
CAN0.init_Filt(4,0x7DF0000); // Init fifth filter...
CAN0.init_Filt(5,0x7E10000); // Init sixth filter...

#else
// Filtros de ID extended
CAN0.init_Mask(0,0x90FF0000); // Init first mask...
CAN0.init_Filt(0,0x90DA0000); // Init first filter...
CAN0.init_Filt(1,0x90DB0000); // Init second filter...

CAN0.init_Mask(1,0x90FF0000); // Init second mask...
CAN0.init_Filt(2,0x90DA0000); // Init third filter...
CAN0.init_Filt(3,0x90DB0000); // Init fouth filter...
CAN0.init_Filt(4,0x90DA0000); // Init fifth filter...
CAN0.init_Filt(5,0x90DB0000); // Init sixth filter...
#endif

CAN0.setMode(MCP_NORMAL); // Configurando o modo de operacao normal, >logo o MCP2515 envia confirmacao para os dados recebidos.

// Enfrentando problemas? ===================================
// Se voce nao esta recebendo nenhuma mensagem, descomente a linha setMode
// abaixo para testar a conexao entre o Arduino e MCP2515.
// Sendo assim, a mensagem enviada nesse programa será instantaneamente
// recebida.
// =======================================================
//CAN0.setMode(MCP_LOOPBACK);

pinMode(CAN0_INT, INPUT); // Configurando o pino Interrupt como entrada

Serial.println("Programa de Request de PID simples usando CAN pela OBD-II");
}

void loop(){

if(!digitalRead(CAN0_INT)){ // Se o pino CAN0_INT esta em nivel baixo, fazer leitura do buffer recebido

CAN0.readMsgBuf(&rxID, &dlc, rxBuf); // Receber dados CAN

// Mostrar os dados CAN na medida em que recebemos eles
if((rxID & 0x80000000) == 0x80000000) // Determinar se o ID eh standard (11 bits) ou extended (29 bits)
sprintf(msgString, "ID Extended: 0x%.8lX DLC: %1d Dados:", (rxID & 0x1FFFFFFF), dlc);
else
sprintf(msgString, "ID Standard: 0x%.3lX DLC: %1d Dados:", rxID, dlc);

Serial.print(msgString);

if((rxID & 0x40000000) == 0x40000000){ // Determine se a mensagem eh uma request remota.
sprintf(msgString, "REQUEST REMOTA");
Serial.print(msgString);
}
else {
for(byte i = 0; i<dlc; i++){
sprintf(msgString, " 0x%.2X", rxBuf[i]);
Serial.print(msgString);
}
}
Serial.println();

//Calculando RPM
/* Posteriomente eu pretendo criar funções */
if (rxBuf[1]==0x41 && rxBuf[2]==0x0C) {
int A = rxBuf[3];
int B = rxBuf[4];

 DisplayValue = ((A * 256)+B)/4;
 int tmpInt1 = DisplayValue;                    // Armazena o inteiro
 float tmpFrac = DisplayValue - tmpInt1;        // Armazena a fracao
 int tmpInt2 = trunc(tmpFrac * 1000);           // Transforma a fracao em inteiro
 sprintf(msgString, "RPM: %d.04%d", tmpInt1, tmpInt2);
 Serial.println(msgString);

}

Serial.println();
}

/* A cada 1000ms (Um Segundo) envia uma request para o PID 0C *

  • Esse PID responde de volta com 2 bytes de dados indicando os *
  • o RPM do veiculo. */
    if((millis() - prevTx) >= invlTx){
    prevTx = millis();
    int resposta = CAN0.sendMsgBuf(FUNCTIONAL_ID, 8, txData);

if(CAN0.sendMsgBuf(FUNCTIONAL_ID, 8, txData) == CAN_OK){
Serial.println("Mensagem enviada com sucesso!");
} else {
Serial.print("Erro ao enviar mensagem. Erro numero: ");
Serial.println(resposta);
}
}
}

FS errors

Build and tried - first was getting brown-outs so I added a 5V PS.

Now I keep getting "W (2269) vfs_fat_spiflash: f_mount failed (13)"

It can't mount the file-system. Does it need some external memory?

Tried it on two different ESPWROOM32, ESP32D0WDQ6 (revision 1)

ESP says "Invalid data received !"

Hi,
having problem to make this Demo work. I'm opening the URL on my iPad and play around with the sliders and whatever I do the ESP says "Invalid data received !". The variables "name" and "value" both are NULL. So this happens in "can-demo-main.c" in line 297.

It seems like that he will not jump into the "http_request_get_arg_value"-Function in http-server.c. I place a printf in there and is does not get called...

Any one else got that issue?

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.