HTML request / handle of data

#1

my garden-irrigation is now working, very fine thing - but I have a "big" problem, where I can't fine the way in Node-Red Flow for receiving data from the Water-pump. there are water-pressure and two level-switches and the ESP8266 send me the the data
Water = 1019
Level 1 = 0
Level 2 = 1
now I have to handle first of all:
Level 1 = 0 means pump and water is ok / Level 1 = 1 means no water or pump is off (topic Pump to ON or STOPP)
Level 2 = ... the same as above for the water supply (topic supply-pump ON or OFF)

how I can divide this html-phrase to use this two argument as "true/false" or 1/0 in the flow of node-red

0 Likes

#2

If you are just trying to change a 0 or 1 to boolean true/false, just use a change node.

change

Paul

0 Likes

#3

thank you but this I have already done
my problem is to separate the payload:

Water = 1019
Level 1 = 0
Level 2 = 1

in:
Water = 1019
Level 1 = 0
Level 2 = 1
so in a function I can find out by if "Level 1 = 1" then / else; or if "Level = 1" then / else
I do not want to succeed

Max

0 Likes

#4

Are you saying the payload is the string below (for example):

Water = 1019
Level 1 = 0
Level 2 = 1

And you want to pull out the separate parts? One way to do this would be to use a change node to replace all the "=" characters with ":", and then pass the payload into a yaml node.

image

[{"id":"7f22ef57.d3278","type":"yaml","z":"f6747993.c9b448","property":"payload","name":"","x":570,"y":100,"wires":[["c46ecbf4.b416a8"]]},{"id":"c06a49fd.f9a6b8","type":"change","z":"f6747993.c9b448","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"=","fromt":"str","to":":","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":100,"wires":[["7f22ef57.d3278"]]}]

Then your payload will be an object with properties "Water", "Level 1" and "Level 2". Is that what you're after?

Although if the only thing you wanted to do was an if-test based on "Level 1 = 0", it would probably be easiest to just look for this whole string. For example:

if (msg.payload.indexOf("Level 1 = 0") >= 0) {
    msg.level1 = "It's zero";
} else {
    msg.level1 = "It's not";
}
return msg;
0 Likes

#5

Max, it's maybe too late now, but using MQTT to pass messages from the ESP to node-RED is much simpler, because you could create different topics to handle different identifiers, such as;

Topic Value
irrigation/water 1019
irrigation/level/1 1
irrigation/level/2 0

And you would read those values in node-RED by simply subscribing to the particular topic;

mqtt

It's also much more reliable as you can use QoS to ensure that the messages are received.

Paul

1 Like

#6

many thanks Michael

the second way help!
I didn't think on this: msg.payload.index0f
now for booth Level 1 and Level 2 I can test 0 or 1

thank you again

0 Likes

#7

thank you Paul

now I could find the solution

for MQTT - later when the project is finished, then I will try as the net step

thank you again for helping

Max

0 Likes