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


#1

Hi,
I'm a beginner with Node-Red. I got a project ... pretty complicate to execute (to me). I need to authentify 1 device, to accept or not the connexion (comparing ID to db), to parse the datas I received from the device, to store the data in this db to record all events.
I'm actually trying to use a protocol to discuss with a device, equiped with a GPS/LBS. I can actually discuss with the device... device=>server and server=>device.
To start this, I choose to apply a simple protocol ( device <=> server). The scenario is based on requests/answers and is the following :

################################"START##########################

A/ The device is trying to authentify (TCP/PORT with buffer/string) with a login on the server : XYRQ00123456789101112%
XY is the general identifier/ RQis the code to say it is a request/ 00 is the code for login/ 123456789101112 is the device ID/ % is the terminator.
The server should verify in a db (to create in node-red) to know if the device ID is real/fake to start the discussion or reject the device with a message like "Error! you are the devil!!" :slight_smile:

A1/ If authentified, the server has to send back (TCP/PORT with buffer/string) an answer to setup the device as : XYAW00,20190207083012,1%
where XY is the general identifier/ AW**is the code to say it is a answer/ 20190207083012 is the YearMonthDayHourMinuteSecond/ 1 is the time UTC/ % is the terminator (to store in the db).

B/ The device is sending infos to feed the system (GPS+LBS+Status+Base +WIFI combining).
XYRQ01190207A2232.9806N11404.9355E000.1061830323.8706000908000102,283,05,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#
where XY is the general identifier/ RQis the code to say it is a request/ 01 is the code for tracking/ 190207 is YearMonthDay/ A is valid data, substitute by V should indicate invalid data and will get LBS data/ 2232.9806N11404.9355E000.1 is 22 degrees north latitude 32.9806 points,114 degrees east longitude 04.9355 points. 0000.0000N00000.0000E if the latitude and longitude are invalid / 000.1 is the speed in km/h. 0 if the longitude and latitude are invalid/ 061830 is the GMT/ 323.87 is the direction angle as 323.87°/ 06000908000102 060 is GSM signal, 009 is the number of satellites, 080 is the battery level, 0 is remaining space, 01 is fortification state, 02 is working mode, (it shows none settings if fortification and working mode are 00)/ 283,05,9520,3671 : 283 means Armenia, 05 is MNC, 0 is moving, 9520 is LAC in decimal, 3671 is CID in decimal.

If the GPS state is V or latitude and longitude are “0000.0000N00000.0000E”, it will try to switch on LBS data (Status+Base +WIFI).
Home|74-DE-2B-44-88-8C|97 is WIFI information, Home is SSID, 74-DE-2B-44-88-8C is MACADDRESS/ 97 is the signal strength.
Variables are separated by“|”,wifi information can be multiple sets and are separated by “&”.

B1/ Server answer ack to send back to the device : XYAW01%

###################################END##########################

There are 15/20 messages like this. (heart rate, blood pressure, pedometer...).
Everything must be kept in a database. All events will be displayed in Worldmap node.

Can anyone help me to parse the incoming datas and create the right command answers??? Please, don't send me on https://nodered.org/docs/writing-functions
as this is not appropriate...

Thanks for your help!!! :wink:


#2

Putting aside this sounds like a homework assignment, can you share where you have got to so far?

Do you have a flow setup that can start receiving the data from the devices? That sounds like the right place to start.

What type of database are you using?


#3

Hi Knolleeary! Thanks for your anwser... My project sounds more like a punishment... not a home assignment!!!!!

In fact, I baught a "smart"watch MKT2303 in HK (nucleus rtos... beurkkkk!!). But that said, the manufacturer just delivered me an awfull Android APP unsable for Europe ... where mostly of the functions are doubled in Chineese!!!!!!! Even the map is from Baidu :frowning: I would like to use this 2G watch here in Europe ... and Node-Red is the solution!!

For the moment, I just have the manufacturer protocol in a document... He send me to hell if I was not happy... So, I started to simulate the incoming possible messages... 10 max but never the same format, wich should arrive in the TCP buffer on port XXX (working). But I don't know how to authentify, parse, split, store and send back commands...

Please look at my attachment in my next message... This is only the device => server part :


#4

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.


#5

Of course, I also have the manufacturer pdf protocol document is you want to have a look?
The original protocol is named TRV but as this "manufacturer" modified it, I can't use or a normalized GPS tracking software as TRACCAR or GPSWOX (standard java softs integrating 150 protocols). But here, due to these modifications, it is not possible.


#6

Sorry, better ?

[{"id":"31352ecc.e68872","type":"tab","label":"TestWatch","disabled":false,"info":""},{"id":"a1aa21de.65064","type":"inject","z":"31352ecc.e68872","name":"AP00 Login","topic":"","payload":"IWAP00353456789012345#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":114,"y":46.00000190734863,"wires":[["4f21f9e0.19dfa8"]]},{"id":"985cc724.d8c948","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":515.0000534057617,"y":101.00000286102295,"wires":[]},{"id":"34a6f62.80a8b0a","type":"inject","z":"31352ecc.e68872","name":"AP01 Locating ","topic":"","payload":"IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,36 71,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":123,"y":172.00000190734863,"wires":[["1ed14ba0.28e7c4"]]},{"id":"d23890fd.0badb","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","x":510.0000534057617,"y":223.00000286102295,"wires":[]},{"id":"1ed14ba0.28e7c4","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":512.0000076293945,"y":171.00000190734863,"wires":[["d23890fd.0badb"]]},{"id":"29c12812.cbdcd8","type":"inject","z":"31352ecc.e68872","name":"AP02 Multiple bases locating","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,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":162,"y":300,"wires":[["13fd7d31.418633"]]},{"id":"a216d13b.d7c64","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":506.0000534057617,"y":351.00000286102295,"wires":[]},{"id":"13fd7d31.418633","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":508.00000762939453,"y":299.00000190734863,"wires":[["a216d13b.d7c64"]]},{"id":"cf7d6d51.f6703","type":"inject","z":"31352ecc.e68872","name":"AP03 Heartbeat","topic":"","payload":"IWAP03,06000908000102,5555,30#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":425,"wires":[["342ec934.b28dd6"]]},{"id":"62a0acc0.a82934","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":504.0000534057617,"y":476.00000286102295,"wires":[]},{"id":"342ec934.b28dd6","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":506.00000762939453,"y":424.00000190734863,"wires":[["62a0acc0.a82934"]]},{"id":"f1a31c30.be7f3","type":"inject","z":"31352ecc.e68872","name":"AP07 Upload audio","topic":"","payload":"IWAP07,20140818064408,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":126,"y":541,"wires":[["c05c1740.4daf58"]]},{"id":"91f83ec3.1e632","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":500.0000534057617,"y":592.000002861023,"wires":[]},{"id":"c05c1740.4daf58","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":502.00000762939453,"y":540.0000019073486,"wires":[["91f83ec3.1e632"]]},{"id":"3c47fb8b.337ee4","type":"inject","z":"31352ecc.e68872","name":"AP10 Alarm and Return address","topic":"","payload":"IWAP10080524A2232.9806N11404.9355E000.1061830323.8706000908000502,460,0,9520,36 71,00,zh-cn,00,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":165,"y":670,"wires":[["b36f7966.9399f8"]]},{"id":"3c0b067e.80564a","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":499.0000534057617,"y":721.000002861023,"wires":[]},{"id":"b36f7966.9399f8","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":501.00000762939453,"y":669.0000019073486,"wires":[["3c0b067e.80564a"]]},{"id":"8acc2b9b.751ba8","type":"inject","z":"31352ecc.e68872","name":"AP49 Upload heart rate","topic":"","payload":"IWAP49,68#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":134,"y":786.2000122070312,"wires":[["bf7b51e3.d7b17"]]},{"id":"c47ccb75.143d98","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":498.0000534057617,"y":837.2000150680542,"wires":[]},{"id":"bf7b51e3.d7b17","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":500.00000762939453,"y":785.2000141143799,"wires":[["c47ccb75.143d98"]]},{"id":"c76cd3e7.d5985","type":"inject","z":"31352ecc.e68872","name":"APHT Upload heart rate and blood pressure","topic":"","payload":"IWAPHT,60,130,85#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":204,"y":910.2000122070312,"wires":[["b1b2af7d.068fb"]]},{"id":"c8825a6f.a674b8","type":"debug","z":"31352ecc.e68872","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":498.0000534057617,"y":961.2000150680542,"wires":[]},{"id":"b1b2af7d.068fb","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":500.00000762939453,"y":909.2000141143799,"wires":[["c8825a6f.a674b8"]]},{"id":"4f21f9e0.19dfa8","type":"function","z":"31352ecc.e68872","name":"split(#)","func":"msg.parts = msg.payload.split(\"#\")\nreturn msg;","outputs":1,"noerr":0,"x":513.0000076293945,"y":48.00000047683716,"wires":[["985cc724.d8c948"]]}]

#7

I probably could be more inspired by this excellent job done by eschava and found at https://flows.nodered.org/flow/59d1529d5cc479995dd5799fd4ea188d ... but I'm clearly not able to modify it :

 [{"id":"f98f185d.7599e8","type":"tab","label":"GPS-TEST","disabled":false,"info":""},{"id":"c507ecb2.4bca1","type":"tcp in","z":"f98f185d.7599e8","name":"","server":"server","host":"","port":"8002","datamode":"stream","datatype":"utf8","newline":"]","topic":"","base64":false,"x":83,"y":96,"wires":[["3871dd6.2fa4a22","b056751d.3f6358"]]},{"id":"3871dd6.2fa4a22","type":"debug","z":"f98f185d.7599e8","name":"watch receive","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":293,"y":46,"wires":[]},{"id":"897084a0.56bce8","type":"tcp out","z":"f98f185d.7599e8","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":863,"y":366,"wires":[]},{"id":"b244b04.9c09d5","type":"change","z":"f98f185d.7599e8","name":"LK","rules":[{"t":"set","p":"payload","pt":"msg","to":"LK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":373,"y":256,"wires":[["b80fa253.ee7b5"]]},{"id":"2575ab4f.1cd644","type":"inject","z":"f98f185d.7599e8","name":"1❤","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":206,"wires":[["b59e973f.2330d8"]]},{"id":"d1c5abff.56f378","type":"inject","z":"f98f185d.7599e8","name":"2❤","topic":"","payload":"2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":246,"wires":[["b59e973f.2330d8"]]},{"id":"35ff4183.68776e","type":"template","z":"f98f185d.7599e8","name":"format","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{id}}*{{length}}*{{payload}}{{param}}]","output":"str","x":623,"y":366,"wires":[["897084a0.56bce8","53f3feb.59075"]]},{"id":"9c1d0cf0.b30c2","type":"change","z":"f98f185d.7599e8","name":"save session","rules":[{"t":"set","p":"sesion","pt":"flow","to":"_session","tot":"msg"},{"t":"set","p":"id","pt":"flow","to":"parts[0] & '*' & parts[1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":703,"y":76,"wires":[[]]},{"id":"ceeb3ece.43639","type":"change","z":"f98f185d.7599e8","name":"load session","rules":[{"t":"set","p":"_sesion","pt":"msg","to":"session","tot":"flow"},{"t":"set","p":"id","pt":"msg","to":"id","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":643,"y":316,"wires":[["35ff4183.68776e"]]},{"id":"23a112e3.8a720e","type":"switch","z":"f98f185d.7599e8","name":"command","property":"parts[3]","propertyType":"msg","rules":[{"t":"regex","v":"^LK","vt":"str","case":false},{"t":"regex","v":"^UD","vt":"str","case":false},{"t":"regex","v":"^UD2","vt":"str","case":false}],"checkall":"false","repair":false,"outputs":3,"x":443,"y":136,"wires":[["b244b04.9c09d5","9c1d0cf0.b30c2","969d8a44.e524f8"],["575176ef.9fd738"],["575176ef.9fd738"]],"outputLabels":["LK","UD","UD2"]},{"id":"d3b1767e.22a878","type":"inject","z":"f98f185d.7599e8","name":"","topic":"","payload":"привет","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":316,"wires":[["356e912a.9212fe"]]},{"id":"53f3feb.59075","type":"debug","z":"f98f185d.7599e8","name":"watch send","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":883,"y":416,"wires":[]},{"id":"a4b23ee4.d3862","type":"inject","z":"f98f185d.7599e8","name":"","topic":"","payload":"hello","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":356,"wires":[["356e912a.9212fe"]]},{"id":"356e912a.9212fe","type":"function","z":"f98f185d.7599e8","name":"hex","func":"var buf = Buffer.from(msg.payload, 'utf16le');\nbuf.swap16();\nmsg.payload = buf.toString('hex');\nreturn msg;","outputs":1,"noerr":0,"x":223,"y":336,"wires":[["d8d40f75.d8a6"]]},{"id":"b80fa253.ee7b5","type":"function","z":"f98f185d.7599e8","name":"hex(length)","func":"var len = msg.payload.length\nif (msg.param)\n    len += msg.param.toString().length\nmsg.length = (len+0x10000).toString(16).substr(-4)\nreturn msg;","outputs":1,"noerr":0,"x":633,"y":256,"wires":[["ceeb3ece.43639"]]},{"id":"1b9f7d2e.e07213","type":"inject","z":"f98f185d.7599e8","name":"TZ+2","topic":"","payload":"+2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":416,"wires":[["925739a.03c3cc8"]]},{"id":"ec7b409f.eb211","type":"inject","z":"f98f185d.7599e8","name":"TZ+3","topic":"","payload":"+3","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":456,"wires":[["925739a.03c3cc8"]]},{"id":"d25af64b.ab0568","type":"inject","z":"f98f185d.7599e8","name":"","topic":"","payload":"12345678","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":83,"y":506,"wires":[["703df2c8.b4893c"]]},{"id":"b056751d.3f6358","type":"function","z":"f98f185d.7599e8","name":"split(,)","func":"msg.parts = msg.payload.split(\",\")\nreturn msg;","outputs":1,"noerr":0,"x":263,"y":96,"wires":[["23a112e3.8a720e"]]},{"id":"d8d40f75.d8a6","type":"change","z":"f98f185d.7599e8","name":"MESSAGE,","rules":[{"t":"set","p":"param","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"MESSAGE,","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":393,"y":336,"wires":[["b80fa253.ee7b5"]]},{"id":"b59e973f.2330d8","type":"change","z":"f98f185d.7599e8","name":"FLOWER,","rules":[{"t":"set","p":"param","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"FLOWER,","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":393,"y":296,"wires":[["b80fa253.ee7b5"]]},{"id":"703df2c8.b4893c","type":"change","z":"f98f185d.7599e8","name":"MONITOR,","rules":[{"t":"set","p":"param","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"MONITOR,","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":393,"y":416,"wires":[["b80fa253.ee7b5"]]},{"id":"925739a.03c3cc8","type":"change","z":"f98f185d.7599e8","name":"LZ,9,","rules":[{"t":"set","p":"param","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"LZ,9,","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":373,"y":376,"wires":[["b80fa253.ee7b5"]]},{"id":"d694b35f.41885","type":"inject","z":"f98f185d.7599e8","name":"","topic":"","payload":"87654321","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":83,"y":546,"wires":[["703df2c8.b4893c"]]},{"id":"21749bc.4bb5d64","type":"change","z":"f98f185d.7599e8","name":"CR","rules":[{"t":"set","p":"payload","pt":"msg","to":"CR","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":373,"y":456,"wires":[["b80fa253.ee7b5"]]},{"id":"b6b778c4.b31948","type":"inject","z":"f98f185d.7599e8","name":"location","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":73,"y":596,"wires":[["21749bc.4bb5d64"]]},{"id":"969d8a44.e524f8","type":"function","z":"f98f185d.7599e8","name":"split(,)","func":"msg.parts = msg.parts[3].split(\",\")\nreturn msg;","outputs":1,"noerr":0,"x":683,"y":116,"wires":[["2d0191da.6d196e"]]},{"id":"575176ef.9fd738","type":"function","z":"f98f185d.7599e8","name":"split(,)","func":"msg.parts = msg.parts[3].split(\",\")\nreturn msg;","outputs":1,"noerr":0,"x":683,"y":176,"wires":[["abd34e2.d120ab"]]},{"id":"2d0191da.6d196e","type":"change","z":"f98f185d.7599e8","name":"pedometer/battery","rules":[{"t":"set","p":"pedometer","pt":"msg","to":"parts[1]","tot":"msg"},{"t":"set","p":"battery","pt":"msg","to":"parts[3]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":883,"y":116,"wires":[["37cf4a21.b02a36","29e8680.d72d898"]]},{"id":"abd34e2.d120ab","type":"change","z":"f98f185d.7599e8","name":"pedometer/battery/location","rules":[{"t":"set","p":"pedometer","pt":"msg","to":"parts[14]","tot":"msg"},{"t":"set","p":"battery","pt":"msg","to":"parts[13]","tot":"msg"},{"t":"set","p":"location","pt":"msg","to":"[parts[4], parts[6]]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":913,"y":176,"wires":[["37cf4a21.b02a36","29e8680.d72d898","a072e12a.a5fcd","25a2d952.976cc6"]]},{"id":"37cf4a21.b02a36","type":"debug","z":"f98f185d.7599e8","name":"Pedometer","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"pedometer","x":1193,"y":116,"wires":[]},{"id":"29e8680.d72d898","type":"debug","z":"f98f185d.7599e8","name":"Battery","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"battery","x":1183,"y":176,"wires":[]},{"id":"a072e12a.a5fcd","type":"debug","z":"f98f185d.7599e8","name":"Location","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"location","x":1183,"y":236,"wires":[]},{"id":"2d0ef920.988f26","type":"worldmap","z":"f98f185d.7599e8","name":"GPS watch","lat":"","lon":"","zoom":"10","layer":"OSM grey","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","x":1393,"y":306,"wires":[]},{"id":"25a2d952.976cc6","type":"change","z":"f98f185d.7599e8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"name\": \"GPS watch\", \"lat\" : location[0], \"lon\": location[1]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1203,"y":306,"wires":[["2d0ef920.988f26"]]}] 

#8

Does someone have an idea?... Is it so difficult to realise under Node-Red?


#9

It is not clear to me why you are unable to modify it.


#10

Euh... I don't understand how to split and re-use multiple messages with a complete difference of syntax for each of them, but coming from the same source ??

Maybe... that is because I don't know any java lang or programming languages and I discovered Node-Red 3 days ago?

If I knew it... I would probably not ask for help ?

Am I good with the answers ? :slight_smile:


#11

It is javascript not java, whoever called it javascript has been the cause of much confusion over the years.

I suspect maybe you are jumping in with a rather complex problem, you might be better to start with some simpler tasks and work up to the problem that way.
Your flow is still not importable I am afraid, you have got the backticks ok but there is something wrong with the contents. Try and import it yourself and you will see.


#12

Something else you could do is to examine the flow you linked to and work out how it works. Put debug nodes in at various points to see what each node does. Any specific things you don't understand then ask again. Remember a flow is a set of nodes. The end product is the result of each node doing what it should. So to understand the flow you need to understand the function of each node.
If you are trying to understand some javascript then the W3schools site is a good reference.


#13

Hi Colin,

I think there is a probably misunderstanding :))

As I want to live in a beautifull house, I'm not necessarily looking for advices to build the house and get it finished in 5 years. I'm just looking about the person who knows how to build it and can tell me how it is not going to collapse every time I close the door to go in the garden!...
Translating this to my project... AS I ALREADY EXPLAINED IN MY PREVIOUS POST... I just baught a watch in China with a poor APP in chineese. So, I'm just looking a way to use it here in Europe. NOTHING MORE... NOTHING LESS :slight_smile:

I'm afraid we can't be all dev or get the right time to be educated on computing tools. We are also living in real live...

If someone has a solution with nodered, I take it! Thanks...


#14

You say you just want a way of using the watch and would like someone to tell you how. The problem is that (it appears) no-one here has already done that so we can't provide a canned solution. Without spending a significant amount of time trying to understand the protocol there is not much we can do.
However I am not clear about the flow by eschava that you posted. Does that implement the protocol that you are interested in? If so then the solution is first to understand that and then use it for whatever you need to do. People here will certainly help if you find you can't understand something or, having done that, need help to make it do what you want.

You said you can't be a dev or have the time to become educated on the computing tools, but if the flow you posted cannot be simply adjusted to your needs then to do what you want may need someone who does have that knowledge and it is not a 5 minute operation, so to find someone who is willing to spend a number of hours looking at your problem may well be difficult.
To return to your analogy, to design a house that will not fall down requires knowledge of the strength of materials, what size bolts to use, what type of concrete etc. If you want a house designed you have no option but to pay an architect or educate yourself sufficiently to do it yourself.

Also, as I said previously I still can't import the original flow of yours that you posted so I still have not idea what it does. You have got the ticks right but the content is not right. Try it yourself.
I have managed to import the other flow, and if it is implementing the same protocol as yours (or very similar) then it could be a good starting point.

[Edit] I see what is wrong with the flow you posted, you are missing a [ off the front. Having added that I can import it. I am not sure what you are trying to do though.


#15

Hi Colin.
I'm someone logical with computing skills but not in Node-Red, at all :slight_smile:
Even with variable parameters, I did suppose it was just a code to read/extract, to split in Node-Red and re-use the datas... My reasoning seems to be the wrong.

Unfortunatly, in his example, Eschava did not use this protocol, but he modeled his protocol for his own watch. My intention was to give helpers a good example to parse the watch datas and to display the result in a web page. The input mecanism seems to be OK except the way to split. Of course, without his watch you can't get any result... (except with the retro-engineering I did. I replaced his listened port (TCP:8002) injecting adapted messages and simulated input...).

But my real problem is much simpler... Let me (try to) explain :slight_smile:

WATCH login => NODE-RED SERVER address:port
AAA123456* locahost:55555

So, It is a bidirectional discussion between WATCH and NODE-RED SERVER.
Just before accepting the dicussion, NODE-RED SERVER has to find a way to look somewhere (a DB?) to verify if 123456 is authorized or not. If YES, NODE-RED SERVER will accept the rest of the discussion, if NOT, NODE-RED SERVER will have reject the authentication. As you saw, NODE-RED SERVER needs to read/extract 123456 as there is no comma in the string, no separations, nothing. To identify the incoming 1st message : AAA means LOGIN, the total length of this string which is always the same (10... here), * is for any message.

If YES, NODE-RED SERVER has to setup the watch by sending back a message (string) on the same port as : BBB,201902019171523,2*
Where BBB is the code for the request Login (AAA), 201902019171523 is YearMonthDayHourMinuteSecond, 2 is the UTC time for NODE-RED SERVER. Here you can see there is a comma. But the problem is to code YearMonthDayHourMinuteSecond and UTC time for NODE-RED SERVER in the answer...

NODE-RED SERVER address:port => WATCH
locahost:55555 => BBB,201902019171523,2*

I'm receiving/sending some messages like this... but the others are always with , or . or | or &...

I think I won't get any other problems for the other steps in Node-Red. My problem is for the LOGIN process. I'm going to use node-red grafana plugin to export and visualize the datas as charts in Grafana.

If you get any solution to manage LOGIN, please tell me. See u.


#16

OK, now we have a defined problem that we can help to solve. You want node-red to simulate the server the watch is expecting. Have you got to the stage where node-red is receiving the login request?


#17

Ya, sure! But nothing else more what you saw in my last post.Just receiving a login string as AAA123456*. I already modeled this in my 1st post... and mostly of the messages I should receive. This messages are just coming in my TCP buffer:8XXXX


#18

For a http end point I think you want an HTTP In node and an HTTP Out node which will send back the response. All I saw in your flow was Inject nodes.
Assuming you have got the message in then I would first use a Switch node to route the input based on the message code (AAA for login) then you can extract the id with a Change node. See below. You can extend the switch to route other message types as required.
Then you need to decide how to store the valid ids. You could use an sqlite db or just global context variables for example. How many will there be?

[{"id":"c433dc.70792428","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"AAA123456*","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":99.5,"y":953,"wires":[["2b4a267e.b2f95a"]]},{"id":"2b4a267e.b2f95a","type":"switch","z":"514a90a5.c7bae8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^AAA","vt":"str","case":false},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":248.5,"y":966,"wires":[["9ab4a9c.d528058"],["48354d8a.2ae5f4"]]},{"id":"f431afce.a22d78","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":584.5,"y":941,"wires":[]},{"id":"48354d8a.2ae5f4","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":405.5,"y":1065,"wires":[]},{"id":"28a7769d.f935fa","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"XYZ123456*","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1012,"wires":[["2b4a267e.b2f95a"]]},{"id":"9ab4a9c.d528058","type":"change","z":"514a90a5.c7bae8","name":"Extract id","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.$substring(3,6)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":392.5,"y":940,"wires":[["f431afce.a22d78"]]},{"id":"d894b8ed.265228","type":"comment","z":"514a90a5.c7bae8","name":"Login","info":"","x":371.5,"y":908,"wires":[]}]

#19

Thanks Colin. This is a very good start now!

Is it possible to treat the extraction id substring, only with positions in AAA123456* and define the code is always between the 4th character and the 9th character ???

Below, I've turned on the watch and posted an export with the real datas...


#20

I don't know how to write the right code for the answer including CodeAnswer,YearMonthDayHourMinutesSeconds...

Nothing I can identify at https://www.w3schools.com/jsref/jsref_obj_date.asp