Can't split to prepare XML

#1

Hi,
Can someone give me a hand please?
I would like to split :
IWAP02,zh_cn,0,7,226,10,1440|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#

and format the array as :
226,10,1440,3671
226,10,9520,3672
226,10,9520,3673
226,10,9520,3674
226,10,9520,3675
226,10,9520,3676
226,10,9520,3677

Below are my nodes to follow the schema :

[{"id":"a4f787d0.7e7488","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a1ec6e30.852a2","type":"inject","z":"a4f787d0.7e7488","name":"LBS","topic":"","payload":"IWAP02,zh_cn,0,7,226,10,1440|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":86,"y":110.00000095367432,"wires":[["56ca0aa8.4cf9b4"]]},{"id":"56ca0aa8.4cf9b4","type":"function","z":"a4f787d0.7e7488","name":"Get flag and other parts","func":"// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|3671|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,460,0,9520|3671|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// Get flag\nmsg.flag = elements[2]                                  // 0\n\n// Get baseCountgsmTower\nmsg.baseCountgsmTower = Number(elements[3])             // 7\n\nmsg.gsmTowerStrings = elements[4]                       // 226\n\nreturn msg","outputs":1,"noerr":0,"x":300,"y":110.20001029968262,"wires":[["a56770a4.dd77f","b3775c82.01479"]]},{"id":"a56770a4.dd77f","type":"debug","z":"a4f787d0.7e7488","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":240.00000762939453,"y":141.2000093460083,"wires":[]},{"id":"b3775c82.01479","type":"switch","z":"a4f787d0.7e7488","name":"Route 0/1","property":"flag","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":235,"y":239.20001125335693,"wires":[["58afc28.302b43c"],[]]},{"id":"58afc28.302b43c","type":"function","z":"a4f787d0.7e7488","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\":\"eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA\",\"username\":\"35177180700178\"}}]}],\"gsm-tower\":[]}\n\n\n// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#\n\n\n\nlet elements = msg.elements; \nLocationRQ.flag = msg.flag; // true or false - A or V\nLocationRQ.gsmTowerStrings = msg.gsmTowerStrings\n\n// Get LBS datas\nlet i;\nlet gsmTowerStrings = LocationRQ.gsmTowerStrings;\nlet j;\nlet gsmTower = [];\nfor (j = 0; j < gsmTowerStrings.length; j++) {\n    let baseElements = gsmTowerStrings[j].split(\"|\")\n    gsmTower.push({ mcc: baseElements[4], mnc: baseElements[5], lac: baseElements[2], ci: baseElements[3]  }) // 460,0,9520|3671|\n}\n// adjust baseCountwifiAccessPoints just in case the number actually there didn't match that expexted\nLocationRQ.baseCountgsmTower = gsmTower.length\nLocationRQ[\"gsm-tower\"] = gsmTower;\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":263.00000762939453,"y":284.2000141143799,"wires":[["960ad642.585058"]]},{"id":"960ad642.585058","type":"debug","z":"a4f787d0.7e7488","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":222.0000114440918,"y":328.2000141143799,"wires":[]}]
0 Likes

#2

Hi, of course anyone with even a basic level of Javescript can tell you how to split up a string however I suspect that string will not always be in the same format.

that said here you go...

var data = 'IWAP02,zh_cn,0,7,226,10,1440|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#';
var dataParts = data.split(",");
data4 = dataParts[4];
data5 = dataParts[5];
//console.log(data4,data5);//should be 226,10
var i, newArrayOfArrays = [], newArrayOfStrings = [];
for (i = 6; i < dataParts.length; i++) { 
  let spl = dataParts[i].split("|");
  newArrayOfStrings.push(`${data4},${data5},${spl[0]},${spl[1]}`);//array of strings
  newArrayOfArrays.push([data4,data5,spl[0],spl[1]]);//array of array with desired values
  
}
console.log("Array of strings:", newArrayOfStrings);
console.log("Array of arrays:", newArrayOfArrays);

output...

Array of strings:[ "226,10,1440,3671", "226,10,9520,3672", "226,10,9520,3673", "226,10,9520,3674", "226,10,9520,3675", "226,10,9520,3676", "226,10,9520,3677" ]
Array of arrays:[ [ "226", "10", "1440", "3671" ], [ "226", "10", "9520", "3672" ], [ "226", "10", "9520", "3673" ], [ "226", "10", "9520", "3674" ], [ "226", "10", "9520", "3675" ], [ "226", "10", "9520", "3676" ], [ "226", "10", "9520", "3677" ] ]

play with it here...

0 Likes

#3

Nice. Thanks!

0 Likes

#4

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.... :frowning:

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":[]}]
0 Likes

#5

So if you have good XML, put it into an XML node to see what the JSON looks like. Then build your object the same way.

0 Likes

#6

I've tried!!! 5 days... and I can't!!! I tried to apply your method.

0 Likes

#7

Have you copied the good XML into the flow I first gave you and looked at the JSON output?
Do that now and copy the JSON output into a code block (```) here and I will tell you how to format the data into it.

0 Likes

#8

Going back to my office in 20 MN. Thanks.

0 Likes

#9

For flag = 0 :

{"LocationRQ":{"$":{"xmlns":"http://skyhookwireless.com/wps/2005","version":"2.26","street-address-lookup":"full"},"authentication":[{"$":{"version":"2.2"},"key":[{"$":{"key":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","username":"ABABABABABBABABABABAB"}}]}],"gsm-tower":[{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3671"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3672"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3673"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3674"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3675"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3676"]},{"mcc":["460"],"mnc":["0"],"lac":["9520"],"ci":["3677"]}]}}

0 Likes

#10

Dude, you really need to improve your questions.

instead of posting Can’t split to prepare XML. Can someone give me a hand please? I would like to split and format the array as
Which I answered!

you should have posted the real question, with examples of what you have done & where it failed - like you did here in your second attempt Can't split to prepare XML (post Number 4)

Your posts seriously lack necessary information for others to help you. We are not mind readers & we are not super happy wasting our time!

Right, so, you are completely missing silly obvious stuff. Can I ask that you please please please please study the solution I offer below and compare what I did to what you did & learn where you went wrong. I have changed as little as possible so you should spot the differences.

Look closely at the code changes inside the function nodes. Them 2 are where it happens!

PS: It took me about 2 mins to fix your flow and about 20 mins to write this!

On to the solution - but first some graphical help...

The solution...
[{"id":"cef2582b.f22018","type":"inject","z":"902baa68.978b18","name":"LBS","topic":"","payload":"IWAP02,zh_cn,0,7,226,10,1440|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":150,"y":100,"wires":[["19847d39.855dc3"]]},{"id":"19847d39.855dc3","type":"function","z":"902baa68.978b18","name":"Get flag and other parts","func":"// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|3671|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,460,0,9520|3671|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\nmsg.elements = msg.payload.replace('#','').split(\",\"); // this gives an array containing the bits\n\n// Get flag\nmsg.flag = msg.elements[2] // 0\n\n// Get baseCountgsmTower\nmsg.baseCountgsmTower = Number(msg.elements[3]) // 7\nmsg.mmc = msg.elements[4] // 226\nmsg.mnc = msg.elements[5] // 10\n\nreturn msg","outputs":1,"noerr":0,"x":350,"y":100,"wires":[["9e56d292.a2e1a","94464227.95164"]]},{"id":"9e56d292.a2e1a","type":"debug","z":"902baa68.978b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":550,"y":100,"wires":[]},{"id":"94464227.95164","type":"switch","z":"902baa68.978b18","name":"Route 0/1","property":"flag","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":300,"y":180,"wires":[["ddba49af.77fe18"],[]]},{"id":"ddba49af.77fe18","type":"function","z":"902baa68.978b18","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\":\"eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA\",\"username\":\"35177180700178\"}}]}],\"gsm-tower\":[]}\n\n\n// flag = 0 \n// IWAP02,zh_cn,0,7,226,10,1440|3671|13,9520|3672|12,9520|3673|11,9520|3674|10,9520|3675|9,9520|3676|8,9520|3677|7#\n\n\n\nlet elements = msg.elements; \nLocationRQ.flag = msg.flag; // true or false - A or V\nLocationRQ.gsmTowerStrings = msg.gsmTowerStrings\n\n// Get LBS datas\nlet i;\nlet gsmTowerStrings = LocationRQ.gsmTowerStrings;\nlet j;\nlet gsmTower = [];\nfor (j = 6; j < msg.elements.length; j++) {\n let spl = msg.elements[j].split(\"|\")\n gsmTower.push({ mcc: msg.mmc, mnc: msg.mnc, lac: spl[0], ci: spl[1] }) // 460,0,9520|3671|\n}\n// adjust baseCountwifiAccessPoints just in case the number actually there didn't match that expexted\nLocationRQ.baseCountgsmTower = gsmTower.length\nLocationRQ[\"gsm-tower\"] = gsmTower;\n\nmsg.payload = {LocationRQ: LocationRQ};\nreturn msg\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":510,"y":160,"wires":[["69088442.804d7c","c66fcc50.acc66"]]},{"id":"69088442.804d7c","type":"debug","z":"902baa68.978b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":690,"y":160,"wires":[]},{"id":"c66fcc50.acc66","type":"xml","z":"902baa68.978b18","name":"","property":"payload","attr":"","chr":"","x":690,"y":220,"wires":[["3496ccc5.eac964"]]},{"id":"3496ccc5.eac964","type":"debug","z":"902baa68.978b18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":830,"y":220,"wires":[]}]

And last the output...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LocationRQ
	xmlns="http://skyhookwireless.com/wps/2005" version="2.26" street-address-lookup="full">
	<authentication version="2.2">
		<key key="eJwVwcENACAIBLC3w5BAENCneExl3N3YShP-Rii3I1aJaUzbl1NsgLhykiK1Q1x72X0UYwtA" username="35177180700178"/>
	</authentication>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>1440</lac>
		<ci>3671</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3672</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3673</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3674</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3675</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3676</ci>
	</gsm-tower>
	<gsm-tower>
		<mcc>226</mcc>
		<mnc>10</mnc>
		<lac>9520</lac>
		<ci>3677</ci>
	</gsm-tower>
	<flag>0</flag>
	<gsmTowerStrings/>
	<baseCountgsmTower>7</baseCountgsmTower>
</LocationRQ>
2 Likes

#11

I'm going to... Thanks for this. Nice speech indeed :frowning:

0 Likes