ESPresense Device Tracking

Currently I am playing with ESPresense.
At the moment i can see the information from the ESP32 in Nodered.
Now i have to filter 2 different ID´s to read out the distance of the device.

With this function it wont work:
image

Thats the payload:
image

At the end i want to evaluate if a device is over e.g. 10m away from the ESP to send true / false. And also to get a false payload if one or both devices are unreachable or out of distance. -> maybe like... if there get no msg within 5min the device is out of range.

msg.payload is an object not an array (Take alook at mdn site search js filter, see it will tell you it is a method of an array).
What exactly are you trying to do. You Know which device is responding as it's in the id. so you could join the incoming messages as key value object, count 2, using the id as key, set the join to output every subsequent msg. Then in the following change or function node, check for distance under 10 for both payload properties, if so send true else send false.

The Join node was the solution :slight_smile:
I was kind of stuck

Thanks!

unfortunately my solution doesn't work as expected.
I sometimes get messages from the same devices. So I have to filter the devices first. A join node is therefore not the solution.
I first have to filter for the IDs and then evaluate the distance accordingly. However, I still don't see a clear solution at the moment.

No need to filter if you join as key value object.
Here is an example.

[{"id":"82a438cf.a9903","type":"inject","z":"30af2d3e.d94ea2","name":"one 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"one\",\"distance\":1}","payloadType":"json","x":510,"y":3080,"wires":[["a39d5a69.9f9278"]]},{"id":"a39d5a69.9f9278","type":"join","z":"30af2d3e.d94ea2","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"payload.id","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":3140,"wires":[["de0114ea.e25ec8","3c1a10ab.7aa64"]]},{"id":"698bc9c0.2b41a","type":"inject","z":"30af2d3e.d94ea2","name":"one 11","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"one\",\"distance\":11}","payloadType":"json","x":520,"y":3120,"wires":[["a39d5a69.9f9278"]]},{"id":"872cca95.1a13d8","type":"inject","z":"30af2d3e.d94ea2","name":"two 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"two\",\"distance\":1}","payloadType":"json","x":490,"y":3200,"wires":[["a39d5a69.9f9278"]]},{"id":"c50d97fa.95c89","type":"inject","z":"30af2d3e.d94ea2","name":"two 11","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":\"two\",\"distance\":11}","payloadType":"json","x":500,"y":3240,"wires":[["a39d5a69.9f9278"]]},{"id":"de0114ea.e25ec8","type":"function","z":"30af2d3e.d94ea2","name":"","func":"let bool_output = false;\nObject.values(msg.payload).forEach(obj => {\n    if(obj.distance <= 10) bool_output = true;\n})\nmsg.payload = bool_output\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":3140,"wires":[["e8ca4b84.7d78c8","dec0e2d1.68407"]]},{"id":"3c1a10ab.7aa64","type":"debug","z":"30af2d3e.d94ea2","name":"object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":3060,"wires":[]},{"id":"e8ca4b84.7d78c8","type":"rbe","z":"30af2d3e.d94ea2","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","x":970,"y":3140,"wires":[["845dd144.4a7ea"]]},{"id":"dec0e2d1.68407","type":"debug","z":"30af2d3e.d94ea2","name":"boollean","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":3100,"wires":[]},{"id":"845dd144.4a7ea","type":"debug","z":"30af2d3e.d94ea2","name":"filtered","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":980,"y":3200,"wires":[]}]
1 Like

I set up the join node exactly as you said. However, I had an error in the subsequent function node and kept getting the following message, and i blamed the join node for that. sorry

image

Now it works as it should :slight_smile: Big thanks!

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