Hi All,
I have been using a struct in my Jeenode sketch and I am wondering if anyone can help to get a similar mechanism working for the Moteino RFM69 library. It helped me lot with preserving the data types of transmitted values. I first saw it on "Steve's blog" at
http://www.trease.eu/?p=1038. It has worked well on the JN and helped a noob such as myself with deconstructing radio data and using it as variables in sketches.
The code in the sending sketch goes like this:
typedef struct {
int nodeid; // sending node ID
float data_1;
float data_2;
float data_3;
float data_4;
} Payload;
Payload data;
int a = data.data_1;
int b - data.data_2;
int c = data.data_3;
//then in loop(), ...
rf12_sendStart(0, &data, sizeof data);
-----------------------------------------------------------------------------
Then the code in the receiving sketch went like this:
// Payload data structure
typedef struct { // Message data structure, same on sending and receiving motes
int nodeid; // sending node ID
float data_1; // data types
float data_2;
int data_3;
} Payload;
Payload data; //instance of Payload
void loop() {
if (rf12_recvDone()) {
if (rf12_crc == 0) {
data=*(Payload*) rf12_data; //apparently fills the data struct with data from rf12_data buffer, can do same for RFM69?
Serial.print(data.nodeid);
Serial.print(",");
Serial.print(data.data_1);
Serial.print(",");
Serial.print(data.data_2);
Serial.print(",");
Serial.print(data.data_3);
I don't really understand magic in the line "data=*(Payload*) rf12_data;" other than it somehow fills the data struct with data from the rf12 data buffer. Can this line be modified to work with the RFM69 library? I simply replaced "rf12_data" with "radio.DATA", but no luck. If anyone can point me in the right direction, I'd appreciate it.