Login
Apr. 29, 2024
Control Area Network (CAN) bus is a serial communication protocol that allows devices to exchange data in a reliable and efficient way. It is widely used in vehicles, working like a nervous system to connect ECUs in the vehicle.
Goto sonnepower to know more.
CAN bus was originally designed for automotive applications by Bosch in the 1980s. It is a multi-master, multi-slave, half-duplex, and fault-tolerant protocol that fits well with the requirements of automotive applications. It is simple, low-cost, and reliable and can be used in harsh environments. The CAN bus provides one point of entry for all the ECUs in the vehicle, which makes it easy to connect and diagnose.
CAN bus data can provide valuable insights into the performance and status of the connected devices. However, collecting and processing CAN bus data can be challenging due to the high data rate, low bandwidth, and variable network conditions.
One possible solution to overcome these challenges is to use MQTT, enabling timely data transmission from cars to cloud even with weak network conditions. EMQX is an open-source MQTT broker that can help you build a reliable and scalable MQTT infrastructure for collecting CAN bus data.
The Controller Area Network (CAN) bus, developed by Bosch, a German multinational engineering and technology company, originated in the early 1980s. Its primary purpose was to establish an effective communication system for automotive applications, specifically to decrease the complexity of wiring harnesses in vehicles.
In 1986, Bosch introduced their initial CAN protocol, which quickly gained momentum among auto makers due to its reliability and robustness. By 1993, it became an international standard under ISO-11898. To summarize the evolution of the protocol:
Apart from automotive applications, other industries have embraced this versatile network protocol over time. Today, it is used in industrial automation systems (CANopen) and marine electronics (NMEA 2000). Its widespread adoption is mainly attributed to its ability to operate reliably even under harsh conditions while maintaining low-cost implementation requirements.
The CAN bus is a decentralized communication protocol. Its decentralized approach makes it ideal for applications in automotive and industrial systems where reliability and real-time performance are essential.
In a CAN network, all nodes are connected via twisted-pair wiring or optical fiber cables. Each node has its own microcontroller responsible for processing incoming messages and sending outgoing ones. Data is broadcasted by a node on the shared bus, allowing all other nodes to receive it. The primary stages of the communication process are:
This combination of features allows CAN buses to maintain high levels of efficiency while ensuring reliable communication between different components in complex systems like vehicles or factory automation equipment.
The message structure in a CAN bus system is crucial for efficient communication between devices. The protocol uses a data frame format that consists of several fields, including an identifier, control field, data field, and error detection mechanism.
Here are the three main types of CAN:
Low-Speed CAN, also known as fault-tolerant or ISO 11898-3, operates at speeds up to 125 kbps. It is designed for less critical systems like body control modules, door locks, window controls, etc., where data transmission speed isn't vital. Its key feature is the ability to continue functioning even when one wire in the bus fails.
High-Speed CAN, or ISO 11898-2, can reach speeds up to 1 Mbps. This type of network is suitable for more time-sensitive applications such as engine management systems and electronic braking systems due to its faster data transfer rates compared to low-speed counterparts. However, it lacks fault tolerance capabilities found in low-speed networks.
CAN FD, introduced by Bosch in 2012, is an extension of high-speed networks with increased data rates—up to 5 Mbps—while maintaining backward compatibility with existing high-speed devices. The primary advantage of this technology lies in its ability to transmit larger payloads more efficiently than traditional CAN, making it ideal for modern vehicles with increasingly complex electronic systems.
The CAN bus data can provide valuable insights into the performance, health, and behavior of a vehicle. Collecting CAN bus data to the cloud is a powerful way to leverage the potential of vehicle data through big data analysis. By applying machine learning, artificial intelligence, or other analytical tools to the collected data from a large number of vehicles, vehicle manufacturers can gain valuable insights and leverage them to optimize vehicle performance.
In the AI era, data is the most valuable property. By collecting data from cars to the cloud and then distributing it to all kinds of data infrastructure like databases, and data lakes, users can leverage the data for nearly all kinds of applications.
Collecting CAN bus data locally on the vehicle is pretty mature. However, it can be challenging to collect and process the CAN bus data and transfer the insight to the cloud in real-time due to the high data rate, low bandwidth, and variable network conditions. Thus, it is impractical to transfer all the CAN bus data to the cloud for processing. Instead, one can collect and process the CAN bus data locally on the edge side to reduce the data volume, and transfer the insight to the cloud in real-time.
We'll need at least two components to build such a solution:
Next, we will illustrate the overall solution combining EMQX and eKuiper.
eKuiper is an open-source edge computing engine that can help you process and analyze CAN bus data in real-time. eKuiper is designed for stream processing on the edge, suitable for the real-time processing of the typical streaming data generated by the CAN bus. eKuiper can address these challenges:
Notice: Some of the features related to the CAN bus described in this document are not open source. You can experiment with these features by utilizing ek-can, which extends CAN bus capabilities on top of eKuiper.
eKuiper uses CAN source plugin to connect to CAN bus and receive CAN frames. It supports two modes to connect to CAN bus as shown in the diagram below.
CAN bus data is in binary form and organized as a frame. The CAN frame is composed of several fields. Various CAN protocols include CAN 2.0A, CAN2.0B, and CANFD. The CAN frame format is slightly different for different protocols. The CAN frame format for CAN 2.0A is shown in the figure below.
Among them, two fields are important for us to decode the CAN bus data:
In the payload, the data is organized as a series of signals. The signal is a named data item with a specific length and a specific position in the payload. DBC file is a text file that contains information for decoding raw CAN bus data to 'physical values'. It defines the signal name, length, position, and the conversion formula to convert the raw data to physical values.
In eKuiper, users can specify the DBC path to use when parsing the CAN bus data. It is pretty flexible and secure to configure the DBC in eKuiper.
After configuring the eKuiper CAN source, users can create a stream to receive the CAN bus data with physical and meaningful signals. For example, the CAN payload 0x0000000000000000
can be parsed to the following signals:
{
"signal1": 0,
"signal2": 0,
"signal3": 0,
"signal4": 0,
"signal5": 0,
"signal6": 0,
"signal7": 0,
"signal8": 0
}
Next, users can leverage the powerful eKuiper stream processing capabilities to flexibly process the parsed data just like receiving from MQTT.
After getting the parsed data, we can do a lot of things with it by eKuiper. In order to reduce the bandwidth to transfer data, we can pick the interested signals only. For example, we can pick the signals signal1
and signal2
only.
{
"signal1": 0,
"signal2": 0
}
The eKuiper SQL to do this is simple:
SELECT signal1, signal2 FROM canStream
Because CAN frame size is limited, there is a good chance that the needed signals spread around multiple CAN frames. In this case, we can flexibly composite the signals from different CAN frames to construct a complete message for applications with various algorithms according to your needs. Check the data merging example for more details. Here, we use signal1 as the main property to pick the data.
SELECT signal1, latest(signal2) as signal2 FROM canStream WHERE isNull(signal1) = false
Another example of processing is to collect the data only when some event happens. This can also significantly reduce the bandwidth. For example, we can collect the data only when the signal1 is higher than 100.
SELECT signal1, signal2 FROM canStream WHERE signal1 > 100
Moreover, these processing rules are flexible and can be changed on the fly. Don't worry if you cannot identify the needed signals at the beginning. You can change the rules to adapt to the requirement changes with hot reload.
The most mature usage is to achieve flexible data collection. Besides that, eKuiper can be used in other scenarios like:
Using an MQTT broker like EMQX for collecting CAN bus data can offer several benefits, such as:
For more canbus monitorinformation, please contact us. We will provide professional answers.
Increased scalability: MQTT can support thousands of concurrent connections and millions of messages per second with a single broker. This can enable large-scale data collection from multiple CAN bus devices without compromising performance or reliability.
Enhanced security: MQTT supports various security mechanisms, such as TLS/SSL encryption, username/password authentication, and access control lists (ACLs), to protect the data from unauthorized access or tampering.
Besides these benefits, EMQX provides more features and together with eKuiper, it can help users save bandwidth, reduce latency, and improve reliability when transferring CAN bus data.
Rev Up Your Connected Vehicles Future with MQTT
The key to building a scalable, secure system for your connected-vehicles business.
Get the Whitepaper →To transfer CAN bus data over MQTT, we usually need to transfer through weak network conditions with limited bandwidth. In this case, we need to reduce the data size as much as possible.
In eKuiper sink, we can use the format
option to specify the data format. The default format is JSON
. We can change it to protobuf
to serialize the data into binary format to reduce the data size significantly. Additionally, we can use the compress
option to compress the data by gzip
or other compression methods. In this way, we can significantly reduce the data size compared to the original JSON data. Especially when sending the data in batch, the data size can be reduced by 90% or more in one of our test cases.
Some of the data is time sensitive for cloud applications. For example, the data to diagnose the vehicle accident is critical. In this case, we need to reduce the latency as much as possible. In eKuiper rule, we can use the MQTT sink to send the data to EMQX.
To save bandwidth in the real-time scenario, we can set the serialization format and compression method as mentioned above in eKuiper MQTT sink. In EMQX side, it provides rule engine which supports decompressing and deserializing the data. Without coding, the data can be consumed by the cloud application in real time.
For data that is not time-sensitive, we can save the data in file or local DB and send it to cloud in batch. It can achieve a higher compression rate to save even more bandwidth. In eKuiper rule, we can use file sink to save and compress data locally. It supports configuring the file rolling policy. For example, we can configure the file rolling policy to roll the file every 10 minutes. In this way, we can save the data in file in batch. EMQX is developing a new feature to support transferring the file. Once completed, the saved file can be transferred by MQTT. Currently, users can use other tools to transfer the file to cloud.
In this blog, we have introduced how to collect, process and transfer CAN bus data from vehicles to the cloud with eKuiper and EMQX. In the next blog post, we will go into more detail about each step.
Related resources
Posted on
Can bus can help us control individuals in the network to be able to communicate. Then, how does this can bus work? If you have used it, what are the benefits? Together with TransTRACK, this time we will learn about the can bus through the following article!
CAN bus is a message-based protocol that allows individual systems, devices, and controllers in a network to communicate. In general, the bus is a multi-node communication system that transfers data between components. Controller Area Network enables robust, low-latency data transfer between sensors and computing units in the system. For example, one hardware company has been working with clients to equip agricultural equipment such as combine harvesters and other complex machinery parts with CAN-enabled hardware, allowing various equipment components to relay information to each other efficiently and effectively.
After its introduction in the mid-1980s, CAN bus communication has expanded far beyond the automotive industry where it was first widely adopted. Before the CAN bus gained popularity, vehicle wiring harnesses could contain miles of cables, with bundles of wires required to carry various signals to and from interconnected vehicle systems. In contrast, the CAN bus utilizes a high-speed (25kbps – 1Mbps) twisted pair wiring system, greatly reducing the number of wires required for system components to communicate.
While CAN is still a widely used option in modern in-vehicle computers, the CAN bus is now also implemented in a variety of embedded and industrial applications, ranging from assembly lines and medical machinery, to building automation and access control installations.
Devices on the CAN bus are called “nodes”. Each node consists of a CPU, a CAN controller, and a transceiver, which adjusts the signal level of the data sent and received by the node. All nodes can send and receive data, but not at the same time.
Nodes cannot send data directly to each other. Instead, they send their data to the network, where it is available to any node it has been addressed to. The CAN protocol is lossless, using a bitwise arbitration method to resolve disputes on the bus.
All nodes are synchronized so that all data samples on the network simultaneously. However, data is not transmitted with clock data (time), so CAN is not a truly synchronous bus, with CAN, all data is sent in frames, and there are four types:
There are two variants of message length: standard and extended. The real difference is the additional 18-bit identifier in the arbitration field.
The arbitration field contains the message identification number and the remote transmission request bit. More important messages have lower ID numbers.
If multiple nodes are transmitting at the same time, they start arbitration simultaneously. The node with the lowest message ID number gets priority. Dominant bits override recessive bits on the CAN bus.
The message identifier can be 11-bits long (Standard CAN, 2048 different message identifiers) or 29 bits long (Extended CAN, 537 million different message identifiers). The remote transmission request bit is dominant and indicates that data is being transmitted.
In most systems, logic 1 represents high, and logic 0 represents low. But this is the opposite on the CAN bus. Therefore, CAN transceivers typically use pull-ups on the driver inputs and receiver outputs, so the devices have defaulted to the recessive bus state.
The CAN bus standard is widely accepted and used in almost all vehicles and many machines. The following advantages of using CAN Bus are:
CAN has excellent control and error detection capabilities. Detecting errors is easy, thus the transmitted data reaches the intended place.
It is an ideal protocol when distributed control of complex systems is required. It reduces heavy wiring and thus cost and weight. Chip costs are low, and implementing CAN is relatively easy due to the clean design of the protocol.
Another advantage of using CAN is that the first two layers: the physical layer and the data link layer, are implemented in cheap microchips, available in several configurations.
The ISO 11898 standard defines several versions of CAN. The dominant CAN types used in the automotive industry are:
Used for fault-tolerant systems that do not require a high update rate. The maximum data transfer rate is 125 kbps, but cabling is more economical than high-speed CAN. In automotive applications, low speed CAN is used for diagnostics, dashboard controls and displays, power windows, etc.
Used for communication between critical subsystems that require high update rates and high data accuracy (e.g., anti-lock braking systems, electronic stability control, airbags, engine control units, etc). The data transfer rate of high-speed CAN ranges from 1 kbit to 1 Mbit per second.
High-speed CAN is faster than low-speed, but bandwidth requirements for new automotive applications are increasing every year, so car OEMs are now installing CAN FD into new cars. CAN FD has been described as “CAN on steroids.”
The latest version of CAN introduces flexible data rates, more data per message, and much higher speed transmission. The data length in each standard CAN message (low-speed and high-speed) is 8 bytes, but with CAN FD this has been increased by 800% to 64 bytes of data. In addition, the maximum data rate has also increased dramatically from 1 Mbps to 8 Mbps.
How is it? Can you understand the Can Bus that has been explained above? If you can understand it, you can start using the fleet management system in TransTRACK for better and safer management of your fleet. Because TransTRACK has been integrated directly with the system of the Ministry of Transportation of the Republic of Indonesia which supports the issuance of route permits on passenger transportation.
Topic
If you are looking for more details, kindly visit distributed io vs remote io.
60 0 0
Join Us
Comments
All Comments ( 0 )