Display Wifi infomation on a PLC touch screen

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?

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.

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)

1 Like

Yes you can :wink:

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.

The first option is a reasonable suggestion 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!

1 Like

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

1 Like

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 \* ?

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 ... :slight_smile:

1 Like
iwlist wlan0 scanning | egrep 'Cell |Encryption|Quality|Last beacon|ESSID'

Gives you good info about the ap you are connected to

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

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

1 Like

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.

4 Likes

Urm, it does Dave :slight_smile: - 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.

1 Like

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

3 Likes

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

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).

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)

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.

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.

1 Like