# Help with the \`node-red-contrib-os\` \`drives\` node

**URL:** <https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085>\
**Category:** General\
**Created:** [22 November 2021 04:28 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085 "2021-11-22T04:28:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 November 2021 04:28 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/1 "2021-11-22T04:28:48Z")

</div>

I have a USB stick in a RasPi.

I want to keep a eye on how full it is. I do that with the `drive` node.  
But.... (And isn't there always a _but_?)  
The output is an array.

I noticed that I wasn't getting a result for the USB stick memory usage recently.  
The _position_ in the array for the USB stick has changed from `9` to `8`.

Basic code:

```auto
[{"id":"7ff716d6.e21418","type":"inject","z":"aa48e352.9ad2f8","name":"Start / test","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":680,"y":2690,"wires":[["6577d12.52626b"]]},{"id":"6577d12.52626b","type":"Drives","z":"aa48e352.9ad2f8","name":"","x":630,"y":2770,"wires":[["782006fd.3e7dd","993a88f2.a45528"]]},{"id":"782006fd.3e7dd","type":"function","z":"aa48e352.9ad2f8","name":"","func":"var used = msg.payload[8].capacity;\nmsg.payload = used * 100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":2770,"wires":[["ef0a36fd.aa9b7","5b576c7e.3b7f74","757c403.9cec9c","454f45f.552593c"]]},{"id":"5b576c7e.3b7f74","type":"debug","z":"aa48e352.9ad2f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1040,"y":2690,"wires":[]}]

```

Without making it too complicated how can I get it to _track_ the USB and not having to change the code in the `function` node?

Because what I have to do is look at the `message` out of the node and open each one to see which is the USB drive and change the `function` node to that number.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 November 2021 09:33 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/2 "2021-11-22T09:33:02Z")

</div>

Use `msg.payload.forEach()` to step through the array till you find the one with the right mount point.

Or more concisely use `Array.reduce()`, whichever you are happiest using.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 November 2021 22:51 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/3 "2021-11-22T22:51:53Z")

</div>

Seems I have two commands I need to _study_ to see how they work.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 November 2021 23:40 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/4 "2021-11-22T23:40:33Z")

</div>

This would/should work too - yeah?

I tried it and it seems to do the trick.

```auto
[{"id":"7ff716d6.e21418","type":"inject","z":"aa48e352.9ad2f8","name":"Start / test","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":680,"y":2690,"wires":[["6577d12.52626b"]]},{"id":"6577d12.52626b","type":"Drives","z":"aa48e352.9ad2f8","name":"","x":630,"y":2770,"wires":[["782006fd.3e7dd","993a88f2.a45528","5a7ab15f.f4439"]]},{"id":"5a7ab15f.f4439","type":"split","z":"aa48e352.9ad2f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":850,"y":2610,"wires":[["ee281b31.d242e8","1b529ead.2ceed1"]]},{"id":"1b529ead.2ceed1","type":"switch","z":"aa48e352.9ad2f8","name":"","property":"payload.filesystem","propertyType":"msg","rules":[{"t":"eq","v":"/dev/sda1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":990,"y":2610,"wires":[["10aa292a.d13ef7"]]},{"id":"10aa292a.d13ef7","type":"debug","z":"aa48e352.9ad2f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":2610,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 November 2021 16:29 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/5 "2021-11-23T16:29:44Z")

</div>

Yes, that is a good node-red way of doing it. Much better than my ideas 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 December 2021 16:30 UTC](https://discourse.nodered.org/t/help-with-the-node-red-contrib-os-drives-node/54085/6 "2021-12-07T16:30:27Z")

</div>

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