As (I think) everyone has agreed, it is best to fix any message format problems at source, so I have taken another look at the Python script you posted in the other thread.
Here is the script as I modified it, with comments to explain the change.
Essentially I'm making a Python dictionary for each access point then adding it to an array.
#! /usr/bin/python
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()
myarray = [] # The output should be an array of js objects, so make an empty array
for network in wifi_networks:
ssid = network[0]
frequency = network[1]
signal_level = float(network[2]) # Take the opportunity to have signal level as a number not string
dict = {"ssid": ssid, "signal_level": signal_level} # Make it a Python dictionary {name:value, name:value}
myarray.append(dict) # Add it to the array
output = json.dumps(myarray) # Finally output as json string
print (output)
This is the slightly modified flow to call the script and process it
[{"id":"77b306137df5482d","type":"ui_chart","z":"4f02d48c1fd987a5","name":"","group":"04d86d5dc7122996","order":2,"width":0,"height":0,"label":"chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":890,"y":500,"wires":[[]]},{"id":"f11072b8baee6804","type":"exec","z":"4f02d48c1fd987a5","command":"/home/pi/foo","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":270,"y":420,"wires":[["7a6ec66b4a5acd27"],[],[]]},{"id":"867be5fe367ced2f","type":"inject","z":"4f02d48c1fd987a5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":420,"wires":[["f11072b8baee6804"]]},{"id":"a33eafdd94fae24a","type":"inject","z":"4f02d48c1fd987a5","name":"empty array to clear chart","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":150,"y":500,"wires":[["77b306137df5482d"]]},{"id":"7a6ec66b4a5acd27","type":"json","z":"4f02d48c1fd987a5","name":"","property":"payload","action":"","pretty":false,"x":410,"y":420,"wires":[["3f36a9d814642f40"]]},{"id":"3f36a9d814642f40","type":"split","z":"4f02d48c1fd987a5","name":"Split on comma","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":560,"y":420,"wires":[["fefa2028f47708e6"]]},{"id":"fefa2028f47708e6","type":"change","z":"4f02d48c1fd987a5","name":"payload, topic","rules":[{"t":"move","p":"payload.ssid","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"payload.signal_level","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":420,"wires":[["048800b73d1a39f5"]]},{"id":"048800b73d1a39f5","type":"switch","z":"4f02d48c1fd987a5","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"TALKTALK","vt":"str"},{"t":"cont","v":"BT-","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":420,"wires":[["77b306137df5482d"],["77b306137df5482d"]]},{"id":"04d86d5dc7122996","type":"ui_group","name":"Default","tab":"f3a8a67ff0904e39","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f3a8a67ff0904e39","type":"ui_tab","name":"HOME","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
My script is /home/pi/foo. Not a wise choice of name but it's experimental. And I'm calling it via the exec node. I think you are using a pythonshell node. I assume it's much the same.
I have to pass the returned string through a json node because exec only returns a string.
I split on commas not new lines because it's now a proper json object.
Setup payload and topic for the chart same as you.
I'm using a switch node to filter out just a few SSIDs for clarity.
Note that there are some accesspoints with blank or weird SSIDs which really mess up the chart, so this switch plays an important role.
Here is an example of the chart