top of page

How to send CAN Bus J1939 equipment data onto a cloud platform or server using MQTT?

Screen Shot 2023-11-10 at 2.32.20 pm.png

The SAE J1939 CAN Bus protocol plays an important role in the rise of heavy-duty telematics & connected vehicles by ensuring that a common language & standardised communication protocol is held across manufacturers of heavy vehicles & industrial equipment.

With the use of an industrially certified IoT gateway that's equipped with CAN J1939 protocol you can collect & send these vehicle or machinery data for monitoring & industrial intelligence applications. The gateway organises the data collection and sends it to a server or cloud using messaging protocols like MQTT. 

Furthermore, devices like the nodeG5 gateway can also embed additional hardware or software to combine a range of complimentary functions on a single device.

  • Adding cellular & GPS modules enable heavy vehicles to be monitored on-the-move, together with positional tracking.

  • Integrated clients from major cloud platforms like Azure & AWS on the firmware helps the set-up for these applications be done faster & more reliably, reducing the engineering time needed for these projects.

  • FOG compute, edge processing or machine learning capabilities allow ground assets to spend less time communicating with the server or cloud, react more quickly to changes, and operate reliably even in extended offline periods. 

The following tutorial gives a step-by-step example of connecting data from a CAN Bus J1939 device (OZEN Elektronik OE91C1700 simulator) to a dashboard on AWS IoT Core.

Step 1: Wire up the J1939 CAN Bus ECU to the Gateway.
Screen Shot 2023-11-13 at 10.34.11 am.png

We will start by connecting the devices together. You will need to refer to the respective user manuals for the pin out configuration of each device. The above diagram shows the signal connection from the OZEN board to the CAN Port E of the nodeG5 IoT gateway using a shielded twisted pair cable. 

Step 2. Match the baud rates of both devices.

The baud rates for both devices need to match. Since the OZEN J1939 ECU Simulator communicates using a 29-bit protocol and 250000 bps baud rate, we need to match that on to the nodeG5 gateway.

To do that you need to log into the web configuration menu of the gateway. Then go to the <Port Settings> tab and enter the following settings below.

Screen Shot 2023-11-13 at 10.53.04 am.png

Once you are done click the 'UPDATE' button & REBOOT the gateway to save your settings.

CONNECT METER TO GATEWAY
Step 3. Map out the data parameters you want to collect.

Next, we will map out the individual sets of data that we want to collect from the ECU. Because different makers of CAN devices will utilise different Parameter Group Number (PGN) settings, if we want to be brand agnostic for cost or product feature reasons, we need to find a universal way to detail the instructions to the gateway. On top of that, data formatting requirements are also different between each cloud platform. This adds to the need for a nimble approach.

Without engineering codes from scratch, a simple but flexible method is to map the parameters we want to monitor onto a configurable file known as an 'iotasset' that's read by the gateway. The example below shows how the "engine coolant temperature" parameter can be translated from the OZEN device user manual to our J1939 iotasset.json format template.

We begin by obtaining the below PGN info from the product's user manual.

PGN 1.png
PGN 2.png

When we will follow the J1939 iotasset.json format template to configure the instructions for polling "engine coolant temperature" to the gateway on a simple program like notepad, we get the following results. I have also added samples for other data such as 'engine rpm' and 'vehicle speed' done using the same process.

{

    "CANBUS":[

        {

            "Key":"J1939EngineCoolantTemp", 

             "IOTMODE":"1",

             "CANBUSTYPE":"J1939",                   

             "CANPORT":"canE",

             "CANPGN":"FEEE",                              #"FEEE" is the PGN 0xFEEE (65262 decimal)

             "CANSA":"00",

             "BYTESTART":"1",                                #our response data is located at start byte position 1

             "BYTECOUNT":"1",                               #our response data has a length of 1 byte

             "DATATYPE":"UINT8",

             "SCALEMUL":"1",                                 #we match AWS requirements by applying a multiplier of x1

             "SCALEADD":"-40"                               #we match AWS requirements by putting an offset of -40

        },

        {
            "Key":"J1939EngineRPM",

            "IOTMODE":"1",

            "CANBUSTYPE":"J1939",

            "CANPORT":"canE",

            "CANPGN":"F004",

            "CANSA":"00",

            "BYTESTART":"4",

            "BYTECOUNT":"2",

            "DATATYPE":"UINT16HL",

            "SCALEMUL":"0.25",

            "SCALEADD":"0"

        },

        {

             "Key":"J1939VehicleSpeed",

             "IOTMODE":"1",

             "CANBUSTYPE":"J1939",

             "CANPORT":"canE",

             "CANPGN":"FE6C",

             "CANSA":"00",

             "BYTESTART":"7",

             "BYTECOUNT":"2",

             "DATATYPE":"UINT16HL" 

        }

    ]

}

Now that you have configured your device configuration file, we can update it to your nodeG5 gateway securely over the air. The gateway HTTPS connected web console must be accessible, if you do not have an Internet connection, you can follow the alternative steps here). 

Log into the nodeG5 (the default address is 192.168.1.1) and enter in the user name and password. Go to the <Management> tab in the web configuration menu. Enable the SSH option (see below) and click the 'UPDATE' button to save your settings. Then reboot the gateway.

Screen Shot 2023-11-08 at 11.06.36 pm.png

Then log in again, go to the <IOT Hardware> menu to set the CAN bus mode to "J1939 mode" and register the polling configuration as required by the user. Click 'UPDATE' to save your settings. 

(Note that all other interfaces like Modbus and BLE can also run concurrently).

Screen Shot 2023-11-13 at 10.48.45 am.png

Next, click “Upload iotasset.txt” button and in the new window, use the 'CHOOSE FILE' tab to select the above prepared file from your local folder to to send over to nodeG5After the upload is successful you will need to close the page and log in again for security purpose. The user can also confirm the status of iotasset.txt file upload by clicking on Diagnostics::Check File.

Screen Shot 2020-07-07 at 11.22.16 am.pn

After these settings are updated, REBOOT the gateway. The user can then check the CAN BUS vehicle data collected (Diagnostics::JSON Data) or delete for testing.

CONNECTING TO A CLOUD STACK
Step 4. Connect the collected data to your AWS IoT Cloud Service

Now that the connectivity between the ECU Simulator and the nodeG5 gateway has been set, we will then look at getting the data onto a designated cloud service. We support an open customer software and 3rd party API (e.g. REST API for HTTP, HTTPS and MQTT) integration to connect to a chosen cloud data or dashboard service (or to use for on board data processing).

 Direct deployment on Azure, AWS IoT or Ubidots can also be done as these IoT clients have been integrated on the nodeG5 Gateway. For this project, we are going to showcase using AWS IoT
(note that an AWS
account is required to continue this tutorial).

4A. Create a new AWS IoT Thing

First log into your AWS IoT Management Console and create a Thing:

AWS IoT > Manage > Thing > Create

Next go to:

Secure > Certificates

Then download the 'Certificate' & 'Private Key File'.

Ensure the Certificate is "Active", otherwise activate it under ACTIONS in 

Things > Your Certificate > Security

AWS Certificate Download.png
4B. Update your IIoT Gateway
Create a new local folder and name it "AWS". 

Save the downloaded certificate files into this folder and rename them as the following:

"certificate.pem.crt"

"private.pem.key"
 

Next zip the folder (ensure that you zip the entire folder and not just the files inside).

Then log into your web console and go to the <Management> tab.

Patch the zipped folder to the gateway using the UPDATE FIRMWARE button.

4C. Create a Security Policy for your Thing

In your AWS IoT Management Console go to:

Secure > Policies > Create

Create AWS Policy.png
At <Things>, select your new Thing then click on

Security > Certificates > Policies

Under <Actions>, choose to Attach a Policy:

Attach AWS Policy.png
4D. Configure your nodeG5 IIoT Gateway to send data to your AWS Account

Now, you are ready to configure your gateway to send AWS IoT endpoint to feed data to your AWS applications. In the web configuration menu, go to the <IoT Client> tab and configure your AWS client settings according as per your AWS end point and Thing settings. Then REBOOT your gateway.

uber5_CAN_web_settings.png
Next go back to go your AWS IoT console and subscribe to the Topic to "Test" that data is being received.

ODB2_AWS_IoT.png
Congratulations! You have succesfully sent your Modbus or CAN bus data to your AWS IoT endpoint and ready to, for example, push the data to a S3 bucket using a Rule in 'Act > Rules'.

The nodeG5 AWS IoT client side is built using AWS IoT Device SDK for Python and users are free to install, modify our device client codes for enhanced edge capabilities or other required functionalities.

See our guides below for connecting to other supported IoT platforms includes Azure IoT and Ubidots. Here is a sample dashboard from Ubidots. 

 
CANonAWS.png

Guides to connect other Cloud Platforms

Connecting to Microsoft Azure IoT Hub

Connect to Ubidots IOT Platform

Have a question for us?
bottom of page