# WAP list with graph - help please

**URL:** <https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361>\
**Category:** General\
**Created:** [23 June 2023 07:06 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361 "2023-06-23T07:06:02Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2023 10:51 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/21 "2023-06-23T10:51:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 June 2023 11:06 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/22 "2023-06-23T11:06:08Z")

</div>

> [@Trying\_to\_learn](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2023 11:11 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/23 "2023-06-23T11:11:34Z")

</div>

This is the output from the python node.

```auto
{"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:

```auto
[{"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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 June 2023 11:20 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/24 "2023-06-23T11:20:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2023 11:21 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/25 "2023-06-23T11:21:33Z")

</div>

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?) 😉

(Forget the above)

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

```auto
{"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.

 ![Screenshot from 2023-06-23 21-36-15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d82c3889fb035bff08ddfc09df0cb48b2c1e8a3b.png)

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

Basically the error says:

```auto
Unexpected token { in JSON at position 50

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2023 11:55 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/26 "2023-06-23T11:55:50Z")

</div>

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?

 ![Screenshot from 2023-06-23 21-52-00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e36eb0871c81ccd0e7e44cf61888d493bb0a36b.png)

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 July 2023 11:56 UTC](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361/27 "2023-07-07T11:56:35Z")

</div>

Closed on 7 July 2023 11:56 UTC

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

[Previous page](https://discourse.nodered.org/t/wap-list-with-graph-help-please/79361.md?page=1)
