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.
Edit: This would probably be helpful, this is the data I am sending from the root node: 4203:in_3:hello world again
and this is what I get: 4203:in_3:hello world ag
Looking into the source of size_t RF24Network::read
bufsize = min(maxlen,frame_size-sizeof(RF24NetworkHeader));
That are at most 24 bytes.
I have tried payloads larger than 24 bytes, it works. Somehow, the lib supports a FRAGMENTATION feature. 72-byte payload works on UNO, but not bigger.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.