I have a setup consisting of two Tx's sending data to one receiver.
Since the package Data structure has aleary 31 bytes, I decided not to use a vaiable to identify each transmitter and assigned one pipe to each TX instead.
On the receiver side, data would be identified by this code:
uint8_t pipe;
pipe = 1;
// for debugging
if(serialPrintFlag == true){
Serial.print("before checking....pipe= ");
Serial.println(pipe);
}
if (radio.available(&pipe)){
// for debugging...
if(serialPrintFlag == true){
Serial.print("after checking..pipe= ");
Serial.println(pipe);
}
if (pipe == 1){ // Changed Jan 2024 check pipe 1 => Cisterna
getCisternaData(); // Changed Jan 2024
}
if (pipe == 2){ // Changed Jan 2024 check pipe 2 => Caixa
getCaixaData(); // Changed Jan 2024
}
but it does not work.
It is probably a stupid mistake for I have been reading forums & tutorial for hours now and I still don't get it.
Can anyone help?
PS I have not posted the entire Tx's & RX codes here because two of them has more than 1100 lines, so I am trying to stick to the issue and made the other people life easier.
You can always pick one of the bytes that will ALWAYS have a low numeric value and set the high order bit to 1 for one sender and to 0 for the other sender.
Post the exact data structure of the payload. I'd be willing to bet there's opportunity for compaction. Also, which Arduino board? On 32-bit architectures you can use the "packed" attribute to recover space "lost" to default data alignment.
Here is the data structure
In my setup there are two Arduinos ProMicro (the Tx's) send data for a ESP32 (the RX) so I took long time to figure out that I had to align the data.....
// Structure of our payload
// ESP32 group data in 4 bytes chunks, so data structure has to be rearranged
//The data to be transmitted by lower and upper water tanks modules is:
// type cisterna caixa superior
// ------- ---------- --------------
// 1 float Irms auxVol (last pumping cycle volume)
// 2 float flow flow
// 3 float Pdisch totalLiters
// 4 float DpFilter flowPoco (added July 2023)
// 5 float Pinlet dummy2
// 6 float lampCurrent dummy4 //added in March 2021
// 7 int rawDp rawDp
// 8 bool flapstate dummy3
// In Jan 2024 rev 0 on, dummy variables on Cx Superior will be assigned a value 0f -100, which will
// be used by the receiver to identify the data belongs to Caixa Superior
// Structure of our payload
struct payload_t // 32 bytes max, used=7*4+2+1 = 31 bytes OK! corrected March 2023
{
uint32_t counter; // - 4 bytes number of packets transmitted
float val1; // - 4 bytes
float val2; // - 4 bytes
float val3; // - 4 bytes
float val4; // - 4 bytes
float val5; // - 4 bytes
float val6; // - 4 bytes
int16_t val7; // - 2 bytes
bool val8; // - 1 byte
};
payload_t payload; // create a variable with the above structure
I'm thinking have a data alignment problem. Print the 'sizeof()' macro result for that data structure on both the ProMicro and ESP32. I'm willing to bet they will be different. The int16_t and bool will likely occupy 4 bytes each on the ESP32. That's why I mentioned the packed attribute.
You also didn't specify the radio type. What are TX and RX?
As for the amount of data, you may need to break the payload into two packets. Then it gets even trickier as you'll need to identify the packet type AND it would be possible to receive interleaved packets from the two TXs causing even more confusion. You'll need to work out a protocol so the two TXs don't stomp on each other.
Thank you for your reply gfvalvo.
This data structure works, since I could receive the correct values of both transmitters when I was using the RF24Netork library.
Well, you're using at a minimum 8 bits to transfer what can be represented in a single bit. The unused 7 bits could be used to represent up to 128 unique data sources, if you wanted to do a little programming. Or, is the structure out of your control?
I would replace the bool with two uint8_t variables (to keep the 32 byte size for the structure). Use one for bit flags. Replace the bool with a bit flag and you have 7 left for future expansion. Use the other one for your ID (I assume you won't have more then 256 devices).