How to concatenate unit8_t array

Hello!!

I am trying to meger to value of type uint8_t.

Initialy, the code is as the following:

uint8_t data[] = "Recieved";
rf95.send(data, sizeof(data));

The things, I also sent the recieved value of buf

Serial.println((char*)buf);

Then I tied like this (I chnaged Recieved to Rec)

//uint8_t data[] = "Recieved:";
      uint8_t data[RH_RF95_MAX_MESSAGE_LEN];
      sprintf(data,"Rec:%d",buf);
      rf95.send(data, sizeof(data));

I also tried several soluiton

 sprintf(data,"Rec:%i",buf);
 sprintf(data,"Rec:%c",buf);
 sprintf(data,"Rec:%d",(char*)buf);

I think that for the third, (crag*) is not really usefull as buf is initially declared as uint8_t

uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

I also tried
uint8_t data[RH_RF95_MAX_MESSAGE_LEN];

data[strlen(data)]= buf;

or

data[strlen(data)]= (char*)buf;

but none of them work

Would it be possible to have a tips or hints?

Many thanks
Cheers

rf95.send(data, sizeof(data));

Both cases of your use of this statement are probably wrong. sizeof(data) includes the null at the end, in which case you will also send the null. You probably should be using:

rf95.send(data, strlen(data));

Pete

Would it be possible to have a tips or hints?

Ask yourself " Why am I trying to do this?"

Hello
Thank for your replies.

But the problem is not at this piont

rf95.send(data, sizeof(data));

By the way, I tried to change to

rf95.send(data, strlen(data));

but it generate an error

invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]

So I kept

rf95.send(data, sizeof(buf));

But no worries about that.

I got a value in buf

uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

And I can sent it as the following

uint8_t data[] = "Rec:";
rf95.send(data, sizeof(buf));

But initialy, my example show me this

uint8_t data[] = "Rec:";
rf95.send(buf, sizeof(buf));

My need is how to either add the value of buf to data in order to have

Rec:The_value_of_buf

Thank

I've read your post 5 times now and I still don't understand what you're trying to do. Please trying explaining more clearly. What are you trying to send? What is stored in 'buff'? Why are you trying to do this?

But no worries about that.

There are worries about that. You are sending one or more nulls to the other end which is probably confusing it.

This should compile.

rf95.send(data, strlen((const char *)data));

I suspect this is an X/Y problem. You have assumed that your problem is X and are asking us to fix a problem with concatenation when in fact the problem is really Y - sending one or more nulls which shouldn't be there.
In particular this code:

      uint8_t data[RH_RF95_MAX_MESSAGE_LEN];
      sprintf(data,"Rec:%d",buf);
      rf95.send(data, sizeof(data));

will send a large number of nulls after the actual string because you have told it to send RH_RF95_MAX_MESSAGE_LEN bytes. So if RH_RF95_MAX_MESSAGE_LEN is defined to be 64, you will send about 54 nulls at the end of the message. You NEED either to use strlen, or in some other way explicitly supply the TRUE length of the string.

So,

I am trying to meger to value of type uint8_t.

(a) - what does this mean?
(b) - WHY are you trying to do doing that? What is the real problem here?

Pete

Dear Pete
Thank for your observation and I am to look around. You ate right , i observe a lot of zero after the sent value.
I also will update my threat because I do not need to add a rec, before val. I can do it on the receiver devise and it's better in that way.

But you point out an interesting point improve!

Tanks