Go Down

Topic: NRF24 array of char doubt (Read 1 time) previous topic - next topic


i have the following payload
Code: [Select]

struct payload_t
  int from_node;
  char message[20];

i'm trying to do a function so i can just change the message that i want to send, but i'm having some problems with char* vs char :|

Code: [Select]
void loop(void)

   if (!sent) {
  char message_to_send[20];
  boolean status = sendMessage(light_node, this_node, message_to_send);
  if (status) {
    Serial.print(" [ok]");
    sent = true;
  } else
    Serial.print(" [failed}");


bool sendMessage(uint16_t to_node, uint16_t from_node, char *message){
  Serial.print("Sending to #");
  payload_t payload = { from_node, message};

  RF24NetworkHeader header(/*to node*/ to_node);
  bool ok = network.write(header,&payload,sizeof(payload));
  return ok;

the problem is baseNode:89: error: invalid conversion from 'char*' to 'char'..
how can i do this ?
I just want to send a different message that i create and then give to sendMessage 3rd argument


You can't initialise the structure like that - you need to copy the content of the string into the payload, for example:

Code: [Select]

strncpy(payload.message, message, sizeof(payload.message));

Note that in your example the variable message_to_send is uninitialised at the point you pass it to sendMessage().

If you want further help I suggest you post a complete sketch that demonstrates the problem - not just an extract.
I only provide help via the forum - please do not contact me for private consultancy.


Which line in your code,   is line 89 ?


thank you PeterH, i dont know how i forgot that :| shame on me.
it's solved now.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131