# Display Wifi infomation on a PLC touch screen

**URL:** <https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665>\
**Category:** General\
**Created:** [18 September 2019 14:46 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665 "2019-09-18T14:46:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeroen](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Jeroen](https://discourse.nodered.org/u/Jeroen)\
**Post date:** [18 September 2019 14:46 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/1 "2019-09-18T14:46:30Z")

</div>

I have a plc wired to my raspberry pi and it is comunicating over TCP IP. Now I want to show on the display of the plc that the pi is connected to WiFi and the strength of the signal. I used Wifi scanner but now I don't see which network is connected. Is there another possibility to do this in node-red?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 September 2019 17:44 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/2 "2019-09-18T17:44:28Z")

</div>

To check the signal strength you can use:  
`iwlist scan wlan0`

However, I think this can only be done with sudo, you cannot execute privileged commands with node-red unless you run it as root (not recommended).

There is another command that doesn't require root.

```auto
nmcli dev wifi

```

(perhaps you need to install it first, I'm not using a Pi at the moment:`sudo apt-get install network-manager`)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 September 2019 19:24 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/3 "2019-09-18T19:24:00Z")

</div>

> [@bakman2](#):
>
> you cannot execute privileged commands with node-red unless you run it as root (not recommended)

Yes you can 😉

All you need to do is to run the command `visudo` and add the `iwlist` command as allowed from sudo without requiring a password. Then you can happily call `sudo iwlist scan wlan0` from an exec node.

You could also allow all commands to use sudo without a password prompt though that is obviously less secure.

Either way, the user id being used still has to be in the correct group which gives admin access.

---

<div class="post-metadata">

**Author:** ![clickworkorange](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clickworkorange/32/12109_2.png) [@clickworkorange](https://discourse.nodered.org/u/clickworkorange)\
**Post date:** [19 September 2019 07:17 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/4 "2019-09-19T07:17:40Z")

</div>

> [@TotallyInformation](#):
>
> All you need to do is to run the command `visudo` and add the `iwlist` command as allowed from sudo without requiring a password. Then you can happily call `sudo iwlist scan wlan0` from an exec node.
> 
> You could also allow all commands to use sudo without a password prompt though that is obviously less secure.

The first option is [a reasonable suggestion](https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password/159009#159009) when you _must_ run a command which would otherwise require the `sudo` password. In the OP's case running `nmcli dev wifi | grep \*` (as suggested by @bakman2) and parsing the output is better.

The second option is a terrible idea IMO. Never do this. Yes, this is how Raspbian is shipped, but that doesn't make it any better. Don't assume that just because its small and has a cute name that a Pi can't totally p\*wn your network and (potentially) all the machines on it. It's just as capable of acting as a backdoor as any system. Stay safe!

---

<div class="post-metadata">

**Author:** ![Ekristoffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ekristoffe/32/11863_2.png) [@Ekristoffe](https://discourse.nodered.org/u/Ekristoffe)\
**Post date:** [19 September 2019 09:43 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/5 "2019-09-19T09:43:50Z")

</div>

> [@clickworkorange](#):
>
> The second option is a terrible idea IMO. Never do this. Yes, this is how Raspbian is shipped, but that doesn't make it any better. Don't assume that just because its small and has a cute name that a Pi can't totally p\*wn your network and (potentially) all the machines on it. It's just as capable of acting as a backdoor as any system. Stay safe!

I think NASA has learned this the hard way ...

---

<div class="post-metadata">

**Author:** ![Jeroen](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Jeroen](https://discourse.nodered.org/u/Jeroen)\
**Post date:** [19 September 2019 09:47 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/6 "2019-09-19T09:47:30Z")

</div>

hello everyone thank you very much for your responses.

I did the following because I could not fully follow your answers.

1. Enterd "sudo visudo" in the commendline behind pi@raspberrypi:~$
2. All the way at the bottom I enterd "myuser ALL=(root) NOPASSWD: /sbin/iwlist wlan0 scan"
3. Ctrl x
4. J
5. Enter
6. Reboot
7. Open the command line and enterd "sudo iwlist wlan0 scan"

Now a lot of information about wlan0 appeared on the screen.

1. Open the command line and enterd "iwlist wlan0 scan"

Now only the information of the connected wifi conection is show.

1. In node-red I used an inject node an exec node and three debug nodes.
2. In the exec node I enterd "sudo iwlist wlan0 scan"

This unfortunately does not work out as I had hoped. As you can see I am not very familiar with this material. can you give me some tips please?

Where do I have to enter `nmcli dev wifi | grep \*` ?

---

<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:** [19 September 2019 09:53 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/7 "2019-09-19T09:53:44Z")

</div>

in the exec node - DON'T - put sudo... try the iwlist version without sudo.  
(the whole point is that the exec node won't exec things as sudo ... 🙂

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [19 September 2019 10:21 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/8 "2019-09-19T10:21:49Z")

</div>

```auto
iwlist wlan0 scanning | egrep 'Cell |Encryption|Quality|Last beacon|ESSID'

```

Gives you good info about the ap you are connected to

```auto
sudo iwlist wlan0 scanning | egrep 'Cell |Encryption|Quality|Last beacon|ESSID'

```

Gives the same plus all other ap that are within the reach

---

<div class="post-metadata">

**Author:** ![Jeroen](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Jeroen](https://discourse.nodered.org/u/Jeroen)\
**Post date:** [19 September 2019 11:40 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/9 "2019-09-19T11:40:18Z")

</div>

It worked now I just have to filter out the ESSID and the signal level. With this information I can show a wifi sign on the plc just like on your phone. in this way I can build a nice debug mode.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 September 2019 16:15 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/10 "2019-09-19T16:15:35Z")

</div>

> [@dceejay](#):
>
> the exec node won't exec things as sudo

Urm, it does Dave 🙂 - reboots, restarts of NR, all sorts. It just needs a little encouragement.

To those who've pointed out about allowing sudo without p/w for all commands. Yes, it is certainly poor security as is leaving the default Pi user in place, especially with the default password. But still handy for testing. Put the devices on their own network (preferably a different VLAN) for a little more security.

Even worse if you forget and then allow inbound connections from the Internet as some people discovered not so long ago.

---

<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:** [19 September 2019 17:27 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/11 "2019-09-19T17:27:57Z")

</div>

But in this case it is not necessary as `iwlist` without sudo will do what the OP wants.

---

<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:** [19 September 2019 18:57 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/12 "2019-09-19T18:57:03Z")

</div>

> [@TotallyInformation](#):
>
> It just needs a little encouragement.

Yes - out of the box it won't.... so beginners try it and it doesn't...

---

<div class="post-metadata">

**Author:** ![clickworkorange](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clickworkorange/32/12109_2.png) [@clickworkorange](https://discourse.nodered.org/u/clickworkorange)\
**Post date:** [19 September 2019 19:19 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/13 "2019-09-19T19:19:44Z")

</div>

I use the exec node to set the system date & time from a GPS via `sudo date -s`. This works because I have `nodered ALL=(ALL) NOPASSWD: /bin/date` in my `/etc/sudoers` file ("nodered" being the user account which Node-RED runs under).

---

<div class="post-metadata">

**Author:** ![JeroenKeetels](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@JeroenKeetels](https://discourse.nodered.org/u/JeroenKeetels)\
**Post date:** [30 January 2023 13:17 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/14 "2023-01-30T13:17:53Z")

</div>

Same question, different circumstances.

In 2019 I asked the following question here.  
"I have a plc wired to my raspberry pi and it is comunicating over TCP IP. Now I want to show on the display of the plc that the pi is connected to WiFi and the strength of the signal. I used Wifi scanner but now I don't see which network is connected. Is there another possibility to do this in node-red?"

After some tips and help I was able to solve the problem as follows.

1. Enterd "sudo visudo" in the commendline behind pi@bpi-iot-ros-ai:~$
2. All the way at the bottom I enterd "myuser ALL=(root) NOPASSWD: /sbin/iwlist wlan0 scan"
3. Ctrl x
4. J
5. Enter
6. Reboot
7. Open the command line and enterd "iwlist wlan0 scan"
8. In node-red I used an inject node an exec node and three debug nodes.
9. In the exec node I enterd "iwlist wlan0 scan"

Currently, the Raspberry-Pi's are not or difficult available. I am now making a clone on a Banana-Pi.

# Banana Pi BPI-M2 Berry

[Banana Pi BPI-M2 Berry - Banana Pi Wiki (banana-pi.org)](https://wiki.banana-pi.org/Banana_Pi_BPI-M2_Berry#Raspbian)

I've tried to do the same trick but somehow it doesn't work.

The Banana-pi doesn't care what I write in the visudo. Could it be that I'm pointing to the wrong directory?

**sudo iwlist wlan0 scan** in the command line works fine.

I am using the following versions:  
nodejs - v14.21.2  
npm 6.14.17  
node red v0.20.7  
Raspbian GNU/Linux 9.4 (stretch)

Hopefully someone can give a tip what I can check or adjust.

---

<div class="post-metadata">

**Author:** ![JeroenKeetels](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@JeroenKeetels](https://discourse.nodered.org/u/JeroenKeetels)\
**Post date:** [1 February 2023 13:20 UTC](https://discourse.nodered.org/t/display-wifi-infomation-on-a-plc-touch-screen/15665/15 "2023-02-01T13:20:28Z")

</div>

Solved

pi@bpi-iot-ros-ai:~ $ cd /sbin  
pi@bpi-iot-ros-ai:/sbin $ ls -l iwlist ---- iwlist is green  
pi@bpi-iot-ros-ai:/sbin $ sudo chmod a+s /sbin/iwlist  
pi@bpi-iot-ros-ai:/sbin $ ls -l iwlist ---- iwlist is red now

This will change the permissions of iwlist and and solved my problem. Maybe it's of use to anyone, take advantage of it.
