Unfortunatly, the result is not ok as for :
[{"id":"38fd6d46.07d862","type":"tab","label":"IWAP02","disabled":false,"info":""},{"id":"4a330da4.5ac7b4","type":"inject","z":"38fd6d46.07d862","name":"TEST IWAP02#","topic":"","payload":"IWAP02,zh_cn,0,7,460,0,9520|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|367 5|9,9520|3676|8,9520|3677|7#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":114,"y":132.7999906539917,"wires":[["b13eed31.409e9"]]},{"id":"b13eed31.409e9","type":"switch","z":"38fd6d46.07d862","name":"SORT INCOMING","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^IWAP02","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":381.00000381469727,"y":143.8000030517578,"wires":[["97b7209d.3d45"]]},{"id":"168c17f3.e614a8","type":"comment","z":"38fd6d46.07d862","name":"INCOMING MESSAGES FROM THE WATCH","info":"","x":177.3000030517578,"y":22,"wires":[]},{"id":"e6d39b5d.4017e8","type":"comment","z":"38fd6d46.07d862","name":"OUTGOING MESSAGES TO THE WATCH","info":"","x":184.00000762939453,"y":355.8000297546387,"wires":[]},{"id":"f8900c11.a7614","type":"change","z":"38fd6d46.07d862","name":"IWBP02# ","rules":[{"t":"set","p":"payload","pt":"msg","to":"IWBP02# ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":97.00000762939453,"y":428.80000591278076,"wires":[["2817006d.81197"]]},{"id":"2817006d.81197","type":"debug","z":"38fd6d46.07d862","name":"outgoing debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":864.3000106811523,"y":354.2000045776367,"wires":[]},{"id":"21466e3.35e1792","type":"change","z":"38fd6d46.07d862","name":"IWBP02 LBS ADDRESS","rules":[{"t":"set","p":"payload","pt":"msg","to":"ADDRESS NEEDED","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":152.00000762939453,"y":492.0000057220459,"wires":[["2817006d.81197"]]},{"id":"9cd8efdf.edd82","type":"inject","z":"38fd6d46.07d862","name":"TEST IWAP02_ADDRESS","topic":"","payload":"IWAP02,zh_cn,1,7,460,0,9520|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|367 5|9,9520|3676|8,9520|3677|7,4,1|D8-24-BD-79-FA-1F|59&2|3C-46-D8-6D-CE-01|81&3|0C-4C-39-1A-7C-65|69&4|70-A8-E3-5D-D7-C0|65#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":143,"y":211.00000381469727,"wires":[["b13eed31.409e9"]]},{"id":"97b7209d.3d45","type":"function","z":"38fd6d46.07d862","name":"split flag 0/1","func":"// flag 0 to split\n//IWAP02,zh_cn,0,7,460,0,9520|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#\nlet answer = {} \nlet elements = msg.payload.split(\",\") // this gives an array containing the bits\nanswer.command = elements[0] // IWAP02\nanswer.languageNotice = elements[1] // zh_cn\nanswer.flag = elements[2] // 0\nnode.warn(`flag is: ${answer.flag}`) // warning flag\nanswer.baseCount = elements[3] // 7\n// you can work out how to put the node.warn statements in yourself\nanswer.mcc = elements[4] // 460\nanswer.mnc = elements[5] // 7\n// now need to get the bases\nlet i;\nanswer.bases = []\nfor (i=6; i<6+answer.baseCount; i++) {\n let baseElements = elements[i].split(\"|\")\n answer.push({lac: baseElements[0], cid: baseElements[1], dbm: baseElements[2]})\n}\n// the rest needs to go in here\nmsg.payload = answer\nreturn msg","outputs":2,"noerr":0,"x":713.3000068664551,"y":144.20001411437988,"wires":[["343e90e6.de5b1"],[]],"outputLabels":[" 0","1"]},{"id":"343e90e6.de5b1","type":"debug","z":"38fd6d46.07d862","name":"incoming debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":723.0000114440918,"y":209.00000286102295,"wires":[]}]
The error :
13/02/2019 Ă 17:10:100:
** [node: split flag 0/1]function : (error)**
"TypeError: answer.push is not a function"
I've also lost all the others infos ( command / languageNotice, mcc, mnc, ...) if I'm using :
let i;
answer.bases = []
for (i=6; i<6+answer.baseCount; i++) {
** let baseElements = elements[i].split("|")**
** answer.push({lac: baseElements[0], cid: baseElements[1], dbm: baseElements[2]})**
}
In the code you gave me you also wrote :
// the rest needs to go in here... What dou you mean Colin?
Thanks...