I am using NRF24 to send messages from one to another Arduino.
The code looks like this
if(condition){
unsigned long message = 10;
RF24NetworkHeader header(node04); // (Address where the data is going)
bool ok = network.write(header, &message, sizeof(message)); // Send the data
}
On the receiver side it looks like this:
network.update();
while ( network.available() ) { // Is there any incoming data?
RF24NetworkHeader header;
unsigned long message;
network.read(header, &message, sizeof(message)); // Read the incoming data
if (message == 10){
do something;
}
If I want to do something at a receiving site, I need to write an if statement and specifically tell Arduino what to do.
What I would like is a code that would tell receiving site, what to do.
Example.
I want to turn on RGB led and buzzer.
r = 255
g = 050
b = 0
buzzer = 1
I would like to send a code 2550500001 and the receiving arduino would decode it.
I know how to make the code. Message = r10000000 + g100000 + etc...
Question: Is there some way to decode this message?
Send a struct containing the values to be used by the receiver. That way you send a single message that is easily decoded and used. Alternatively add delimiters between the data items that you send and parse it in the receiver code using the delimiters
Personally I would favour using a struct because it allows you to use meaningful variable names within it
I'll bet that works. But, as has been discussed here many times (strict C++ typing, undefined behavior, etc), that should probably be replaced with a read() into a uint8_t buffer followed by a memcpy() into receivedData.
EDIT:
Sorry, my bad. The read function uses memcpy().
Thank you, was just reading many threads about sscanf(), I am pretty used to parsing with https://regex101.com/ so this looks a bit similar, so I think I will get it to work. Thanks