So basically I'm sending this struct data from my Arduino to my RPi, both fitted with an NRF24L01 module. Library on the Arduino is tmrh20, and on the RPi, BLavery.
struct values{
char nameSensor[4]; // user inputs name of sensorNode e.g. "Home"
float tempToSend;
float humiToSend;
float lightToSend;
float soilMoist;
float soilTemp;
float gasSensor;
int motionSensor; //struct size should be max 32 bytes for the RF24 pipe
};
struct values dataToSend;
//dataToSend.nameSensor=saved_nameSensor; //from EEPROM
//...
radio.write(&dataToSend,sizeof(dataToSend));
A few months ago, all I had to do was transmit temp and humidity float array from the Arduino, and I found the following code to work:
DataBytes=8
receivedMessage = bytearray(DataBytes)
radio.read(receivedMessage,radio.getDynamicPayloadSize())
data = struct.unpack('ff',receivedMessage)
humidity=data[0]
temp=data[1]
I'll just get right to it. I don't know how to convert/decode this struct into their respective data types in RPi. I don't even know where to begin, I could not find any Python code that receives a struct.
The only example I found was this post on Reddit: https://www.reddit.com/r/arduino/comments/juivxw/sending_struct_with_nrf24l01/
But in this post, both the receiver and transmitter are in Arduino architecture.
Does anyone know of a way to decode struct data similar to the float array struct.unpack above?
receivedMessage
value. I think the struct needs to be changed todata = struct.unpack('<4c6fl',receivedMessage)
for the new struct.