Pages: [1]   Go Down
Author Topic: NRF24 array of char doubt  (Read 702 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
i have the following payload
Code:
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 smiley-neutral

Code:
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
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which line in your code,   is line 89 ?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you PeterH, i dont know how i forgot that smiley-neutral shame on me.
it's solved now.
Logged

Pages: [1]   Go Up
Jump to: