Steve,
If you use datas isolated, that works... but I can't use your datas in my config. I need to get them set up in the way you you did help me before... cause
Same problem : flag = 0 or flag = 1 (as the other flow was flag = A or flag = V)... here the split is different.
I tried with your method to reverse XML in JSON but that is not for my level.
for flag = 0
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#
For flag = 0, the result in XML should be :
<?xml version="1.0" encoding="UTF-8" ?>
<LocationRQ xmlns="http://skyhookwireless.com/wps/2005" version="2.26" street-address-lookup="full">
<authentication version="2.2">
<key key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" username="ABABABABABBABABABABAB" />
</authentication>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3671</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3672</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3673</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3674</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3675</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3676</ci>
</gsm-tower>
<gsm-tower>
<mcc>460</mcc>
<mnc>0</mnc>
<lac>9520</lac>
<ci>3677</ci>
</gsm-tower>
</LocationRQ>
but my result is :
<?xml version="1.0" encoding="UTF-8" ?>
<LocationRQ xmlns="http://skyhookwireless.com/wps/2005" version="2.26" street-address-lookup="full">
<authentication version="2.2">
<key key="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" username="ABABABABABBABABABABAB" />
</authentication>
<gsm-tower>
<mcc>460</mcc>
<mcc>460</mcc>
<mcc>460</mcc>
<mcc>460</mcc>
<mcc>460</mcc>
<mcc>460</mcc>
<mcc>460</mcc>
<mnc>0</mnc>
<mnc>0</mnc>
<mnc>0</mnc>
<mnc>0</mnc>
<mnc>0</mnc>
<mnc>0</mnc>
<mnc>0</mnc>
<lac>9520</lac>
<lac>9520</lac>
<lac>9520</lac>
<lac>9520</lac>
<lac>9520</lac>
<lac>9520</lac>
<lac>9520</lac>
<ci>3671</ci>
<ci>3672</ci>
<ci>3673</ci>
<ci>3674</ci>
<ci>3675</ci>
<ci>3676</ci>
<ci>3677</ci>
</gsm-tower>
</LocationRQ>
and for flag = 1
IWAP02,zh_cn,1,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|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#
same disaster....
here are the nodes :
[{"id":"7eed26d6.bc6ce8","type":"tab","label":"TEST_STEVE","disabled":false,"info":""},{"id":"e5ea33d1.2ab45","type":"function","z":"7eed26d6.bc6ce8","name":"Prepare msg type V","func":"//Prepare JS object and fill out fields before conversion to XML\n\nvar LocationRQ = {\"$\":{\"xmlns\":\"http://skyhookwireless.com/wps/2005\",\"version\":\"2.26\",\"street-address-lookup\":\"full\"},\"authentication\":[{\"$\":{\"version\":\"2.2\"},\"key\":[{\"$\":{\"key\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"username\":\"ABABABABABABABBABAAB\"}}]}],\"access-point\":[],\"gsm-tower\":[]}\n\n// flag = V\n// IWAP02,zh_cn,1,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|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#\n\nlet elements = msg.elements; \nLocationRQ.flag = msg.flag; \n\n\n// Get LBS datas\nLocationRQ[\"gsm-tower\"] = msg[\"gsm-tower\"];\n\n\n// Get WIFI datas \nLocationRQ[\"access-point\"] = msg[\"access-point\"];\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg;","outputs":1,"noerr":0,"x":506,"y":289.20001316070557,"wires":[["d94b8c9e.8405c","9cc7bbd6.459af8","a7254729.988af8"]]},{"id":"d94b8c9e.8405c","type":"function","z":"7eed26d6.bc6ce8","name":"Format msg V","func":"\ndelete msg.payload.LocationRQ.flag;\ndelete msg.payload.LocationRQ.signalStrength;\ndelete msg.payload.LocationRQ.batteryLevel;\ndelete msg.payload.LocationRQ.baseCountwifiAccessPoints\nvar msg1={};\nmsg1.payload=msg.payload;\nreturn msg1;","outputs":1,"noerr":0,"x":487,"y":322.2000150680542,"wires":[["a7254729.988af8"]]},{"id":"af7d3d28.09bad","type":"switch","z":"7eed26d6.bc6ce8","name":"Route 0/1","property":"flag","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":244,"y":253.20001125335693,"wires":[["e90269a5.d80e98"],["e5ea33d1.2ab45"]]},{"id":"9cc7bbd6.459af8","type":"xml","z":"7eed26d6.bc6ce8","name":"","property":"payload","attr":"","chr":"","x":736.0000076293945,"y":246.20001125335693,"wires":[["258d636.79c469c","669353c.e96ecac"]]},{"id":"a7254729.988af8","type":"debug","z":"7eed26d6.bc6ce8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":735.0000114440918,"y":357.2000141143799,"wires":[]},{"id":"e90269a5.d80e98","type":"function","z":"7eed26d6.bc6ce8","name":"Prepare msg type 0","func":"//Prepare JS object and fill out fields before conversion to XML\n\nvar LocationRQ = {\"$\":{\"xmlns\":\"http://skyhookwireless.com/wps/2005\",\"version\":\"2.26\",\"street-address-lookup\":\"full\"},\"authentication\":[{\"$\":{\"version\":\"2.2\"},\"key\":[{\"$\":{\"key\":\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\"username\":\"ABABABABABABABBABAAB\"}}]}],\"gsm-tower\":[]}\n\n\n// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#\n\nlet elements = msg.elements; \n// LocationRQ.flag = msg.flag; // 0\n\n// Get LBS datas\nLocationRQ[\"gsm-tower\"] = msg[\"gsm-tower\"];\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg;","outputs":1,"noerr":0,"x":499.00000381469727,"y":184.20001125335693,"wires":[["acfaac8.026f45","6b11d731.f07968"]]},{"id":"f1e4bd7f.9584f","type":"function","z":"7eed26d6.bc6ce8","name":"Get flag and other parts","func":"// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#\n// flag = 1\n// IWAP02,zh_cn,1,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|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#\n\nlet elements = msg.payload.replace('#','').split(\",\"); // this gives an array containing the bits\n\n// GET flag\nmsg.flag = elements[2]; // 0 or 1\n\n// Get LBS datas\nmsg.baseCountcellTowers = Number(elements[3]) // 7\nlet i;\nlet gsmTower = [];\nfor (i=6; i<6+msg.baseCountcellTowers; i++) {\n let baseElements = elements[i].split(\"|\")\n gsmTower.push({ mcc: elements[4], mnc: elements[5], lac: baseElements[0], ci: baseElements[1] }) // 226,10,1440,22337....\n}\nmsg[\"gsm-tower\"] = [gsmTower];\n\n// Get WIFI datas\nmsg.baseCountwifiAccessPoints = Number(elements[i] || 0) // this will be zero if there aren't any\nlet ap = []\nif (msg.baseCountwifiAccessPoints > 0) {\n i = i+1 // move on to wifi bases\n let wifiAccessPointsStrings = elements[i].split(\"&\")\n let j;\n for (j=0; j<wifiAccessPointsStrings.length; j++) {\n let baseElements = wifiAccessPointsStrings[j].split(\"|\")\n ap.push({ mac: baseElements[1].replace(/:/g,\"\"), ssid: baseElements[0], [\"signal-strength\"]: baseElements[2] }) // 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\n }\n // adjust baseCountwifiAccessPoints just in case the number actually there didn't match that expexted\n msg.baseCountwifiAccessPoints = ap.length\n}\nmsg[\"access-point\"] = [ap];\n\nreturn msg \n","outputs":1,"noerr":0,"x":309,"y":124.20001029968262,"wires":[["af7d3d28.09bad","c93a1358.f03c9"]]},{"id":"258d636.79c469c","type":"debug","z":"7eed26d6.bc6ce8","name":"Final XML","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":744.0000114440918,"y":278.20001316070557,"wires":[]},{"id":"6b11d731.f07968","type":"function","z":"7eed26d6.bc6ce8","name":"Format msg 0","func":"\ndelete msg.flag;\ndelete msg.payload.LocationRQ.flag\ndelete msg.baseCountcellTowers;\ndelete msg[\"gsm-tower\"];\ndelete msg.baseCountwifiAccessPoints;\ndelete msg[\"access-point\"];\n\nreturn msg;","outputs":1,"noerr":0,"x":487,"y":217.20001125335693,"wires":[["9cc7bbd6.459af8","acfaac8.026f45"]]},{"id":"acfaac8.026f45","type":"debug","z":"7eed26d6.bc6ce8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750.0000114440918,"y":185.2000093460083,"wires":[]},{"id":"5410e46c.4941fc","type":"inject","z":"7eed26d6.bc6ce8","name":"LBS","topic":"","payload":"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#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":81,"y":99,"wires":[["f1e4bd7f.9584f"]]},{"id":"31767ee0.20c792","type":"inject","z":"7eed26d6.bc6ce8","name":"LBS+WIFI","topic":"","payload":"IWAP02,zh_cn,1,7,226,10,1440|22337|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|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":90,"y":156.20001316070557,"wires":[["f1e4bd7f.9584f"]]},{"id":"c93a1358.f03c9","type":"debug","z":"7eed26d6.bc6ce8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":249.00000762939453,"y":155.2000093460083,"wires":[]},{"id":"669353c.e96ecac","type":"function","z":"7eed26d6.bc6ce8","name":"Format POST REQUEST","func":"// Get positions \n//node.log(msg.payload);\nmsg.headers = {};\nmsg.headers['content-type'] = 'text/xml';\n//return msg;\n//node.log(msg.payload);\nreturn msg;\n","outputs":1,"noerr":0,"x":523.0000076293945,"y":438.0000057220459,"wires":[["797f1fb3.8d9fd"]]},{"id":"797f1fb3.8d9fd","type":"debug","z":"7eed26d6.bc6ce8","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":472.0000114440918,"y":469.0000057220459,"wires":[]}]