How to connect multiple node using Can id

hi i am new for Embedded , i want to communicate multiple device using Can protocols using node ID ,

for example i want to communicate 10 devices, theses ID also 1to 10; how i will select the id and i want to sending the string={“kalaivananworkingthecanbuscommunication”}received the string={“thecanbuscommunicationworkingfine”}

#include "mbed.h"
#if defined (DEVICE_CAN) || defined(DOXYGEN_ONLY)
Serial pc(USBTX,USBRX); 

Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);

 CAN can1(PD_0, PD_1);
 CAN can2(PB_5,PB_6);

//char counter []= {'0','8','5','9','5'};
char counter = 0;

void send()
{
    printf(" Start to send the Data \n");
    if(can1.write(CANMessage(1, &counter, 1)))   //id data second
    {
        printf("Sending Data Done \n");
        counter++;
        printf("Message sent: %d \n", counter);
    } 
    led1 = !led1;
}

int main() 
{
    pc.baud(9600);
    can1.frequency(115200);
    can2.frequency(115200);

    printf("main()\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1) {
       // printf("loop()\n");
        //if(can1.read(msg))
        if(can2.read(msg))
        {
            printf("Message received: %d\n", msg.data[0]);
            led2 = !led2;
            wait_ms(300);
            printf(" Start to send the Data \n");
    }
}

}
#else
  #error CAN NOT SUPPORTED
  
#endif

these code working fine in my Nucleo F767ZI
pls help …

Hello,

because the CAN is based on 8 bytes frames then you need to split the string (Len of string / frame size) and develop an own protol that will determinate start and stop of the complete message.
Something similar is used in cars with diagnostic tools. Where the CAN is just lower layer what is used by (for example) KWP2000 which is upper layer and real data are just in few bytes and the rest are for KWP2000 addressing and commands and so on - ISO 15765-2 - Wikipedia

Also CAN::filter can be useful for set just specific ID to one specific device - Mbed OS Reference | CAN Class Reference

BR, Jan