Site Information

 Loading... Please wait...


SAE J1939 to Bluetooth Gateway - Android Code (Java) Sample Code

Posted by Wilfried Voss on

Electronic Logging Device - ELD

Just as a fair warning upfront, the code that I am referring to in this post is not a finished sample code, but it demonstrates how to receive and decode SAE J1939 message frames (PGNs) from our JCOM Bluetooth device. 

To explain the situation: Some time ago, we had started a customer project with the intention to develop an ELD (Electronic Logging Device). The project was ultimately abandoned due to lack of funds. 

Note: An electronic logging device (ELD) is electronic hardware that is attached to a commercial motor vehicle engine to record driving hours. The driving hours of commercial drivers (truck and bus drivers) are regulated by a set of rules known as the hours of service (HOS). The Commercial Vehicle Driver Hours of Service Regulations vary in Canada and the United States.

During the project's initial lifetime, we developed a hardware that would meet the requirements of the ELD rule, including the necessary firmware. The hardware is described in our product page  CAN Bus / SAE J1939 Electronic Logging Device With Bluetooth, BLE, WiFi Option, and, after the project ended, we created a few SAE J1939 devices based on the same hardware, however, incorporating some optional modules to support Bluetooth, BLE (Bluetooth Low Energy), WiFi, GPS, and more.

At the same time, we developed a concept of our ELD device as described in our post  ELD Concept: SAE J1939 Data Recording And Display Using Android Or iOS Devices. Let me emphasize the point that we chose an Android tablet (not iPhone with iOS) not only as a data terminal but also as GPS and cellular connection provider. 

Note: The choice for Android over iOS was made due to practical considerations, such as price and reliability in an electrically harsh environment (i.e. a vehicle). Using BLE on a daily basis (iPhone, iMac in combination with airpods, keyboard, wireless mouse), I have come to doubt BLE's reliability in an industrial or vehicle environment.

We are, however, neither Android nor Java programming experts, so we hired an external resource to develop the Android Java code. The sample code that I am offering here receives the SAE J1939 data frames from our Bluetooth device and decodes them for further processing. The code also took some sample PGNs and displays them on the screen.

Note: The Java code is based on an older version of the Android OS and may need modification to suit upgraded versions. However, the code is suited to serve as a helpful resource for your own project.

Our product, the  SAE J1939 to Bluetooth Gateway With 9-Pin Deutsch Connection Cable, works perfectly in combination with our jCOM1939 Monitor, an SAE J1939 Monitoring, Analyzer and ECU Simulation software under Windows, and it is very well suited for an adaptation to Android (or iOS).

And while I am not convinced that BLE is a good option for ELD purposes, our Bluetooth device can be easily converted to BLE by replacing the BT module with a BLE alternative such as the one described in  Dual-Mode Bluetooth And BLE To USB Module.

Last, but not least, please be aware that the serial communication between the BT device and the receiving device (Andoid tablet/phone/phablet, PC, etc.) is well documented (see below resources). We also have developed sample code in C and C# to demonstrate the communication. As a matter of fact, we used a C# to Java converter to provide sample code for our Java developer.

Development Resources

Getting Started with Bluetooth Low Energy: Tools and Techniques for Low-Power NetworkingGetting Started with Bluetooth Low Energy: Tools and Techniques for Low-Power Networking

With Bluetooth Low Energy (BLE), smart devices are about to become even smarter. This useful guide shows how this impressive wireless technology helps developers create mobile applications that share data with external hardware and how hardware engineers can obtain easy and reliable access to mobile operating systems.

This book renders a reliable, high-level overview of how devices use BLE to communicate with each other. You learn about valuable low-cost tools for developing and testing BLE-enabled mobile apps and embedded firmware and get examples using various development platforms, including iOS and Android for app developers and embedded platforms for product designers and hardware engineers.

  • Understand how data is organized and transferred by BLE devices
  • Explore BLE’s concepts, key limitations, and network topology
  • Dig into the protocol stack to grasp how and why BLE operates
  • Learn how BLE devices discover each other and establish secure connections
  • Set up the tools and infrastructure for BLE application development
  • Get examples for connecting BLE to iPhones, iPads, Android devices, and sensors
  • Develop code for a simple device that transmits heart rate data to a mobile device

More Information...

IoT Development Board Based On ESP-32S Module Supports WiFi And Bluetooth

The NodeMCU ESP-32S is an IoT (Internet of Things) development board created by NodeMcu to evaluate the ESP-WROOM-32 module. It is based on the ESP32 microcontroller that supports WiFi, Bluetooth, Ethernet, and Low Power support all in a single chip.The NodeMCU-32S board is also an open source IoT platform. It uses Lua script and a lot of [...]

Read More »

Low-Cost Do-It-Yourself CAN Bus To WiFi, Bluetooth, BLE, USB, RS485 Gateway Based On Raspberry Pi Zero

In the following, I will discuss a do-it-yourself project utilizing the Raspberry Pi Zero in combination with the CAN Bus Plus RS485 HAT. The combination of serial and wireless ports provided by this system allows the development of a great number of gateway applications. Overall, this small-size hardware includes connections such as CAN Bus, RS485, [...]

Read More »

Bluetooth Low Energy (BLE) Breakout Board Connects Arduino To iOS Or Android Devices

The Adafruit Bluefruit LE (Bluetooth Smart, Bluetooth Low Energy, Bluetooth 4.0) nRF8001 breakout board allows to build an easy to use wireless link between an Arduino and any compatible iOS or Android (4.3+) device.  It works by simulating a UART device beneath the surface, sending ASCII data back and forth between the devices, letting the user determine what [...]

Read More »

Bluetooth Low Energy (BLE) Wireless Modules Suitable For High-Speed IoT Devices And Applications

Fujitsu Components America released their FWM7BLZ20B series of Bluetooth 5.0 Low Energy wireless modules matching the speed demands of Internet-of-Things (IoT) devices and applications.The FWM7BLZ20B series is powered by Nordic Semiconductor's nRF52832 System-on-Chip (SoC). The symbol rate and data rate supports both 1Mbps and enhanced 2Mbps to expedite communication speed with other Bluetooth devices.The series comprises [...]

Read More »

Bluetooth Low Energy (BLE) Projects with Arduino, Raspberry Pi, and Smartphones

Bluetooth Low Energy (Bluetooth LE, colloquially BLE, previously marketed as Bluetooth Smart) is a wireless personal area network technology designed and marketed by the Bluetooth Special Interest Group (Bluetooth SIG) and intended for innovative applications in the healthcare, fitness, beacons, security, and home entertainment applications. Compared to Classic Bluetooth, Bluetooth Low Energy was designed to render [...]

Read More »

GSM/GPRS/GNSS/Bluetooth HAT for Raspberry Pi, Based on SIM868

This is a handy, low power Raspberry Pi HAT which features multi communication functionalities: GSM, GPRS, GNSS and Bluetooth. It allows your Pi to easily make a telephone call, send messages, connect to wireless Internet, global position, transfer data via Bluetooth, and so on. Features Raspberry Pi connectivity, compatible with Raspberry Pi 2B/3B/3B+/Zero/Zero W Supports SMS, phone call, GPRS, [...]

Read More »

Rapid IoT Prototyping Kit With BLE And Zigbee Connectivity

The Rapid IoT Prototyping Kit by NXP Semiconductors was designed to take developers from an Internet of Things (IoT) idea to Proof of Concept (PoC) in a matter of minutes.  The Rapid IoT Prototyping Kit operates with the powerful Kinetis K64F Core 32-bit Microcontroller for application processing and features a Kinetis KW41Z Wireless Controller for Bluetooth® Low Energy (BLE), Thread, [...]

Read More »

Bluetooth Low Energy (BLE) Projects with Arduino, Raspberry Pi, And Smartphones

Bluetooth Low Energy (BLE) is a wireless personal area network technology designed and marketed by the Bluetooth Special Interest Group (Bluetooth SIG) aimed at novel applications in the healthcare, fitness, beacons, security, and home entertainment industries. Compared to Classic Bluetooth, Bluetooth Low Energy is intended to provide considerably reduced power consumption and cost while maintaining a [...]

Read More »

Ultra Small Form Factor IoT Device With Wi-Fi, Bluetooth And 4G Connectivity

Global computer hardware manufacturer Logic Supply has announced their CL200 Ultra Small Form Factor computer, built to power innovation at the network's edge. Surrounded by an ultra-durable cast aluminum enclosure, and configurable with Wi-Fi, Bluetooth and 4G connectivity, the CL200 has been engineered to bring reliability to the Internet of Things.Both models in the CL200 Series are [...]

Read More »