Sending a char array using RF24Network on Arduino
I am trying to use the RF24Network library to create a sensor network in
which the root node connects to an MQTT broker using the PubSubCient
library.
I have done a basic test which relays the MQTT topic and message payload
from MQTT to one other node in the network, it does this by using sprintf
to create a delimited string of the current millis() time on the root
node, the topic and message which is stored in a car array of size 200 (as
the size of the RF payload must be predefined), I can see from serial
output that this is being done correctly.
However from the serial output of the receiving node I find that only the
first 24 characters of the string are being received and I am out of ideas
as to why this is the case.
Code for sending node:
void ByteToChar(byte* bytes, char* chars, unsigned int count){
for(unsigned int i = 0; i < count; i++)
chars[i] = (char)bytes[i];
chars[count] = '\0';
}
void callback(char* topic, byte* message, unsigned int length) {
Serial.println("Sending...");
char buf[length + 1];
ByteToChar(message, buf, length);
char payload[200];
sprintf(payload, "%lu:%s:%s", millis(), topic, buf);
Serial.println(payload);
Serial.println(sizeof(payload));
RF24NetworkHeader header(other_node);
bool ok = network.write(header, payload, sizeof(payload));
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
free(payload);
}
And receiving node:
while ( network.available() )
{
RF24NetworkHeader header;
char payload[200];
memset(payload, 0, 200);
network.read(header, &payload, sizeof(payload));
Serial.println(payload);
Serial.println(sizeof(payload));
free(payload);
}
It's not impossible that I have just overlooked something very simple. Any
help is greatly appreciated.
No comments:
Post a Comment