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.