WAP list with graph - help please

Ok, so I seem to be getting a JSON formatted message with all the WAP names and their strength.

If I want to graph that.... Not sure if I want a line or bar - line seems better.
Do I just sent the messages into the chart node and it handles it?

Are you hoping to show signal strength against time for multiple access points?
Show us the data you have now.

This is the output from the python node.

{"ssid": "Marys_Farm_2.4", "signal_level": "-69"}
{"ssid": "MyRepublic 49D9", "signal_level": "-55"}
{"ssid": "Marys_Farm_5", "signal_level": "-52"}
{"ssid": "TelstraCA5E31", "signal_level": "-52"}
{"ssid": "\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00", "signal_level": "-68"}
{"ssid": "Optus_ABA172_5GHz", "signal_level": "-64"}
{"ssid": "Optus_ABA172", "signal_level": "-69"}
{"ssid": "PiNet", "signal_level": "-55"}
{"ssid": "WiFi-AFB6", "signal_level": "-47"}
{"ssid": "WiFi-F852", "signal_level": "-74"}
{"ssid": "WiFi-AFB6-5G", "signal_level": "-70"}
{"ssid": "Aussie Broadband 4928", "signal_level": "-68"}
{"ssid": "\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00", "signal_level": "-78"}
{"ssid": "WiFi-F852-5G", "signal_level": "-71"}

This is the flow:

[{"id":"057c784d0fb29dfc","type":"pythonshell in","z":"c56bddee.ca0a18","name":"wifiscan","pyfile":"/home/pi/python_stuff/wifiscan5.py","virtualenv":"","continuous":false,"stdInData":false,"x":145,"y":3490,"wires":[["cab9900ce3a0acc3","5e4102de54fda245","b944e2c6474312cd","94ef4b87e1c7c29e"]],"l":false},{"id":"94ef4b87e1c7c29e","type":"split","z":"c56bddee.ca0a18","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":310,"y":3420,"wires":[["177e50e0152c6adc"]]},{"id":"177e50e0152c6adc","type":"json","z":"c56bddee.ca0a18","name":"","property":"payload","action":"","pretty":false,"x":440,"y":3420,"wires":[["48ee756e1ec0c783","f09abc35ef453f9c"]]},{"id":"f09abc35ef453f9c","type":"change","z":"c56bddee.ca0a18","name":"","rules":[{"t":"move","p":"payload.signal_level","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"payload.ssid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":3420,"wires":[["a5f43014722527f0"]]}]

chart node not included.

Not sure if the split node is helping me or not.

Sorry.
The is the python code:

import json
import subprocess
import re

def scan_wifi():
    # Run the iwlist command to scan for wireless networks
    cmd = subprocess.Popen(['sudo', 'iwlist', 'wlan0', 'scan'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, _ = cmd.communicate()

    # Decode the output from bytes to string
    output = output.decode()

    # Extract the relevant information using regular expressions
    networks = re.findall(r'ESSID:"(.*?)".*?Frequency:(.*?)\s.*?Signal level=(.*?)\s', output, re.DOTALL)

    # Return the list of networks
    return networks

wifi_networks = scan_wifi()

for network in wifi_networks:
    ssid = network[0]
    frequency = network[1]
    signal_level = network[2]
#    print(f"Network: {ssid}, Frequency: {frequency}, Signal Level: {signal_level}")
#    this = print(f,"Network: {ssid}, Level: {signal_level}")

    output = json.dumps({"ssid": network[0], "signal_level": network[2]})
    print(output)

Just so we are all on the same page.

Yes, use ssid as topic and signal_level as payload to the chart node.
As multiple messages arrive it will draw a line for each ssid.

1 Like

I think I have those two the wrong way around.

Thanks.

How would I get the WAP names shown at the bottom?
(Tick the box - yes?) :wink:

(Forget the above)

New development:
Now when I run that code I get an error.
See below.

{"payload":"{\"ssid\": \"Marys_Farm_2.4\", \"signal_level\": \"-69\"}\n{\"ssid\": \"MyRepublic 49D9\", \"signal_level\": \"-53\"}\n{\"ssid\": \"Marys_Farm_5\", \"signal_level\": \"-51\"}\n{\"ssid\": \"TelstraCA5E31\", \"signal_level\": \"-51\"}\n{\"ssid\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\", \"signal_level\": \"-69\"}\n{\"ssid\": \"Optus_ABA172_5GHz\", \"signal_level\": \"-67\"}\n{\"ssid\": \"Optus_ABA172\", \"signal_level\": \"-73\"}\n{\"ssid\": \"PiNet\", \"signal_level\": \"-56\"}\n{\"ssid\": \"WiFi-AFB6\", \"signal_level\": \"-78\"}\n{\"ssid\": \"WiFi-F852-5G\", \"signal_level\": \"-63\"}\n{\"ssid\": \"WiFi-F852\", \"signal_level\": \"-71\"}\n{\"ssid\": \"Aussie Broadband 4928\", \"signal_level\": \"-69\"}\n{\"ssid\": \"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\", \"signal_level\": \"-73\"}\n{\"ssid\": \"OPTUS_69E639M\", \"signal_level\": \"-80\"}\n{\"ssid\": \"TelstraDDE916\", \"signal_level\": \"-74\"}\n{\"ssid\": \"WiFi-AFB6-5G\", \"signal_level\": \"-80\"}\n{\"ssid\": \"TelstraDAE48B\", \"signal_level\": \"-83\"}","_msgid":"3c06dffa910558dd","error":{"message":"Unexpected token { in JSON at position 50","source":{"id":"177e50e0152c6adc","type":"json","name":"WAP LIST JSON","count":1}}}

What's going on there?

UPDATE

IF I open the chart and tick the box shown, it gives the error.

If I have it as none it doesn't get/give an error.

And now having said that, it is now not stopping if/when I put it back to none.

Basically the error says:

Unexpected token { in JSON at position 50

Ok, (sorry folks)

I'm confused.

The python sends a block (JSON) message with ALL the names and their strengths as ONE message - yes?

So what's going on here?

You see the error message from the JSON node. (RED)
But there are a lot of messages (one per SSID?) (BLUE) being sent out of the JSON node.
Shouldn't it be ONE BIG MESSAGE?

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