how to save data coming from CanBus into 1 string ?

Hello ,
I'm using Henry's Bench code for reading canbus
and it's working great - and I see all the information on the serial monitor .
now I want to be able to save it into string \ array
how can I do this?
what do I need to setup ?

so in the end iwill have a string with this data inside : rcv - rxID - CanBusData

I was able to save it into a SD card , but I don't know how to save it into a string...

if (CAN_MSGAVAIL == CAN.checkReceive())           // check if data coming
  {

    //  Serial.print("got data ");
    rcvTime = millis();
    CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

    rxId = CAN.getCanId();

// if (rxId == (0xC6 , HEX))
//      {
//        rxId = "david";
//      }
      
    Serial.print(rcvTime);
    Serial.print("\t\t");
    Serial.print("0x");
    Serial.print(rxId , HEX);
   
    Serial.print("\t");

    myFile = SD.open("data.txt" , FILE_WRITE);

    myFile.println(rcvTime);
    myFile.print("-");
    myFile.print("0x");
    myFile.print(rxId, HEX);
    myFile.print("-");


    for (int i = 0; i < len; i++) // print the data
    {
     
      if (buf[i] > 15)
      {
       
        Serial.print("0x");
        Serial.print(buf[i], HEX);
        myFile.print("0x");
        myFile.print(buf[i], HEX);
        

      }
      else
      {
        Serial.print("0x0");
        Serial.print(buf[i], HEX);
        myFile.print("0x0");
        myFile.print(buf[i], HEX);
      }

      //Serial.print("0x");
      //Serial.print(buf[i], HEX);

      Serial.print("\t");
    }
    Serial.println();
    myFile.close();

Thanks ,

now I want to be able to save it into string \ array

Why? What do you intend to do with the string? The data is already in an array, so that part of the statement is meaningless.

OK - so maybe I didn't explain myself :

how can I see the buf array?
I want to print it as it is -1 long line
So I will be able to compare it to known information
Thanks ,

how can I see the buf array?

You didn't seem to have any trouble writing it to the SD card. So, I can't see why you'd have any trouble "see"ing it. For whatever definition of "see" you have in mind.

I want to print it as it is -1 long line

Do you want +1 long line? -4 lines?

this is my problem , how to save it into a array ot string
in the file it was easy - becasue I know how to write into a file .
but I don't know how to "save" into my own string so I can compare it after it.

this is what in the monitor

2234510 0x18FEF530 0x38 0x37 0x36 0x35 0x34 0x33 0x32 0x31

I want to save this line and "see" it as:

2234510-0x18FEF530-0x380x370x360x350x340x330x320x31

hope now it's more understoodable \ easy to understand :slight_smile:

What I have thought to do is this :

unsigned char FinalInfo[10];
unsigned char buf[8];

then

FinalInfo[0] = (rcvTime); 
FinalInfo[1] = (rxId);

for (int i = 0; i < len; i++) // print the data
    {
     
      if (buf[i] > 15)
      {
       
        Serial.print("0x");
        Serial.print(buf[i], HEX);
        myFile.print("0x");
        myFile.print(buf[i], HEX);
        FinalInfo [i+2] = (buf[i] , HEX);

      }
      else
      {
        Serial.print("0x0");
        Serial.print(buf[i], HEX);
        myFile.print("0x0");
        myFile.print(buf[i], HEX);
        FinalInfo [i+2] = (buf[i] , HEX);
      }

      //Serial.print("0x");
      //Serial.print(buf[i], HEX);

      Serial.print("\t");
    }
    Serial.println();
    myFile.close();

I know I can do it - but now how can I save it as ONE string?

in the end I would like to compare FinalInfo with known data

Thanks ,

        myFile.print(buf[i], HEX);
        FinalInfo [i+2] = (buf[i] , HEX);

Why would you want to store 16 in the i+2 position of the array?

You you want to store the data in an array, or a string representation of the data?

if you want to store a string representation of the data, you'd use a char array that was long enough, and sprintf() with the appropriate format string, to populate (and NULL terminate) the array, resulting in a string.

sorry - but I didn't understand you .
I will explain what I did :
myFileprint(buf , HEX); - give me the correct value of the data from buf array - for example "38"
I thought that if i will do the same things in my new array called "FinalInfo" - I will get the same number -"38"
this is OK correct right?
now I want to take all there is in FinalInfo , which wiil be something like {test,22.11,1,2,3,4,5,6,7,38}
and change it to string :
test-22.11-1-2-3-4-5-6-7-38
I don't think I can explain this easier what I want to do....
please tell me you unserstand where I'm going with this
Thanks ,

any idea?

can't be the first one who want to do it ...