CAN Bus gateway integration

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
Post Reply
vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

CAN Bus gateway integration

Post by vaxr01 » Saturday 27 May 2017 16:17

Hello !
For more than a year I started to use Domoticz on a old laptop (Acer 5601 with broken screen) which is very sufficient to manage home automation and more.
I connected many devices, like USB300 enocean, or RFlink and now I've decided to develop a hardware support for domoticz to add the possibility of connecting a bus CAN to Domoticz, and it's work ! :D
For this, I'have use a very low cost and effective gateway : the USBtin CAN gateway. (we use it in my company, I've already develop software in java to show the CAN activity and do diagnostic on our CAN bus).
Actually I've created the management of the gateway :
Image
And now I'm working to add a full support of the "SFSP lighting module" (which we now call : "light air switch", you can find some information on internet).
I would like to know if it's possible to contribut in Domoticz developpment and how to because I've never use Github ;)
thanks

domoticzcan
Posts: 5
Joined: Wednesday 05 July 2017 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: CAN Bus gateway integration

Post by domoticzcan » Wednesday 05 July 2017 14:36

Hello vaxr01

I have very interest by your CAN bus gateway integration.
I have a project for school with domoticz and i have no idea to integrate can bus protocol.
I use the raspberry pi 3 and PICAN2 shield but i can use USBtin CAN.
I saw the message which explain that you have created the management of the gateway and software in java to show the CAN activity and do diagnostic on our CAN bus.
I would very much like you to explain to me the way in which you integrated the CAN protocol on domoticz.
The community is welcome to respond.

Thanks!!

domoticzcan
Posts: 5
Joined: Wednesday 05 July 2017 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: CAN Bus gateway integration

Post by domoticzcan » Monday 24 July 2017 14:10

Hello vaxr01

I have very interest by your CAN bus gateway integration.
I have a project for school with domoticz and i have no idea to integrate can bus protocol.
I use the raspberry pi 3 and PICAN2 shield but i can use USBtin CAN.
I saw the message which explain that you have created the management of the gateway and software in java to show the CAN activity and do diagnostic on our CAN bus.
I would very much like you to explain to me the way in which you integrated the CAN protocol on domoticz.
The community is welcome to respond.

Thanks!!

vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

Re: CAN Bus gateway integration

Post by vaxr01 » Monday 07 August 2017 8:52

Hello !
The gateway is manage like a serial device, so I've write a driver which can connect the gateway by serial to domoticz. After it's just some kind of simple command to manage gateway, to change CAN baudrate, open the CAN, close the CAN, reset the gateway if problem,etc...
But after that you need to write a layer to manage the CAN according to what you connect (CAN Open, CAN J1939, proprietary, etc...) or you just want to do "Free" can system ?

domoticzcan
Posts: 5
Joined: Wednesday 05 July 2017 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: CAN Bus gateway integration

Post by domoticzcan » Monday 07 August 2017 15:12

Hello vaxr01
Thanks you for your reply.
Currently, I use USBtin CAN and I just want to do ''Free'' can system.
To create a driver which can connect the gateway, what's the software used ?
I don't make a driver, can you give the documentation which explain the build of driver ?
After the build of driver, domoticz software recognize automatically the device?
Yes, I know the command to manage gateway, to change CAN baudrate, open the CAN, etc....

Thanks!!

vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

Re: CAN Bus gateway integration

Post by vaxr01 » Monday 07 August 2017 19:32

Ha ok ! So if you want to integrate it in domoticz like me you must write a hardware driver by following the short tutorial here :
https://www.domoticz.com/wiki/Developin ... are_plugin
I thinks it's the only way to do it.
I've started it here on my github but not finish (only the base).

domoticzcan
Posts: 5
Joined: Wednesday 05 July 2017 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: CAN Bus gateway integration

Post by domoticzcan » Wednesday 09 August 2017 18:34

Thanks for the link to write a hardware driver.
Can you give me the link of your github ?

vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

Re: CAN Bus gateway integration

Post by vaxr01 » Wednesday 09 August 2017 20:34

(oh, forgot the link) https://github.com/Reivax851/domoticz . I think you will quickly understand how it works !
PS: Actually I've not tested it on a windows server (only linux), if you do it'll be a good thing to give feedback.

domoticzcan
Posts: 5
Joined: Wednesday 05 July 2017 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: CAN Bus gateway integration

Post by domoticzcan » Thursday 10 August 2017 19:49

Thank you so much.

The last question : After making all the changes using the tutorial, you only have to compile the makefile and then you get USBTIN recognition.

vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

Re: CAN Bus gateway integration

Post by vaxr01 » Thursday 10 August 2017 22:54

Yes, exactly ! ( the USbtin must be recognized in /dev with ttyACMx (x = 0 if you have just the USBtin, but if you have over serial device it can be 1, 2, etc...). Personnaly I have link the ttyACM0 of my USBtin to ttyUSBtin ;-) this is more convenient !

kimot
Posts: 49
Joined: Saturday 25 November 2017 18:18
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: CAN Bus gateway integration

Post by kimot » Saturday 02 December 2017 0:31

CAN bus, well.
But what protocol between CAN bus devices?
CanOpen is wery huge for simply controllers, like Arduino etc.
And CAN message has only 8 bytes of data.
Of course, we can use some EXT ID bits too.
I try to integrate CAN bus to MYsensors project, but problem is, that domoticz sends data to Mysensors like strings, and 8 bytes are not enough in most cases.
I Try rewrite some libraries of MySensors, but now I think, the better way for me is code my own CAN bus ethernet gateway.
I love like ESPesay communicate with Domoticz, when I am able send JSON commands to domoticz and events from domoticz to ESPeasy.
I am planing translate this commands to my CAN protocol and vice versa.
About my CAN protocol.
I am using extended 29bit ID, first 6 bits are receivers ID, so I can set mask and filter registers so, that I receive only messages for my node or broadcast.
Others bits in ID and in payload I use for senders ID, sensor ID,message type , data type, data and etc.
( like Mysensors protocol )
I am using MCP2515 module.

I am able code to one CAN message:
6 bits - destination
6 bis - sender
(gateway, broadcast, 62 nodes - it is enough for me for one bus. I plane three buses and gateway can " translate " or "expand" nodes ID from and to controller )
1 bit - RACK
1 bit - IS ACK
3 bits - command
6 bits - type ( MY sensors has 56 types max. now )
6 bits - sensor id ( only 64 sensors per node ... )
3 bits - payload type ( int, uint, long .... )

The sum of these is not 29, but 32 so I am using a little "hacking" data length field in CAN frame to obtain additional 3 bits.
For data I have got 8 bytes.
It is enough for conventional data types from char to floating point.
Only text messages are limited to 8 bytes. But for us, old boys, who remember old DOS file names, it is enough.
Now I am able send data between nodes and between nodes and gateway.
I try a "stress test" like here:
https://forum.mysensors.org/topic/5051/ ... tress-test

I send 10 000 messages from two nodes to "gateway" at some time ( 22kbps ).
Result - zero messages lost.
But it is expectable with CAN.

Now I must connect this to Domoticz :o(

vaxr01
Posts: 7
Joined: Sunday 19 March 2017 16:10
Target OS: Linux
Domoticz version:
Location: France
Contact:

Re: CAN Bus gateway integration

Post by vaxr01 » Monday 11 December 2017 23:04

If you want to integrate a CAN device in Domoticz the best way is to do the same like the RFXcom or RFlink. You must create in first the hard driver of your gateway and Only after creates all the CAN layer you want (like CanOpen if you want...).
This is what I've do with the USBtin CAN Gateway, hard driver one side and all layers you want one another side.
I've not say it's easy ;-)
( CanOpen is so easy, J1939, Isobus or NMEA2000 are more more complex, I'm embedded developer on stm32, I know what I mean ;) )

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests