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

In javascript in a function node you can use the substring method

You can use node-red-contrib-moment. Something like this

[{"id":"a9156097.d9e12","type":"moment","z":"514a90a5.c7bae8","name":"","topic":"","input":"nothing","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"[BBB,]YYYYMMDDHHmmss","locale":"en_GB","output":"payload","outputType":"msg","outTz":"ETC/GMT","x":328.5,"y":1280,"wires":[["48354d8a.2ae5f4"]]}]

Alternatively you could do it in a function node in javascript using new Date() and then the various access methods to get the components. Then convert to strings and concatenate.

That's a strange format, I wonder how it will deal with daylight saving time changes...

My suggested solution provides it in UTC, or at least that is what I intended, I can't actually test that easily as we are on UTC at the moment. Whether that is what the device actually wants I don't know. I suspect they are just using it instead of a GUID, so it doesn't actually matter.

whaouh!!! :star_struck:

It is like you take me as someone qualified on Node-Red.... Just use it, you can do this or you can do that .... but if you don't tell me how... this will be complicate :))) Your Date/Time formater seems to be adapted... but how can I implement it in the scene with the answer IWBP00...........................# ?

I don't know Node-Red :slight_smile:

Not sure what you mean by that, what exactly do you want to see?
Did you look at my suggestion and see what it produces (by feeding in a message and looking at the output with debug node, after installing node-red-contrib-moment obviously) then looking at the info panel for the moment node so that you can understand what mine does? Once you understand what mine does you may be able to work out how to change it to do what you want.

Yes I saw. Your solution is perfect... except I don't know how to include it with the answer...

You still haven't said exactly what you want the message to be

If you just need to change the text round the date string then you just need to change the format string in the moment node.

Hi Colin,
wonderfull ! Solved with your moment node !!

ONLY 3 REQUESTS / ANSWER TO SOLVE AND IT IS FINISHED!!! BUT THEY ARE THE MOST DIFFICULT... OF COURSE! :frowning:

ARE YOU STILL WITH ME FOR THE 3 LAST TO DECODE, PLEASE??

There isn't much point keeping posting the whole flow, please just ask specific questions that can be addressed. So tell us what the remaining issues are.

Right, I understand it is heavy... I erased the solved ones. Here, it is going to be harder : watch=>server / server =>watch

1/ Below are just the nodes concerned. I need to split the incoming message and to convert/decode as the notice explains (after the message below).

2/ I also need to send an answer to the watch as the notice said...
2 options: or the answer is *IWBP02# and I solved it
but when
the reply flag is 1, the server needs to respond: IWBP02F16D3357025E5753715C3A535753776D275953903100300037003900F753# which is the UNICODE encoded address to setup the address in the watch!!

An here I don't know how to do this!!

[{"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":139,"y":244.00000190734863,"wires":[["b13eed31.409e9"]]}]

IWAP02 INCOMING MESSAGES FROM THE WATCH to decode

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#

where IWAP02 = command
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 to the 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)

platform responds:

OUTGOING MESSAGES TO THE WATCH
platform replies:
IWBP02#

If the reply flag is 1, the server has to setup the address to the watch:
IWBP02F16D3357025E5753715C3A535753776D275953903100300037003900F753# UNICODE.

A couple of questions
Is that a fixed reply or is some of it variable?
When you say it is unicode I am not sure exactly what you mean. Can you give more detail? Perhaps show the byte sequence you expect for the start of the message.

If you really want to decode something like this, you need to set up something to monitor the traffic between the watch and the LIVE server. This will tell you exactly what happens and when. You can use a "proxy" service for this, there are plenty of tutorials on the internet.

Just watch out for the fact that, if the server operates in a Chinese language, any unicode text coming back may be in a double-byte format.

I think he has already done that. He isn't trying to decode that string, he is trying to build it to send back.

The strings are coming in alphanumeric, no HEX or Unicode. I just need to split, name and convert the incoming datas.

I thought you said you didn't know how to build the Unicode string. You didn't answer my questions

To split it I think the easiest way will be to use a function node. Have you done any programming? You are going to need to learn some javascript.
you can first split it at the commas then where appropriate split the elements at the | symbols, building a javascript object with the results. So something like (untested)

let answer = {}
let elements = msg.payload.split(",")  // this gives an array containing the bits
// elements[0] is IWAP02 so we can ignore that
answer.language = elements[1]
node.warn(`language is: ${answer.language}`)  // for testing display it in the debug pane
answer.flag = elements[2]
node.warn(`flag is: ${answer.flag}`)
answer.baseCount = elements[3]
// you can work out how to put the node.warn statements in yourself
answer.country = elements[4]
answer.operator = elements[5]
// now need to get the bases
let i;
answer.bases = []
for (i=6, i<6+answer.baseCount, i++) {
  let baseElements = elements[i].split("|")
  answer.push({lac: baseElements[0], cid: baseElements[1], dbm: baseElements[2]})
}
// the rest needs to go in here
msg.payload = answer
return msg

That should be a start for splitting it up. Get that going then see if you can handle the rest. No doubt there are syntax errors in what I have posted but it will be good practice fixing them.

Of course, I don't know! :slight_smile: 50% of what I built here is because you helped me Colin!!
I'm always using the same protocol to go forward :
I'm trying to build a solution with my knowledges. When I can't find a way, I'm asking here.
For this raison, I'm updating my posts till the state "solution".

Colin...
You give me the flight manual ... during the flight!!!! :smile:
You just told me to squawk Mode Charlie and to reduce my speed at 255, altitude 1200... also asked me to wilco and enter in stanby mode...

Of course, I have to deduct where is the airport without
landmarks neither a radar... in the dark :)))

No way to use this in my schema!!