All Projects → c3re → can2mqtt

c3re / can2mqtt

Licence: MIT license
Bidirectional CAN-Bus to MQTT-Bridge

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to can2mqtt

pyuavcan
Python implementation of the Cyphal protocol stack.
Stars: ✭ 91 (+133.33%)
Mutual labels:  can, can-bus, socketcan
can-prog
Command-line tool to flashing devices by CAN-BUS
Stars: ✭ 66 (+69.23%)
Mutual labels:  bus, can, socketcan
ecu-simulator
OBD-II ECU Simulator
Stars: ✭ 24 (-38.46%)
Mutual labels:  can, can-bus, socketcan
python-can
Copy of python-can from bitbucket for the purposes of new protocol development
Stars: ✭ 20 (-48.72%)
Mutual labels:  can-bus, socketcan
CANopen-monitor
An NCurses-based TUI application for tracking activity over the CAN bus and decoding messages with provided EDS/OD files.
Stars: ✭ 15 (-61.54%)
Mutual labels:  can, can-bus
PSAVanCanBridge
VAN - CAN protocol bridge (V2C) for cars made by PSA Group (Peugeot, Citroen)
Stars: ✭ 67 (+71.79%)
Mutual labels:  can, can-bus
netcore-can-example
SocketCan example on dotnet-core
Stars: ✭ 21 (-46.15%)
Mutual labels:  can-bus, socketcan
JavaCAN
A simple JNI wrapper for the socketcan API provided by the Linux kernel. As it is wrapping a Linux Kernel API, it is intended for use on Linux only.
Stars: ✭ 23 (-41.03%)
Mutual labels:  can, socketcan
cpp-can-isotp
C++ implementation of CAN ISO 15765-2 also known as CAN ISO transport protocol. CPP CAN isotp.
Stars: ✭ 14 (-64.1%)
Mutual labels:  can, can-bus
can-go
Controller Area Network (CAN) SDK for Go.
Stars: ✭ 113 (+189.74%)
Mutual labels:  can, socketcan
J1939-Framework
Framework to work with J1939 Frames used in CAN bus in bus, car and trucks industries
Stars: ✭ 123 (+215.38%)
Mutual labels:  bus, can-bus
pcan cantact
🤖 XCAN firmware for CANtact ( CANable ) or any other similar boards.
Stars: ✭ 192 (+392.31%)
Mutual labels:  can, socketcan
openHCAN
Hausautomatisierungsloesung auf CAN-Bus Basis.
Stars: ✭ 16 (-58.97%)
Mutual labels:  can, socketcan
public regulated data types
Regulated DSDL definitions for Cyphal (standard and third-party)
Stars: ✭ 62 (+58.97%)
Mutual labels:  can, can-bus
react-in-out-textarea
A simple React.js User Interface Component that is like Google Translate with full TypeScript Support
Stars: ✭ 28 (-28.21%)
Mutual labels:  converter
cantools
CAN bus tools.
Stars: ✭ 1,266 (+3146.15%)
Mutual labels:  can-bus
xml-to-json
Simple API that converts dynamic XML feeds to JSON through a URL or pasting the raw XML data. Made 100% in PHP.
Stars: ✭ 38 (-2.56%)
Mutual labels:  converter
bmtc
Ruby wrapper for Bangalore Metropolitan Transport Corporation BMTC Intelligent Transport System (ITS) API
Stars: ✭ 13 (-66.67%)
Mutual labels:  bus
SerialToTCPBridgeProtocol
An error tolerant serial UART to TCP connection, raw data bridge.
Stars: ✭ 16 (-58.97%)
Mutual labels:  bridge
react-native-mercadopago-px
🚀 MercadoPago PX bridge for react-native
Stars: ✭ 87 (+123.08%)
Mutual labels:  bridge

can2mqtt

can2mqtt is a small piece of software written in Go. Its purpose is to be a bridge between a CAN-Bus and a MQTT-Broker. Those are completely different worlds but they have similiaritys in the way they are built. I think i don't have to speak about the differences so i will just pick up the similiarities: In the CAN-world you have so called CAN-Frames. Each CAN-Frame can contain up to eight bytes of payload and CAN-Frame has an ID. In the MQTT-world you have topics and messages. Each message has a specific topic. As you can see it should be possible to map CAN-IDs to MQTT-Topics and their respective payload to messages. That's what this little programm does.

Installation

You need to have go installed. After that you should be able to get can2mqtt to run with the following commands:

$ mkdir ~/go
$ export GOPATH=~/go
$ go install github.com/c3re/can2mqtt/can2mqtt@latest

After that you should have a runnable binary under $GOPATH/bin/ called can2mqtt.

Usage

The commandline parameters are the following:

can2mqtt -f <can2mqtt.csv> -c <can-interface> -m <mqtt-connectstring> [-v]

Where can2mqtt.csv is the file for the configuration of can and mqtt pairs, can-interface is a socketcan interface and mqtt-connectstring is string that is accepted by the eclipse paho mqtt client. An additional -v flag can be passed to get verbose debug output. Here an example that runs on our Raspberry Pi @c3RE:

can2mqtt -f /etc/can2mqtt.csv -c can0 -m tcp://127.0.0.1:1883

Screenshot

Here you can see can2mqtt in action: can2mqtt screenshot

can2mqtt.csv

The file can2mqtt.csv has three columns. In the first column you need to specify the CAN-ID as a decimal number. In the second column you have to specify the convert-mode. You can find a list of available convert-modes below. In the last column you have to specify the MQTT-Topic. Each CAN-ID and each MQTT-Topic is allowed to appear only once in the whole file.

Here again the example from the Pi@c3RE:

112,none,huette/all/a03/door/sensors/opened
113,2uint322ascii,huette/all/000/ccu/sensors/time
115,uint322ascii,huette/serverraum/000/filebitch/sensors/ftp_diskusage_percent
116,uint322ascii,huette/all/000/router/sensors/rx_bytes_s
117,uint322ascii,huette/all/000/router/sensors/tx_bytes_s
118,uint322ascii,huette/clubraum/000/ds18b20/sensors/temperatur
119,uint322ascii,huette/all/000/airmonitor/sensors/temp
120,uint322ascii,huette/all/000/airmonitor/sensors/hum
121,uint322ascii,huette/all/000/airmonitor/sensors/airq
122,uint322ascii,huette/all/000/airmonitor/sensors/pm2_5
123,uint322ascii,huette/all/000/airmonitor/sensors/pm10

Explanation for the 1st Line: For example our Doorstatus is published on the CAN-Bus every second with the CAN-ID 112 (decimal). can2mqtt will take everything thats published there and will push it through to mqtt-topic huette/all/a03/door/sensors/opened.

convert-modes

Here they are:

none

does not convert anything. It just takes a bunch of bytes and hands it over to the other side. If you want to send strings, this will be your choice.

uint82ascii / uint162ascii / uint322ascii / uint642ascii

On the can2mqtt way it takes 1, 2, 4 or 8 byte and interprets it as an uint of that size and parses it to a human readable string for the mqtt side. The other way round this convert motde takes an int in a string representation and sends out an array of bytes representing that number (little-endian)

2uint322ascii

This one is a bit special but all it does is that it takes 8 bytes from the CAN-Bus and parses two uint32s out of it and sends them in a string representation to MQTT. The two numbers are seperated with a simple space(" "). MQTT2CAN-wise it takes two string representations of numbers and converts them to 8 bytes representing them as 2 uint32.

bytecolor2colorcode

Converts an bytearray of 3 bytes to hexadecimal colorcode

pixelbin2ascii

This mode was designed to adress colorized pixels. MQTT-wise you can insert a string like "<0-255> #RRGGBB" wich will be converted to 4 byte on the CAN-BUS the first byte will be the number of the LED 0-255 and bytes 1, 2, 3 are the color of red, green and blue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].