CAN bus transport implementation
-
Question: Is your gateway connected to some controller software?
Afaik, MySensors won't work propperly without, this is what you experience as problems with ID request and transport layer reset. Though there are options to get around that, I'd strongly recommend to involve one. -
a request for information, how to do :
to add the CAN transport you have to modify the files or replace them with what exists ?
- MyTransportCAN.cpp
- MyTransportHAL.h
https://github.com/mysensors/MySensors/pull/1488/commits/492aa631298d5960b4060f94084cdafaaad18f21
I will maybe test the work of AdamSlowik
-
Hi @JeeLet, to test my implementation You should:
- Set up hardware as described in my first post in this thrread.
- Download source from my fork (https://github.com/AdamSlowik/MySensors/archive/refs/heads/development.zip)
- Somewhere in Your lib folder swap official MySensors files with those downloaded.
- Upload "CANSwitch.ino" to first arduino and "GatewaySerialCAN.ino" to second one. Both files can be found in examples.
If everything is fine then You Should get results similar to those presented in my post dated to "14 Jul 2020, 20:42"
Please let Us know if You managed to reproduce My results.
-
Hello
thank you for the answerquestions:
-
which CAN library did you start on,
mcp2515.h or mcp_can.h ...etc -
the management of Float values is also managed ?
(numbers with decimals )
like this library which manages Floats https://github.com/pierremolinaro/acan/search?q=float -
and of course any CAN card is managed, like this one https://www.gotronic.fr/ori-module-bus-can-sbc-can01-28405.jpg
I prepare another test computer for the installation of your version :)
Translated with www.DeepL.com/Translator (free version)
-
-
1
- which CAN library did you start on,
I have used https://github.com/coryjfowler/MCP_CAN_lib
This library is embedded in code in my fork, so if You are going to test My fork You don't have to worry about underlying library. Consider it an implementation detail. If You are going to implement CAN bus transport at Your own, You can pick different library.2
- the management of Float values is also managed ?
I did not tested transferring float numbers over CAN network, however in my opinion such concern is out of the scope of protocol implementation. During implementation My goal was to transfer array of bytes from one arduino to another via CAN. I don't care how those bytes are interpreted. Those bytes can be Strings, ints, floats, images etc. It should not matter.
3
- and of course any CAN card is managed, like this one https://www.gotronic.fr/ori-module-bus-can-sbc-can01-28405.jpg
Any CAN module supported by underlying library should be ok (so after all it's not an implemantation detail). Library readme says it will work with MCP2515 and MCP25625. Module picked by You (https://www.gotronic.fr/art-module-bus-can-sbc-can01-28405.htm) have MCP2515+MCP2562 so You should be god. Module used by Me had MCP2515+tja1050. Yours transciever is different then mine, however I hope it doesn't matter
4
I prepare another test computer for the installation of your version :)
I would really appreciate Your feedback
-
"you can choose a different library"
I like this freedom of choice, my questioning is not necessary :)"I would really appreciate your comments"
yes yes in 4 to 5 days, theoreticallyFinally a high reliability Wired Bus for MySensors with the MyS protocol which is extraordinarily rich.
(the RS485 bus is good, but the cables/wiring must be more rigorous and the management of collisions more delicate for X Nodes, and the CAN bus is a good field bus ) -
Hello
to save time, you can tell me more about the configuration of MCP_CAN_lib
not all settings are shown on the MyS sketch :)
here in an example https://github.com/coryjfowler/MCP_CAN_lib/blob/master/examples/CAN_receive/CAN_receive.ino
there are some parameters to adjustor the filters https://github.com/coryjfowler/MCP_CAN_lib/blob/master/examples/Extended_MaskFilter/Extended_MaskFilter.ino
can you indicate me the files in question ???
(I think I have found but to confirm)to make it clean
thanks
-
So I have pull up some config parameters. Those are defined and briefly described in:
https://github.com/AdamSlowik/MySensors/blob/development/MyConfig.h
lines 270-315
You can set those parameters to different values, but for first run I suggest deploy examples without modifications. By examples I mean those 2 files:
https://github.com/AdamSlowik/MySensors/blob/development/examples/CANSwitch/CANSwitch.ino
https://github.com/AdamSlowik/MySensors/blob/development/examples/GatewaySerialCAN/GatewaySerialCAN.inoIf it fails I would set:
CAN_CLOCK to MCP_16MHZ
because i think can module from Your vendor uses 16MHz (My used 8MHz)filters are set in:
https://github.com/AdamSlowik/MySensors/blob/development/hal/transport/CAN/MyTransportCAN.cpp
line 37 method _initFilters()
without clear reason (eg. bug) I would recommend to not alter it.
Filters are set to drop messages not intended for certain node. Thanks to this MCU do not have to handle 'spam'.If My answer answers Yours questions then great. If this is insufficient ask for a specific parameter or line in code I will try to answer any questions asap
-
a start of error messages return (on both sketches)
IDE version 1.8.19for CANSwitch.ino
the message returns me to the line
MyTransportCAN.cpp --->
163 : ",TOTAL=%"PRIu8",CURR=%"PRIu8",TO=%"PRIu8",FROM=%"PRIu8"\n"), header, messageId, totalPartCount,
228 : ",TOTAL=%"PRIu32",CURR=%"PRIu32",TO=%"PRIu32",FROM=%"PRIu32"\n"), rxId, messageId,the one copy (a part) of the IDE
In file included from /home/mci/Arduino/libraries/MySensors-development/MySensors.h:395:0, from /tmp/arduino_modified_sketch_39381/CANSwitch.ino:43: /home/Arduino/libraries/MySensors-development/hal/transport/CAN/MyTransportCAN.cpp:163:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix] ",TOTAL=%"PRIu8",CURR=%"PRIu8",TO=%"PRIu8",FROM=%"PRIu8"\n"), header, messageId, totalPartCount, ^ /home/Arduino/libraries/MySensors-development/hal/transport/CAN/MyTransportCAN.cpp:163:32: war...... ^... /home/Arduino/libraries/MySensors-development/hal/transport/CAN/MyTransportCAN.cpp:228:18: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix] ",TOTAL=%"PRIu32",CURR=%"PRIu32",TO=%"PRIu32",FROM=%"PRIu32"\n"), rxId, messageId, ^ /home/Arduino/libraries/MySensors-development/hal/transport/CAN/MyTransportCAN.cpp:228:34: warni..... -
https://sourcecodeartisan.com/2021/03/06/invalid-suffix-on-literal.html
for the Error code it is
a requirement in C++ 11 (or later).lines 163 and 228 modify and error resolved
.../hal.transport/CAN/MyTransportCAN.cpp
CAN_DEBUG(PSTR("CAN:SND:CANH=%" PRIu32 ",ID=%" PRIu8 ",TOTAL=%" PRIu8 ",CURR=%" PRIu8 ",TO=%" PRIu8 ",FROM=%" PRIu8 "\n"), header, messageId, totalPartCount,CAN_DEBUG(PSTR("CAN:RCV:CANH=%" PRIu32 ",ID=%" PRIu32 ",TOTAL=%" PRIu32 ",CURR=%" PRIu32 ",TO=%" PRIu32 ",FROM=%" PRIu32 "\n"), rxId, messageId,:+1:
-
a topo of the day
on the hardware side, I got screwed with an arduino pin that became too soft, too dilated, look for an hour before understanding why no dialog.
Otherwise, on the Gateway side, no problem, MyController recognized well.
and CAN_Switch.ino is good too, my Widget on MyC switches well on the switch change.
listing of the dialog pour le Node 51 (set up in a fixed place )
coter log from MyC:
2022-06-11T18:49:35.167+0200 recd 0;255;3;0;9;1482640 TSF:MSG:READ,51-51-0,s=4,c=1,t=16,pt=1,l=1,sg=0:1 2022-06-11T18:49:35.170+0200 recd 51;4;1;0;16;1 2022-06-11T18:49:35.179+0200 recd 0;255;3;0;9;1482653 TSF:MSG:READ,51-51-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0 2022-06-11T18:49:35.182+0200 recd 51;255;3;0;21;0coter IDE from MyS:
67889 TSF:MSG:BC 68197 TSF:MSG:SEND,51-51-0-0,s=255,c=3,t=21,pt=1,l=1,sg=0,ft=0,st=OK:0 68203 TSF:MSG:READ,0-0-255,s=255,c=3,t=20,pt=0,l=0,sg=0: 68208 TSF:MSG:BC 68836 TSF:MSG:SEND,51-51-0-0,s=255,c=3,t=21,pt=1,l=1,sg=0,ft=0,st=OK:0 68843 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255 68848 TSF:TDI:TSL 68849 MCO:SLP:WUP=-1 ........ it is incompletewell now we have to calm down the CAN bus dialog, the Rx/Tx Led of the gateway looks like a Christmas tree :)tomorrow I'll test a CAN_Switch version2 sketch
-
test with the digital output inputs of 2 Arduino on CAN Bus.
- status of a button and control of a led with MyC
a proof in video that it is functional :)
all is not functional, on the end of the video, the reset or reboot does not work, (but functional with the RS485 bus)
.... to follow ;)
(now the Analog values, decimal to test )I would like to test the Node to Node with the filtering.
a question : is it difficult to put the filters on the MySensors sketch ???there are still MySensors on the forum ???
if yes, a help for Adam Slowik would be a great thing.
implement it in MyS Yes YesThanks
-
@JeeLet as I can see You had bussy weekend. I was AFK so I was unable to respond. Within working days I should be able to respond quicker.
@JeeLet said in CAN bus transport implementation:
lines 163 and 228 modify and error resolved
Can you push Your fix to My repo?
@JeeLet said in CAN bus transport implementation:
a proof in video that it is functional
Great job! I never was at this stage.
@JeeLet said in CAN bus transport implementation:
all is not functional, on the end of the video, the reset or reboot does not work, (but functional with the RS485 bus)
.... to followCan You provide (gateway/node) logs from reset scenario. It would be great to have those logs either for RS485 and CAN so I can compare them.
@JeeLet said in CAN bus transport implementation:
I would like to test the Node to Node with the filtering.
a question : is it difficult to put the filters on the MySensors sketch ???Could You describe what kind of test You would like to perform? Right now there is no way to set filters from the sketch. I think it should stay this way.
Perhaps We have different things in mind when We think about filters. I'll try to describe how I see this.
When it comes to CAN frame there is header and body. Header contains metadata and body contains data. mcp2515 can filter frames based on header content. Header contains id of destination node. Based on this id filters are set to drop any messages not intended for current node. This way if gateway want to send message to node with id=51 only node with this id receives this message.
There is exception for this rule. Messages with destination id set to BROADCAST_ADDRESS reaches all nodes.
With this in mind I see no reason to set filters differently. Of course I can be wrong.
Composition of header is described in MyTransportCAN.cpp in method _buildHeader()
As of now my all can modules and arduinos are burried in some box at My attic so I am unable to test anything
-
"Can you provide logs (gateway/node) from the reset scenario. It would be great to have these logs for RS485 and CAN so I can compare them."
Released today 2 gateways connect to MyController
- UNO_usb - Gateway and RS485 bus
- UNO_usb - Gateway and CAN Bus
with connect, a UNO with the basic sketch "RelayWithButtonActuator_base.ino" (slightly modified)
with ... a Led and a Switch, for each bus.The Listing split in several parts
"Log of the IDE and MyC for the two types of bus (node34 and node 54), CAN and RS485.
- Listing Action RESET with MyController 2 parts for CAN and 2 parts for RS485 and - Listing Action On/Off on the node switch or with MyController 4 parts for CAN and 4 parts for RS485No error on the Reset, it works fine, an error from me.
Oh yes, I even found an error :)
the sendSketchInfo("test xxxxx", "1.0"); is not upsee the end of the video
video....I will answer the other question tomorrow.
-
@Adam-Slowik "Can you push your patch to my repository? " .... I don't know how
On the CAN principle
@Adam-Slowik "Based on this id, the filters are configured to remove all messages not intended for the current node. This way, if the gateway wants to send a message to the node with id = 51, only the node with that id receives that message." ... yes, that's how I see it.
another way to say/explain it.
"The philosophy of CAN is to constitute a messaging system.
The messages (the letter) send on the CAN Bus (the post office), distributed by the CAN Bus (the letter carrier).Each (letter) have each an identifier (stamp of the post ☺ ) that ... identifies it.
And put in the right mailbox (the MCP2515) according to the choice of filter/mask ( color, scent? ☺ ) of the letter."So there are two "stratum" of dialogue / work.
- one on the Can Bus, and another on the Nodes.
The idea is to relieve the Nodes of unnecessary work/effort with the risks that this brings. Less letter to open :)
@Adam-Slowik "... my modules and arduinos are buried in a box in my attic..." ? Arduino 8bit and MySensors is over for you?
( if it's a personal / family reason don't say anything ) -
I tested my sketch with clock and OLED to see :)
bah No the time is not up :(
I give this information for an overview, it can help for the continuation (but not to give you work :) )
The listing of the messages of mySensors
test with "void receiveTime" function (without RTC clock)
https://forum.mysensors.org/topic/4809/real-time-clock-module-lcd-display-and-controller-time/8?_=1655208396048..........Log MyC - terminal ssh ......... 2022-06-14T14:01:45.115+0200 recd 0;255;3;0;9;65310350 TSF:MSG:READ,55-55-0,s=255,c=3,t=1,pt=0,l=0,sg=0: 2022-06-14T14:01:45.119+0200 recd 0;255;3;0;9;65310356 TSF:MSG:ECHO REQ 2022-06-14T14:01:45.127+0200 recd 0;255;3;0;9;65310360 TSF:MSG:SEND,0-0-55-55,s=255,c=3,t=1,pt=0,l=0,sg=0,ft=0,st=OK: 2022-06-14T14:01:45.127+0200 recd 55;255;3;0;1; 2022-06-14T14:01:45.146+0200 sent 55;255;3;0;1;1655215305 2022-06-14T14:01:45.160+0200 recd 0;255;3;0;9;65310394 TSF:MSG:SEND,0-0-55-55,s=255,c=3,t=1,pt=0,l=10,sg=0,ft=0,st=OK:1655215305..........Log MyS - terminal IDE ......... time current:0 ------------------------------------------- 58007 TSF:MSG:SEND,55-55-0-0,s=255,c=3,t=1,pt=0,l=0,sg=0,ft=0,st=OK: 58017 TSF:MSG:READ,0-0-55,s=255,c=3,t=1,pt=0,l=0,sg=0: 58022 TSF:MSG:ECHOavec Bus RS485
..........Log MyC - terminal ssh ......... 2022-06-14T14:22:41.265+0200 recd 0;255;3;0;9;72000090 TSF:SAN:OK 2022-06-14T14:22:41.274+0200 recd 0;255;3;0;9;72000096 TSM:READY:NWD REQ 2022-06-14T14:22:41.298+0200 recd 0;255;3;0;9;72000115 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK: 2022-06-14T14:22:41.917+0200 recd 0;255;3;0;9;72000736 TSF:MSG:READ,22-22-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0 2022-06-14T14:22:41.920+0200 recd 22;255;3;0;21;0 .........Log MyS - terminal IDE ......... time current:1422 ------------------------------------------- 423956 TSF:MSG:READ,0-0-255,s=255,c=3,t=20,pt=1,l=1,sg=0:0 423962 TSF:MSG:BC 424008 TSF:MSG:SEND,22-22-0-0,s=255,c=3,t=21,pt=1,l=1,sg=0,ft=0,st=OK:0 requestOn----------------------------------------- -
@JeeLet said in CAN bus transport implementation:
Arduino 8bit and MySensors is over for you?
No it is not over. Right now I don't have enough time. Now I am able to work for let's say 1 hour per week. Probably I will become more active at the end of 2023 :D
@JeeLet said in CAN bus transport implementation:
bah No the time is not up
Here You posted RS485 version:
https://forum.mysensors.org/topic/4809/real-time-clock-module-lcd-display-and-controller-time/8?_=1655208396048Could You post here CAN version?
-
@Adam-Slowik "Could you post the CAN version here?"
it's the same, except that the bus is not rs485 but CAN :)
...... ........ #define MY_NODE_ID 55 /*Node en ID static*/ #define MY_CAN #include "SSD1306Ascii.h" ........ .....but I'll go back to PaulStoffregen's Lib <TimeLib.h> to see if I can simplify the basic sketch of MySensors
-
In previous example (with diodes) did You set CAN_CLOCK to MCP_16MHZ?
-
no it stayed on 8Mhz ?
I didn't modify anything (the other sketches work)
But I just looked at the quartz and it's 16M!! (SW-65-16M)
I am lost :(
https://www.gotronic.fr/art-module-bus-can-sbc-can01-28405.htm
but on the doc there is :
The 8000000 stands that the MCP2515 operates with a clock of 8 MHz. This
depends on the quartz used and may need to be adjusted.error
on the official doc it's a 16Mhz like mine.- https://www.joy-it.net/en/products/SBC-CAN01
OSCILLATOR 16 MHz Crystal Oscillator
so 8Mhz or 16Mhz?
and why does it work with the previous sketches? - https://www.joy-it.net/en/products/SBC-CAN01