Go Down

Topic: NRF24 array of char doubt (Read 785 times) previous topic - next topic

Carlcox89

hi,
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)
{
  network.update();

   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 #");
  Serial.print(to_node);
  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

PeterH

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.

michinyon

Which line in your code,   is line 89 ?

Carlcox89

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

Go Up