nRF24 / RF24Mesh

OSI Layer 7 Mesh Networking for RF24Network & nrf24L01+ & nrf52x devices
http://nrf24.github.io/RF24Mesh
GNU General Public License v2.0
422 stars 154 forks source link

heads up on data being sent to/from RPi from/to Arduino #175

Closed OldSurferDude closed 4 years ago

OldSurferDude commented 4 years ago

The data I was sending from the RPi to an Arduino was:

#define dataType_toNode 'A'
struct dataPacketA_toNode {
  bool relayState;
  bool reboot;
  bool isSumpPump;
  unsigned long pumpTimeout;
} 

-----------------------------------------------------------and coming back was

#define dataType_fromNode 'A'
struct dataPacketA_fromNode {
  bool emptyState;
  bool fullState;
  float temperature;
  float humidity;
  bool relayState;
  uint8_t BootType;
} nodeState[16]; // = {no, no, -20.0, 0.0, relayOff, 0};  // only use logic of relay when turning on or off

but the data was buggered.

I displayed the sizeof() each structure on the RPi and the Arduino. The latter was as expected on the Arduino, 7 and 12, but on the RPi it was 12 and 16!

Some quick research showed that on the RPi the variables need to be aligned to on a 4 Byte boundary.

Putting the most Bytes variables first and padding the structure to be a multiple of 4 Bytes fixed the problem!

Avamander commented 4 years ago

Yes, this is how C structs work.