modified RoomNode Sketch + FHEM

Added by bjoern777 almost 5 years ago

Hello there,

after playing around my RoomNode and FHEM i had in mind to write my own FHEM modul for jeelink.
The node should placed in the heating room and collect there some temperatures.

I have modified the RoomNode sketch like this:

struct {
byte id :8; // identity, should be different for each node
int temp1 :10; // temperature: –500..+500 (tenths)
int temp2 :10; // temperature: –500..+500 (tenths)
int temp3 :10; // temperature: –500..+500 (tenths)
int temp4 :10; // temperature: –500..+500 (tenths)
int temp5 :10; // temperature: –500..+500 (tenths)
byte lobat; // supply voltage dropped under 3.1V: 0..1
} payload;

But i don’t know if it’s right, because i don’t understand the suffix “:10”

For testing i set the readings in doMeasure manually:

payload.temp1 = 110;
payload.temp2 = 220;
payload.temp3 = 330;
payload.temp4 = 440;
payload.temp5 = 550;

After setting verbose level in FHEM to 5 i can see :

OK 13 2 110 112 163 20 110 38 2 0

Can someone tell me why there is no output like this?

OK 13 2 110 220 330 440 550 0

Thank you in advance!

Replies (2)

RE: modified RoomNode Sketch + FHEM - Added by JohnO almost 5 years ago

I think the :10 means allocate 10 bits in the structure.

Seems to add up to 58 bits, not a multiple of 8 so will display a little odd.

RE: modified RoomNode Sketch + FHEM - Added by lightbulb almost 5 years ago


I’ll be quick because I am on my phone screen.

:n is a bit packing notation to allow the compiler to help pack data for you.

Assuming a ‘byte’ is 8bits, you can use this notation to help you get access to the 8bits directly using a struct.

struct {
byte id1 :1; // bit1
byte id2 :1; // bit2

byte id8 :1; // bit8
} payload;

in this case payload is a single byte, and its 8 bits can be accessed like so: payload.id2;
It is used to pack ’appropriate’ data into a smaller ’space’.

You may find it helpful to use ‘sizeof’, which will tell you the size of the data type you are using.
Compare sizeof(int) with the size of your struct - this may help you understand what that code is doing.
Hint: until you are familiar, just use ‘int’ (remove the :n) until you understand, and at the jeelink each OK result will contain an ‘int’ with the relevant value. Then work back to the packed format until you understand.