I'm wondering about this struct:
typedef struct {
uint32_t uptime;
uint16_t reading;
uint8_t nodeid;
} Payload;
Payload thePayload;
Why on Arduino sizeof(Payload) returns 7, and on ESP8266 it returns 8? Is it possible to have it equal so it matches when transferring data?
It is just a packing issue. There's a pragma you can use to force byte alignment. Easiest solution though is probably to add a dummy byte on the Arduino to push the structure out to a nice round eight bytes.
The size of a struct is inherently dependent upon the device architecture, and in c/c++ is explicitly NOT constant across platforms. Trying to force it to be so will lead to madness if you are not on a consistent platform. The best approach is to design your system to EXPECT variability, and deal with it. Likely the most common problem will be small data types, especially 8-bit types, occupying a larger amount of memory (16 or 32 bits).
Regards,
Ray L.
Understood, so always multiples of 4. I guess I will just convert nodeid to uint16_t and live with it 
Thank you wildbill and Ray L!
Marton79:
Understood, so always multiples of 4. I guess I will just convert nodeid to uint16_t and live with it 
Not always multiples of four though, it could be pretty much any size. For example, on my 64-bit computer, the size and alignment of doubles, longs, and pointers is 8 bytes, and even 16 bytes for long doubles.
This means that the size of the following struct will be 32 bytes, even though the sizes of the two components add up to only 17 bytes:
[color=#00979c]struct[/color] [color=#000000]S[/color] [color=#000000]{[/color]
[color=#00979c]uint8_t[/color] [color=#000000]u[/color][color=#000000];[/color]
[color=#00979c]long[/color] [color=#00979c]double[/color] [color=#000000]d[/color][color=#000000];[/color]
[color=#000000]}[/color][color=#000000];[/color]
alignof(uint8_t) = 1
sizeof(uint8_t) = 1
alignof(long double) = 16
sizeof(long double) = 16
alignof(S) = 16
sizeof(S) = 32
// g++ alignment.cpp -o alignment && ./alignment
#include <iostream>
#define PrintExpr(Expr) std::cout << #Expr " \t= \t" << (Expr) << '\n'
#define PrintSizeAlignment(T) \
PrintExpr(alignof(T)); \
PrintExpr(sizeof(T))
int main() {
struct S {
uint8_t u;
long double d;
};
PrintSizeAlignment(uint8_t);
PrintSizeAlignment(long double);
PrintSizeAlignment(S);
}
You always have to be careful when sending the raw byte representation of a struct to a different system (Arduino → Arduino, Arduino → ESP8266, Arduino → PC), because the alignment requirements will be different, and so will the sizes.
For example, on 8-bit AVR Arduinos, the size of double is 4 bytes, but on 32-bit ARM Arduinos, the size of double is 8 bytes, and the size of int is 2 bytes versus 4 bytes respectively.
Thank you, PieterP. PC is out of the question in my case, so I guess 4 bytes rounding will be OK for me. But will definitely take your suggestions into account of course!