after some more reading, I found out that is a problem related to data alignment. Arduino pro mini is 8 bit and ESP8266 is 32 bit. So I declared the struct like this:
typedef struct {
uint16_t nodeId; //store this nodeId
uint16_t light;
uint16_t batt;
double temp; //temperature maybe?
double humid;
} Payload;
but, i still have problems with temperature and humidity, for these I haven't found a solution so far. I want to do this in order to avoid reflashing my sensors.
Help would be high apreciated.
I know this is an old topic, but I came across the same problem (Node is 8-bit AVR, but Gateway is 32-bit ESP-12E).
So if someone else is still having issues with data received, this worked for me:
typedef struct __attribute__((__packed__)) {
uint16_t node_id;
float temp;
float hum;
uint16_t batt;
} Payload;
TomWS, thanks for pointing this out.
That means on AVR node instead of this:
typedef struct {
int node_id;
float temp;
float hum;
int batt;
} Payload;
I should use this:
typedef struct {
uint16_t node_id;
float temp;
float hum;
uint16_t batt;
} Payload;
Or what would be the correct method?
TomWS, thanks for pointing this out.
That means on AVR node instead of this:
typedef struct {
int node_id;
float temp;
float hum;
int batt;
} Payload;
I should use this:
typedef struct {
uint16_t node_id;
float temp;
float hum;
uint16_t batt;
} Payload;
Well, we're mixing signed-ness with size and they are entirely different. IF you really want a signed integer to pass back and forth in a packet, you could use:
typedef struct {
int16_t node_id;
float temp;
float hum;
int16_t batt;
} Payload;
or, if you really do want unsigned values, this is fine:
typedef struct {
uint16_t node_id;
float temp;
float hum;
uint16_t batt;
} Payload;
Note that, in these cases, 'float' is accepted to be a single precision IEEE floating point value (whose size is standard, unlike ints).
Finally, so that you can use a single include file to be defining the packet structures with the same file on both ends, including the packed attribute, as you had earlier, is also fine (the attribute is redundant on the AVR processor).
typedef struct __attribute__((__packed__)) {
uint16_t node_id;
float temp;
float hum;
uint16_t batt;
} Payload;
Tom