Javascript node giving weird output now and then

Folks, I'm confused.

It is a complicated flow so I won't post it.

This is a python script I am running to scan for visible WAPs.

#wifiscan.py
import subprocess
import json
import re
 
child = subprocess.Popen('sudo iwlist wlan0 scan | grep -B 2 ESSID',shell=True,stdout=subprocess.PIPE)
output = child.communicate()[0]
output = output.decode("utf8")
output = output.replace('                   ESSID:','')
output = output.replace(' "','')
output = output.replace('"','')
output = output.splitlines()
 
output = json.dumps(output)
 
print (output)

and ideally I should get this back:

["                    Quality=70/70  Signal level=-37 dBm  ", "                    Encryption key:on", "Marys_Farm_2.4", "", "", "--", "                    Quality=70/70  Signal level=-32 dBm  ", "                    Encryption key:on", "Marys_Farm_2.4", "--", "                    Quality=35/70  Signal level=-75 dBm  ", "                    Encryption key:on", "Vodafone5G-A4998", "--", "                    Quality=41/70  Signal level=-69 dBm  ", "                    Encryption key:on", "Vodafone2.4G-A4998", "--", "                    Quality=34/70  Signal level=-76 dBm  ", "                    Encryption key:on", "MyRepublic 49D9", "--", "                    Quality=36/70  Signal level=-74 dBm  ", "                    Encryption key:on", "FSF_Common Area", "--", "                    Quality=60/70  Signal level=-50 dBm  ", "                    Encryption key:on", "Marys_Farm_5", "--", "                    Quality=56/70  Signal level=-54 dBm  ", "                    Encryption key:on", "...

It is run about every 40 seconds.

But now and then I get this on it's output:

[]

Not good.

Any ideas what is going on and causing the empty array to be sent?
And at worst, if it is going to send [] rather it sends a message like: something went wrong.

Surely you need to work out whether it is the subprocess or the python script or something else generating that error.

Also not really clear why you are using python to run an OS command when you can do that direct in node-red?

1 Like

I think ignorance/stupidity can be used for both. :wink:

Sorry, this is something I did a long time ago - and probably with help from here.
(no offense to those who did help)

It just spits out a list of visible WAPs and I then parse that to see if my WAPs are there.

How would I do it in NR?

Just run sudo iwlist wlan0 scan | grep -B 2 ESSID using an exec node, see what output you get and then parse it down using a function node or similar.

3 Likes

Love ya!

(No, not in that way.)

Thanks.

I guess what I had was right at the time.
I maybe had a lot to do with how complicated it is/was.
I was maybe playing with Python at the time.

That works great.
Well, I'd better not say that or Sod's law will happen.
But thanks, that does work.

1 Like

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