# Rpi-backlight not working in a function

**URL:** <https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108>\
**Category:** General\
**Created:** [10 July 2019 13:20 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108 "2019-07-10T13:20:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [10 July 2019 13:20 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/1 "2019-07-10T13:20:45Z")

</div>

Has anyone gotten this package to work? All I keep getting is blank returns no matter what method I use. It also won't write to the brightness file.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cf3e96a8ca117e2732b6418cb660da85bce67b56.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 July 2019 13:28 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/2 "2019-07-10T13:28:21Z")

</div>

2 things...

1. does the account running node-red have access to the file trying to be modified?  
`/sys/class/backlight/rpi_backlight/actual_brightness` ([code](https://github.com/pimterry/rpi-backlight/blob/master/index.js#L4))

2. You might need to use async or wait for promise to be resolved (see the [function code](https://github.com/pimterry/rpi-backlight/blob/master/index.js#L49) uses `then()`)

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [10 July 2019 13:53 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/3 "2019-07-10T13:53:22Z")

</div>

I don't think it does since echoing a number to the brightness file from the shell requires the use of

```auto
sudo bash -c "echo ### > /sys/class/backlight/rpi_backlight/actual_brightness"

```

for getting the brightness I can always use the read file node so not too worried about that, it's mostly setting the brightness that's the bigger issue.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 July 2019 13:58 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/4 "2019-07-10T13:58:45Z")

</div>

> [@injector22](#):
>
> I don't think it does since echoing a number to the brightness file from the shell requires the use of
> 
> ```auto
> sudo bash
> 
> ```

Normally, node-red doesnt run under sudo (or root) so the very fact you have to use `sudo` (super user do) at the shell to update the file suggests this is the problem.

Some choices are - relax permissions on the file or Run node-red as sudo (NOT recommended)

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [10 July 2019 14:16 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/5 "2019-07-10T14:16:07Z")

</div>

Yep, that was it. Thanks @Steve-Mcl

In case anyone else runs into this here's the command I ran in the shell to add the permissions

```auto
sudo chmod a+rw /sys/class/backlight/rpi_backlight/brightness

```

Note this gives every user of the pi permissions to read and write

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 July 2019 15:33 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/6 "2019-07-10T15:33:26Z")

</div>

Does that survive a reboot ?

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [10 July 2019 17:03 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/7 "2019-07-10T17:03:39Z")

</div>

It sure doesn't. I guess I need to figure out how to make it survive a reboot

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [10 July 2019 17:15 UTC](https://discourse.nodered.org/t/rpi-backlight-not-working-in-a-function/13108/8 "2019-07-10T17:15:08Z")

</div>

I added the command to /etc/rc.local and it's all good now
