Testing ELM327 without the car

Hello!

It’s winter here and so I have decided to explore possibilites that might help me avoid programming in the car. First it is cold, second it is not comfortable at all. At some point I have to go outside, but not just yet.

I bought OBD2 male connector (the same one you have in your car) to power up the ELM327 on my desk  with no CAN connection. Let’s take a look at OBD2 schematics:

OBD2 pinout schematics.

OBD2 connector pinout schematics.
Source: instructables.com

I need to power up the ELM327 – the start sequence after power-up is self test, then it starts to broadcast Bluetooth. So I can develop the connection library, test sending and receiving messages over bluetooth and even check voltage. Clever, especially when it is cold outside and you don’t have the garage. Or you live in Russia.

Anyway, to start we need 12V on pin 16 and ground on pins 4 and 5 (I have checked with multimeter and my adapter has those pins bridged, so I actually needed just one). This is how the connector looks like (black ground, red 12V):

OBD2 connector on the desk with wires attached.

OBD2 connector on the desk with wires attached.

Few hours later I connected it to the stabilized DC power supply where I set 12V – it should work fine on PC power supply too if you don’t have lab power supply on your desk:

ELM327 connected to the power supply with my connector.

ELM327 connected to the power supply with my connector.

It works (red light on the right), there was a boot sequenece and self test visible too, but it’s hard to capture it on the picture. And surprise – 30mA for idle, 42mA on start. This was really strange for me, as far as I know whole car with ignition off usually draws 30-50mA. This is a lot.

A good example how OBD2 pins should not be soldered.

A good example how OBD2 pins should not be soldered.

So I took the whole connector apart and soldered the wires.

Damn, too much solder, I had to repeat the process 🙁 It did not help at all anyway. Strange. I have to add it to the things to consider for later, I don’t like it to draw so much current on idle, or maybe it is not idle?

Let’s connect and check the connection, there is OBD2 on the list (or just a mac address, after double click it will be renamed). Default passcode provided by Apple was 0000, it did not work, I had to put 1234:

macOS devices list with OBD2 adapter ready to pair.

macOS devices list with OBD2 adapter ready to pair.

I tried Cornflake as a serial GUI application, but it does not work at all, so I have used terminal with screen (38400 is a baudrate) – make sure that bluetooth devices list says “not connected” until you actually run the command:

screen /dev/tty.OBDII-SPPDev 38400

Terminal with screen connected to OBD2.

Terminal with screen connected to OBD2.

AT L1 command sets the line feed to be sent by the device – it is hard to read responses when terminal tries to put them in the one line.

AT I is an Info command, @1 displays device informations.

AT RV is a Read Voltage command, it should display voltage on the battery pin. Shame it did not, I have 12V with tolerance of +/-0.05V here. Great it could be calibrated, so I set the 12.00V with Change Voltage command and from now on I am going to have better readouts of my car battery voltage.

Node Module Version Mismatch: Expected 50

Today I got the same error as in the title. Installed nvm, tried all versions of node from 6.8 to 7.1 which reulted in 48 and 51 result mode version (in file config.gypi).

So I’ve opened Electron page https://electron.atom.io/ and checked current Electron and node versions. Then a few commands to run:

And it does not work anyway… And there is no indication what is wrong, except now Electron expects NODE_MODULE_VERSION 53 and I have somehow 51. Checked node_version.h file and there is #define NODE_MODULE_VERSION 51 . So nothing wrong and still does not work.

I have searched for NODE_MODULE_VERSION 53 and noticed that it is on master for Electron, which is 8.0. And there is no Node 8.0 in nvm (and I won’t like to use alpha version anyway). So blind guess – downgrade the Electron:

And now bozon start  works fine 🙂

 

@Edit:

Got today once again:

So just a reminder – after the restart it is mandatory to use nvm use 7.4 again 😉

Binding.gyp file for Objective-C++ project built using XCode

Hi!

Last time we started with the project and I promised that next will be an addon. I don’t have it finished yet, but stepped into an unknown teritory of configuring everything to compile and link find with an Objective-C(++) code and native macOS libraries: CoreBluetooth and CoreFoundation.

There are not many informations at all on the internet about how to make it work so I had to do a lot of guessing and trying.

First I made a rookie mistake (I am a newbie with Node addons so no surprise here) and added include_dirs at the wrong level of the file. Which made it unusable for both Xcode and node-gyp.

And I spent a few hours just setting it manually in Xcode settings (some of node-gyp commands remove the project file, node-gyp rebuild  for example, or just node-gyp clean ) before I found the problem.

I was really pissed off at the moment when I have found out that most of settings that I put there were just not parsed at all because there were not added as a child element of target.

Anyway.

We need to build on OS X using native libraries. I wanted to use Objective-C too just to try how it works. So first we may add .m and .mm files (.m is Objective-C, .mm is Objective-C++ – there is not much difference between them, second just allows C++ code inside) so my “sources” now looks like this:

Of course it won’t work now. We need to change at least two more things. First (this is not mandatory, but I really recommend that) we add conditional settings based on operating system. This way we will not break compile on another platforms in the future:

Then we populate the “mac”:

Notice how libraries are imported (“link_settings”). Somehow for one library it is:

It does not work for more than one though, tried using comma etc. The way I put it works.

Next thing is CLANG_CXX_LIBRARY which means I can use C++11 and -ObjC++ which tells the compiler that some of the code will be in Obj-C.

Now also project created with this command works and can be built using Xcode:

This works fine so I will now try to finish the library and add some logging possibility. Stay tuned 😉

Let’s start with C++ NodeJS addon

First things first – I know literally nothing about NodeJS C++ addons. I have an experience with C++ and with interopearation between C+++ and other languages, but not JavaScript and definitely not NodeJS (except small, top-secret project in bozon).

So we are going to learn together ;] Happy?

Let’s get started with getting project structure prepared – current architecture divides the project into (at least) three layers, which makes it kind of “Buissness Logic Desing Pattern”:

  • JavaScript / HTML presentation layer.
  • JS / NodeJS thin proxy as a business logic.
  • C++ addon for NodeJS for whole OBD2 protocol and connection.

The first layer has to run on desktop – which does not often happen for JS apps. That’s where Electron kicks in. It is a framework for building desktop apps with NodeJS, HTML and CSS, which nicely fits my needs.

Sometimes I am actually a lazy person and don’t like to create whole project structure by hand, so for that I’ve been using Bozon. It is not perfect, but creates a project scaffolding with build script, run script and unit testing script (created with Gulp, whatever this is). Exactly what I need, everything else I can do myself. You can see it created yourself in this commit.

Okay, enought about libraries, let’s start with creating NodeJS addon in C++, so we can see how it works.

First we create a source code of our binding layer file as described in documentation:

Then we have to create a binding.gyp describing build configuration:

At the end install and run the node-gyp:

Now we have a scaffolding for the C++ plugin which can be easily built. There is one more thing actuall, I don’t like writing C++ in the notepad, so I wanted to have an XCode project and this is quite easy to do with one command:

Clever. The build does not work without node-gyp configure ran after though.

Then we want nan module which creates an abstraction between v8 and node version and our C++ code. I wanted to do this myself, but there is no need to reinvent the wheel:

And change our bindings file, there should be added information about include directories:

Now every use of #include <node.h>  should be replaced with #inlcude <nan.h> .

Also if you use like me Xcode you need to edit project “binding.xcodeproj” and add to search paths nan directory:

Also we will in the future have more than one NodeJS library so we might want some common code – path to headers should be added the same way.

This is all for now, in next post we are going to try this with bluetooth enumeration on macOS and think about why node-gyp does not create proper project with HEADER_SEARCH_PATHS.