How about wrapping up all your information into a structure, and sending the complete object via the nrf24l01, which works pretty well?
Where do I find the full documentation for using "structure"? Do they work like "record" in Turbo Pascal or like an object in Java?
What has been nagging me is the allocation or reservation of memory in the receiver sketch for the 16 bytes required by the bme280data object. This is where I think I am going wrong.
But returning to the struct object, I have found two methods of declaration that appear to be the same, OK let's just say they both work in practice.
This is the first method:
struct Message{ float temperature; float pressure; float altitude; float humidity; }; Message bme280data; // declare the message object
And this is the second:
struct Message{ float temperature; float pressure; float altitude; float humidity; }bme280data;
I don't know if one method has any advantages or disadvantages over the other.
As for memory allocation, I assumed that the following line in the receiver sketch
radio.read(&bme280data, sizeof(bme280data));
took the 16 received bytes and stored them in memory starting at the address referenced by bme280data. I guess I will have to take a look at the read() function in the RF24 library to find out exactly what it is doing.
The other option I was considering was to create a 16 byte char array to accept the incoming data and then writing the array directly to &bme280data.
As for the checksum, I could use the 16 bytes directly in an XOR routine and add the result to the struct object.
struct Message{ float temperature; float pressure; float altitude; float humidity; byte checksum; }bme280data;
Happy to help... what error messages did you encounter?
None, I am getting run time errors!!
The receiver is printing empty floats e.g.
0.00
0.00
0.00
0.00
Your declaration looks incorrect... Please try the following "Type Definition":
typedef struct Message{ float temperature; float pressure; float altitude; float humidity; } bme280data; bme280data MyObject; void setup() { Serial.begin(9600); MyObject.temperature = 1.011f;
Etc...
Just saw that you're also using the byte data type instead of the uint64_t data type for the address... try the correct data type and see if that makes any difference.
Just saw that you're also using the byte data type instead of the uint64_t data type for the address... try the correct data type and see if that makes any difference.
where exactly do you mean?
const uint64_t address = 01; //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
No change!! Still getting 0.00 floats on the serial monitor!
I have changed the above, where else do I need to change the data types?
Here are the current .ino files as they stand!
The odd thing is that the following code in the receiver sketch
Serial.println(myObject.temperature); Serial.println(myObject.pressure); Serial.println(myObject.altitude); Serial.println(myObject.humidity); Serial.println(sizeof(myObject));
is showing
0.00
0.00
0.00
0.00
16
conclusion, length of 16 bytes is correct, but the data is not being passed to the object