How to make an IoT protocol (parsing, answering)?

Sorry, don't understand

It was you that decided to take off without it :slight_smile:

1 Like

Where do I insert your function node in my schema here ???

[{"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,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":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":379.00000381469727,"y":184.80000114440918,"wires":[["59e2af21.74ffa"]]},{"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":644,"y":302.80002880096436,"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":544,"y":363.8000297546387,"wires":[["2817006d.81197"]]},{"id":"2817006d.81197","type":"debug","z":"38fd6d46.07d862","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854.3000106811523,"y":354.2000045776367,"wires":[]},{"id":"17d7a98f.89c3c6","type":"debug","z":"38fd6d46.07d862","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":883.300012588501,"y":184.18750190734863,"wires":[]},{"id":"59e2af21.74ffa","type":"switch","z":"38fd6d46.07d862","name":"IWAP02 ANSWER OPTION","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"IWAP02,zh_cn,0","vt":"str"},{"t":"cont","v":"IWAP02,zh_cn,1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":636.3000068664551,"y":184.40001487731934,"wires":[["f8900c11.a7614","17d7a98f.89c3c6"],["17d7a98f.89c3c6","21466e3.35e1792"]]},{"id":"21466e3.35e1792","type":"change","z":"38fd6d46.07d862","name":"IWBP02 ADDRESS","rules":[{"t":"set","p":"payload","pt":"msg","to":"ADDRESS NEEDED","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":575.0000076293945,"y":411.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":"21280e2.e73acf2","type":"debug","z":"38fd6d46.07d862","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":395.29998779296875,"y":486,"wires":[]}]

I've tried this... whitout success !! That say :
node: Colin Split
function : (error)
"SyntaxError: Unexpected token )"

[{"id":"1a14219f.a11e6e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3100a75a.d1c1b8","type":"debug","z":"1a14219f.a11e6e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":687.3000335693359,"y":149.20000457763672,"wires":[]},{"id":"9682ef7b.96758","type":"function","z":"1a14219f.a11e6e","name":"Colin Split","func":"let answer = {}\nlet elements = msg.payload.split(\",\")  // this gives an array containing the bits\n// elements[0] is IWAP02 so we can ignore that\nanswer.language = elements[1]\nnode.warn(`language is: ${answer.language}`)  // for testing display it in the debug pane\nanswer.flag = elements[2]\nnode.warn(`flag is: ${answer.flag}`)\nanswer.baseCount = elements[3]\n// you can work out how to put the node.warn statements in yourself\nanswer.country = elements[4]\nanswer.operator = elements[5]\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":1,"noerr":10,"x":493.3000259399414,"y":149.20000457763672,"wires":[["3100a75a.d1c1b8"]]},{"id":"87acea40.d63618","type":"inject","z":"1a14219f.a11e6e","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":256,"y":202.20001316070557,"wires":[["9682ef7b.96758"]]},{"id":"1e587e1f.ce8ea2","type":"inject","z":"1a14219f.a11e6e","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,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":227,"y":124,"wires":[["9682ef7b.96758"]]}]

If you open the function node you will see red crosses showing syntax error. Hover over the first one and it will show an error message. Now compare what I said against this and you should be able to see what I have done. If you read the rest of the reference too then you should see what it is doing.
https://www.w3schools.com/js/js_loop_for.asp

Euh.... after 10 mns, I made a stroke!!! :ambulance:

I would like to extract, split and convert this complex string...

OUTPUT 1 :
IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#

That need to split as this : (split)IWAP01(split)080524(split)A(split)2232.9806N11404.9355E(split)000.1(split)061830(split)323.87(split)060(split)009(split)080(split)0(split)01(split)02(split),(split)460(split),(split)0(split),(split)9520(split),(split)3671(split)#(split)

where :
IWAP01=code for request location/tracking ; 080524=date as 24 th May 2008 ; A=valid datas
2232.9806N11404.9355E=22 degrees north latitude 32.9806 points, 114 degrees east longitude 04.9355 points ; 000.1=speed is 000.1 km/h ; 061830=GMT 06:18:30 ; 323.87 = direction angle is 323.87° ; 060=GSM signal ; 009=number of satellites ; 080 = battery level, 0=remaining space ; 01 = fortification state ; 02=working mode (it shows none settings if fortification=0 and working mode=00)
460,0,9520,3671 : LBS is base data ; MCC=country code ; 460=China ; 0=MNC ; 0=moving ;
; 9520=LAC in decimal ; 3671=CID in decimal.

OUTPUT 2 :
IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-
8C|97& Home3|74-DE-2B-44-88-8C|97#

That need to split as this : (split)IWAP01(split)080524(split)A(split)2232.9806N11404.9355E(split)000.1(split)061830(split)323.87(split)060(split)009(split)080(split)0(split)01(split)02(split),(split)460(split),(split)0(split),(split)9520(split),(split)3671(split),(split)Home(split)|(split)74-DE-2B-44-88-8C(split)|(split)97(split)&(split)Home1(split)|(split)74-DE-2B-44-88-8C(split)|(split)97(split)&(split)Home2(split)|(split)74-DE-2B-44-88-8C(split)|(split)97(split)& (split)Home3(split)|(split)74-DE-2B-44-88-8C(split)|(split)97(split)#(split)

where :
If state in GPS package is V or latitude and longitude are “ 0000.0000N00000.0000E”, it will call LBS additional datas where :
Home|74-DE-2B-44-88-8C|97 : one set of WIFI information, Home=SSID ; 74-DE-2B-44-88-8C=MAC address ; 97=signal strength ; variables are separated by“|”. Wifi informations can be multiple sets and are always separated by “&”.

tried to model the nodes below but I can't split and convert these values...

[{"id":"29207ae2.24de86","type":"tab","label":"IWAP01","disabled":false,"info":""},{"id":"6c249876.4d3fa8","type":"inject","z":"29207ae2.24de86","name":"TEST IWAP01","topic":"","payload":"IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":126,"y":70.79999542236328,"wires":[["e44ff81f.446118"]]},{"id":"87ff4d28.7f4f8","type":"inject","z":"29207ae2.24de86","name":"TEST IWAP01+LBS","topic":"","payload":"IWAP01080524V0000.0000N00000.0000E**000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97# ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":145,"y":115.79998970031738,"wires":[["e44ff81f.446118"]]},{"id":"e44ff81f.446118","type":"switch","z":"29207ae2.24de86","name":"SORT INCOMING","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^IWAP00","vt":"str","case":false},{"t":"regex","v":"^IWAP01","vt":"str","case":false},{"t":"regex","v":"^IWAP02","vt":"str","case":false},{"t":"regex","v":"^IWAP03","vt":"str","case":false},{"t":"regex","v":"^IWAP07","vt":"str","case":false},{"t":"regex","v":"^IWAP10","vt":"str","case":false},{"t":"regex","v":"^IWAP49","vt":"str","case":false},{"t":"regex","v":"^IWAPHT","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":8,"x":360.00000381469727,"y":116.80000305175781,"wires":[[],["b4ddb1af.258d4"],[],[],[],[],[],[]]},{"id":"b4ddb1af.258d4","type":"switch","z":"29207ae2.24de86","name":"AP01 Locating / OPTION","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"IWAP01080524A","vt":"str"},{"t":"cont","v":"IWAP01080524V","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":635.0000076293945,"y":83.79999542236328,"wires":[["62ed95ce.ffaf8c","e5204f6b.7f3d2"],["62ed95ce.ffaf8c","6fb04af.06aa4b4"]]},{"id":"e5204f6b.7f3d2","type":"function","z":"29207ae2.24de86","name":"Valid","func":"\nreturn msg;","outputs":1,"noerr":0,"x":860.5000114440918,"y":62.79999542236328,"wires":[[]]},{"id":"6fb04af.06aa4b4","type":"function","z":"29207ae2.24de86","name":"Invalid","func":"\nreturn msg;","outputs":1,"noerr":0,"x":862.5000114440918,"y":101.80000114440918,"wires":[[]]},{"id":"9d9bacfc.e391f","type":"comment","z":"29207ae2.24de86","name":"INCOMING MESSAGES","info":"","x":151.3000030517578,"y":20,"wires":[]},{"id":"62ed95ce.ffaf8c","type":"debug","z":"29207ae2.24de86","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":824.0000114440918,"y":186.20000648498535,"wires":[]}]

Yuk, that is horrible. Once again I think you will have to use a function node. You can split the last bits off using split(",") like we did before. Are the bits in the section before the first comma fixed length? If so then you can use substring to split out the various bits. But it is going to get a bit messy.
https://www.w3schools.com/jsref/jsref_substring.asp

Hi Colin. Thanks.
Yes indeed, the bits before the first comma will always get the same length. But here, the split criteria are far too numerous and multiples... I'am not able to write a node...

I have also completed my post to make it clearer. Please read it again??

Yesterday, I never found any solution for IWAP02... even with your advices. I tried till 3 in the morning :frowning:

Lets do one thing at a time then. Show us what you have got for that so far.

nothing else for this IWAP01 message. If i'm reading the protocol document that would probably 4 differents messages to parse...

[{"id":"29207ae2.24de86","type":"tab","label":"IWAP01","disabled":false,"info":""},{"id":"6c249876.4d3fa8","type":"inject","z":"29207ae2.24de86","name":"TEST IWAP01","topic":"","payload":"IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":126,"y":70.79999542236328,"wires":[["e44ff81f.446118"]]},{"id":"87ff4d28.7f4f8","type":"inject","z":"29207ae2.24de86","name":"TEST IWAP01+LBS","topic":"","payload":"IWAP01080524V0000.0000N00000.0000E**000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97# ","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":145,"y":115.79998970031738,"wires":[["e44ff81f.446118"]]},{"id":"e44ff81f.446118","type":"switch","z":"29207ae2.24de86","name":"SORT INCOMING","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^IWAP00","vt":"str","case":false},{"t":"regex","v":"^IWAP01","vt":"str","case":false},{"t":"regex","v":"^IWAP02","vt":"str","case":false},{"t":"regex","v":"^IWAP03","vt":"str","case":false},{"t":"regex","v":"^IWAP07","vt":"str","case":false},{"t":"regex","v":"^IWAP10","vt":"str","case":false},{"t":"regex","v":"^IWAP49","vt":"str","case":false},{"t":"regex","v":"^IWAPHT","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":8,"x":360.00000381469727,"y":116.80000305175781,"wires":[[],["b4ddb1af.258d4"],[],[],[],[],[],[]]},{"id":"b4ddb1af.258d4","type":"switch","z":"29207ae2.24de86","name":"AP01 Locating / OPTION","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"IWAP01080524A","vt":"str"},{"t":"cont","v":"IWAP01080524V","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":635.0000076293945,"y":83.79999542236328,"wires":[["62ed95ce.ffaf8c","e5204f6b.7f3d2"],["62ed95ce.ffaf8c","6fb04af.06aa4b4"]]},{"id":"e5204f6b.7f3d2","type":"function","z":"29207ae2.24de86","name":"Valid","func":"\nreturn msg;","outputs":1,"noerr":0,"x":860.5000114440918,"y":62.79999542236328,"wires":[[]]},{"id":"6fb04af.06aa4b4","type":"function","z":"29207ae2.24de86","name":"Invalid","func":"\nreturn msg;","outputs":1,"noerr":0,"x":862.5000114440918,"y":101.80000114440918,"wires":[[]]},{"id":"9d9bacfc.e391f","type":"comment","z":"29207ae2.24de86","name":"INCOMING MESSAGES","info":"","x":151.3000030517578,"y":20,"wires":[]},{"id":"62ed95ce.ffaf8c","type":"debug","z":"29207ae2.24de86","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":824.0000114440918,"y":186.20000648498535,"wires":[]}]

I would prefer to get th IWAP02 going first while I still remember what it was about.

It is exactly the same way Colin... but more complicated here :slight_smile: In the IWAP02 message I have the choice to generate 2 answers ... TAKE CARE CAUSE THE INCOMING MESSAGES CAN BE DIFFERENTS HERE!! JUST REALISED THIS NOW... :frowning:

AP02 Multiple bases locating package / OUTPUT 1
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#

AP02 Multiple bases locating package / OUTPUT 2
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#

Notice:
IWAP02= code locating
zh_cn: language notice
0:reply flag,the server doesn’t reply address when it’s 0,and replies address when it’s 1.
7: 7 sets of bases
460: MCC is country code
0: MNC operator code
9520|3671|10: LAC|CID|dbm shows a set of base information and the numbers should correspond tothe number of bases. 10:dbm is signal strength, multiple bases signal strength is suggested to be
arranged from high to low then downloaded, signal strength are using absolute values: 150 – abs(dbm)
4: sets of wifi
1|D8-24-BD-79-FA-1F|59: ssid|mac address| signal strength,signal strength are using absolute
values:150 – abs(signal strength)

NODE-RED SERVER will answer :
IWBP02# as base.... but If the reply flag is 1, the server needs to respond:
IWBP02F16D3357025E5753715C3A535753776D275953903100300037003900F753#
UNICODE encoded reply message from server which contains address(深圳市南山区
Notice:
南海大道 1079 号)

And the code I generate till here... : TAKE CARE THE INCOMING MESSAGES ARE DIFFERENTS ... AS FOR THE IWAP01

[{"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":379.00000381469727,"y":184.80000114440918,"wires":[["59e2af21.74ffa"]]},{"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":169.00000762939453,"y":318.80002784729004,"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":109.00000762939453,"y":426.8000297546387,"wires":[["2817006d.81197"]]},{"id":"2817006d.81197","type":"debug","z":"38fd6d46.07d862","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":854.3000106811523,"y":354.2000045776367,"wires":[]},{"id":"17d7a98f.89c3c6","type":"debug","z":"38fd6d46.07d862","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":862.3000106811523,"y":238.18750286102295,"wires":[]},{"id":"59e2af21.74ffa","type":"switch","z":"38fd6d46.07d862","name":"IWAP02 ANSWER OPTION","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"IWAP02,zh_cn,0","vt":"str"},{"t":"cont","v":"IWAP02,zh_cn,1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":409.3000259399414,"y":244.40000343322754,"wires":[["f8900c11.a7614","17d7a98f.89c3c6"],["17d7a98f.89c3c6","21466e3.35e1792"]]},{"id":"21466e3.35e1792","type":"change","z":"38fd6d46.07d862","name":"IWBP02 ADDRESS","rules":[{"t":"set","p":"payload","pt":"msg","to":"ADDRESS NEEDED","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":132.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"]]}]

Sorry, I am lost, I thought you were trying to split the IWAP02 message into its components, as in the function node yesterday. Your flow does not show that code at all. Please try to explain exactly what exact bit of the problem you are trying to solve. It is very difficult when you keep skipping from problem to problem.

Sorry Colin, I thought the problem was correctly described. I saw the other project, so I know it is really harder to solve.

I did not include your split function node in my post because only errors are generated with it. So no results!...

The split is the 1st step, after it is anyway necessary to convert the text position in decimal postion to display in a worldmap node. But I don't know if you can do this in the same split function node?? So maybe one step before the second ...

I need to :

  • get the incoming datas => done
  • split these datas in 2 outputs (if flag 0 or if flag 1) => done
    - in case of flag 0, I need to convert the datas into real tracking position (convert text to decimal tracking position!!!)=> not done
  • send answer to the whatch if flag 0 => done
    - in case of flag 1, I need to convert the datas into real tracking position (physical address) !!! => not done
    - send the answer to the whatch if flag 1 to setup the physical position address in Unicode => not done

Maybe if you look inside the present functions nodes I'm sending, you will understand better what to split when flag is 0 or flag is 1 ???

Please, tell me...

[{"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":[["59e2af21.74ffa"]]},{"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":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":864.3000106811523,"y":354.2000045776367,"wires":[]},{"id":"59e2af21.74ffa","type":"switch","z":"38fd6d46.07d862","name":"IWAP02 ANSWER OPTION","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"IWAP02,zh_cn,0","vt":"str"},{"t":"cont","v":"IWAP02,zh_cn,1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":411.30005264282227,"y":188.40001487731934,"wires":[["97b7209d.3d45"],["c907a988.f00058"]]},{"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 without calling LBS / flag 0","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#\n\nlet answer = {}\nlet elements = msg.payload.split(\",\")  // this gives an array containing the bits\n// elements[0] is IWAP02 so we can ignore that\nanswer.language = elements[1]\nnode.warn(`language is: ${answer.language}`)  // for testing display it in the debug pane\nanswer.flag = elements[2]\nnode.warn(`flag is: ${answer.flag}`)\nanswer.baseCount = elements[3]\n// you can work out how to put the node.warn statements in yourself\nanswer.country = elements[4]\nanswer.operator = elements[5]\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":1,"noerr":10,"x":746.3000106811523,"y":145.20000743865967,"wires":[["f8900c11.a7614","343e90e6.de5b1"]]},{"id":"c907a988.f00058","type":"function","z":"38fd6d46.07d862","name":"split calling LBS / flag 1","func":"//flag 1 to split\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 answer = {}\nlet elements = msg.payload.split(\",\")  // this gives an array containing the bits\n// elements[0] is IWAP02 so we can ignore that\nanswer.language = elements[1]\nnode.warn(`language is: ${answer.language}`)  // for testing display it in the debug pane\nanswer.flag = elements[2]\nnode.warn(`flag is: ${answer.flag}`)\nanswer.baseCount = elements[3]\n// you can work out how to put the node.warn statements in yourself\nanswer.country = elements[4]\nanswer.operator = elements[5]\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":1,"noerr":10,"x":728.3000106811523,"y":191.2000150680542,"wires":[["21466e3.35e1792","343e90e6.de5b1"]]},{"id":"343e90e6.de5b1","type":"debug","z":"38fd6d46.07d862","name":"incoming debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":875,"y":273,"wires":[]}]

You haven't even fixed the error identified by the red crosses. I explained what to do about that. Sort that first. Then see what happens when you run it.

Of course, we are going to stay in the same postion Colin. I did not do any progress since yesterday, same hour. It is desesperating!! I already told you I tried till 3 o'clock in the morning... This logic is not mine :frowning:

And today I tried to tell you that the 2 IWAP02 incoming messages are differents... So, how to split 2 messages with the same function node ???

[{"id":"daf10fec.5ee17","type":"tab","label":"SPLIT TEST COLIN","disabled":false,"info":""},{"id":"1d95b95f.c83757","type":"debug","z":"daf10fec.5ee17","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":687.3000335693359,"y":149.20000457763672,"wires":[]},{"id":"9dc12f9.b5544d","type":"function","z":"daf10fec.5ee17","name":"Colin Split","func":"let answer = {}\nlet elements = msg.payload.split(\",\")  // this gives an array containing the bits\n// elements[0] is IWAP02 so we can ignore that\nanswer.language = elements[1]\nnode.warn(`language is: ${answer.language}`)  // for testing display it in the debug pane\nanswer.flag = elements[2]\nnode.warn(`flag is: ${answer.flag}`)\nanswer.baseCount = elements[3]\n// you can work out how to put the node.warn statements in yourself\nanswer.country = elements[4]\nanswer.operator = elements[5]\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":1,"noerr":10,"x":493.3000259399414,"y":149.20000457763672,"wires":[["1d95b95f.c83757"]]},{"id":"b9ddbd5b.6e5bf","type":"inject","z":"daf10fec.5ee17","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|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":256,"y":202.20001316070557,"wires":[["9dc12f9.b5544d"]]},{"id":"74f6e78a.792918","type":"inject","z":"daf10fec.5ee17","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|3675|9,9520|3676|8,9520|3677|7#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":227,"y":124,"wires":[["9dc12f9.b5544d"]]}]

That will be the easy bit. Just concentrate on one message at a time. Once you get one working then worry about the other situation. Look at what it says when you hover over the first red cross. Look at that line of code carefully (with IT the detail is all important). Then look at the link I posted. What difference do you see?

I think I will finally understand the loop :star_struck:

I can see clearer now ...

Tomorrow morning, I will come with IWAP02 solved :slight_smile:

For the moment, after correcting the code, I have :
12/02/2019 à 18:44:18[node: split without calling LBS / flag 0]
"language is: zh_cn"

12/02/2019 à 18:44:18[node: split without calling LBS / flag 0]
"flag is: 0"

12/02/2019 à 18:44:18[node: incoming debug]
{ command: "IWAP02", languageNotice: "zh_cn", flag: "0", baseCount: "7", mcc: "460" … }

Excellent, now you can hopefully add in the other elements.
To go back to your question of splitting, then I suggest doing it after the function node. You can use msg.payload.flag to switch on.

maybe I spoke too fast Colin. Impossible to understand what you wrote below and to compare with :

Example

var i = 2;
var len = cars.length;
var text = "";
for (; i < len; i++) {
text += cars[i] + "
";
}
at https://www.w3schools.com/js/js_loop_for.asp

You wrote me :

// flag 0 to split
//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#
.....
// now need to get the bases
let i;
answer.bases = []
for (i=6, i<6+answer.baseCount, i++) { // error is : expected ';' and instead saw ')'
let baseElements = elements[i].split("|")
answer.push({lac: baseElements[0], cid: baseElements[1], dbm: baseElements[2]})
}
What I understand here is your not including the first 6 expressions from IWAP02,zh_cn,0,7,460,0,

But after I don't know what you mean with i<6+answer.baseCount

Please, explain...

The error is that it should be ; not , so the line should be
for (i=6; i<6+answer.baseCount; i++) {
The meaning of that line and the three lines after it is:
First set the variable i to the value 6 and run through the following three lines (demarcated by the {...}) which splits the next element on th | character and makes an object with the contents of that item and adds it into the array answer.bases.
Then it goes back to the start of the loop and adds one to i (so it is now seven) then it looks at the bit i<6+answer.baseCount which means "while i is less than 6+answer.baseCount, now baseCount is the number of bases so if i (now 7) is less than 6+answer.baseCount then it means that element[i] contains the next base, and we have not run off the end of the list of bases. So it runs through the next lines again so splits up the next base and adds it to answer.bases. Then it goes round again, and so on till it has interpreted all the bases, at which point i will be greater than 6+baseCount so it will drop out of the loop and carry on.
The net result is that answer.bases will contain all the base information, with lac, cid and dbm for each.
Perhaps it would be a good idea for you to look at a tutorial on javascript to get some more background into what is going on.