DS2408 from owfs to 8 dashboard output for status

Please help me, because I don't know how to create a solution in the most system-friendly way.
I am reading a DS2408 from an OWFS server. This returns between 0 and 255 as a decimal number.
I convert this as into a binary number.
The result is 10011010 as an example.
I would like to create something like this
the first binary number 1
Heating pump=true
the second binary number 0
Solar pump= false
the third binary number 0
the fourth binary number 1
Floor pump=true
the eighth binary number 0

the whole thing should be displayed in the dashboard and I would like to trigger further actions, for example when the fireplace is generating heat, so that my burner control of the heating system is then set to night reduction. I know how to do this, I just have to set the status of the fireplace as global flow.
I don't know how to break down the bimary number to generate 8 outputs for the dahbord. I am grateful for any suggestions

I don't understand what you mean by that. All numbers in javascript are stored the same, as floats. So what exactly have you converted it into? Feed it into a debug node and show us what it says.

You need to use binary AND to mask the bits, for example if you binary AND your result with 128 you will get the leftmost bit (heating pump), 64 = solar pump and so on.

I recommend to use the buffer node

1 Like

interesting, I haven't thought about that yet, so it's similar to the network mask.
I have tried with split and switch.

I get a decimal number from DS2408 of the status from the potential applied to the pins. If I convert this to binary, this is the status of the eight inputs, that show me the states of my pumps.

buffer node? I have not heard of. Is this a separate node? will ask google

Feed it into a debug node and show us please.

reading from device:
msg.payload : Object
Devices-Detail-Response: object
$: object
xmlns: "http://www.embeddeddatasystems.com/schema/owserver"
xmlns:xsi: "http://www.w3.org/2001/XMLSchema-instance"
PollCount: array[1]
0: "8185"
DevicesConnected: array[1]
0: "12"
LoopTime: array[1]
0: "0.360"
DataErrors: array[1]
0: "0"
owd_DS18S20: array[11]
[0 … 9]
0: object
1: object
2: object
3: object
4: object
5: object
6: object
7: object
8: object
9: object
[10 … 10]
owd_DS2408: array[1]
0: object
$: object
Name: array[1]
Family: array[1]
ROMId: array[1]
Health: array[1]
RawData: array[1]
PrimaryValue: array[1]
0: "207"
PIOLogicState: array[1]
PIOOutputLatchState: array[1]
PIOActivityLatchState: array[1]
RSTZconfiguration: array[1]
PowerOnResetLatch: array[1]

converting PrimaryValue 207 to:
msg.payload : string[8]

my 8 inputsof the DS2408 device

OK, so you haven't converted it to a value in a Buffer, as @ghayne assumed, but as characters "1" and "0" in a string. You might be better just to build the js object instead of building the string.

Can yo help me to change my function to generate an object?

let num = msg.payload.FA0000000C56E529.Value;
    let binary = (num % 2).toString();
    for (; num > 1; ) {
        num = parseInt(num / 2);
        binary =  (num % 2) + (binary);
    msg.payload= binary;

return msg;

So if I take your example:

The result 1001 1010 is decimal 157.

So with the buffe nodes you can convert the number in a buffer - and then it will be analysed.

So the first buffer node converts number in a buffer:



buffer is 0x9d


The buffer node can parse the byte bitwise and convert it to a boolean and directly assign a key to it.

The result is a payload with the specified keys:


You can also create directly the buffer within a function node:

The topic contains the decimal number of the inject Node and is marked in green. So you can directly see the outcome of decimal 157 (1001 1101) and 207 (1100 1111).

const buf= new Buffer(1);
buf.writeUInt8(msg.payload, 0);
msg.payload = buf;
return msg;
[{"id":"3a160476169a5f53","type":"inject","z":"61c5ee22.b88f1","name":"","props":[{"p":"payload"},{"p":"topic","v":"payload","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"157","payloadType":"num","x":530,"y":3400,"wires":[["8e56b87c0b808d68"]]},{"id":"8e56b87c0b808d68","type":"function","z":"61c5ee22.b88f1","name":"","func":"const buf= new Buffer(1);\nbuf.writeUInt8(msg.payload, 0);\nmsg.payload = buf;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":3420,"wires":[["2653be59f0069fc4"]]},{"id":"2653be59f0069fc4","type":"buffer-parser","z":"61c5ee22.b88f1","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"bool","name":"Heating Pump","offset":0,"length":1,"offsetbit":7,"scale":"1","mask":""},{"type":"bool","name":"Solar pump","offset":0,"length":1,"offsetbit":6,"scale":"1","mask":""},{"type":"bool","name":"Fireplace","offset":0,"length":1,"offsetbit":5,"scale":"1","mask":""},{"type":"bool","name":"Floor pump","offset":0,"length":1,"offsetbit":4,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":850,"y":3420,"wires":[["89478baccc51bfde"]]},{"id":"89478baccc51bfde","type":"debug","z":"61c5ee22.b88f1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1030,"y":3420,"wires":[]},{"id":"576557b0aaf107d3","type":"inject","z":"61c5ee22.b88f1","name":"","props":[{"p":"payload"},{"p":"topic","v":"payload","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"207","payloadType":"num","x":530,"y":3440,"wires":[["8e56b87c0b808d68"]]}]

first of all thank you for this mickm2
It works wonderfully and with the buffer function I will have to read the documentation a little more in detail, as I haven't really understood it yet, but I see some opportunities here where I have probably built completely overblown flows in the past.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.