Ambitions exercise I must say - I love it!
I won't attempt at trying to understand the MQTT protocol itself (I barely use it)
But...
As a TCP server, the TCP IN Node should be Listen On
and I would output it as a Stream OfBuffer payloads - this is important as some MQTT protocal packets may not be printable ASCII.
As for the TCP Out node - this should be Reply to TCP
But this will need some careful design work.
The TCP IN Node will include a _session object in all output - and the TCP Out node will use that, in order to know what connected client the reply should go to.
So if an MQTT Client expects a reply to a command the _session that will be included can be left untouched.
But if an MQTT Client sends a command, and by design the protocol requires the result be sent to all clients you need to delete _session - so the TCP Out will send to all.
But at the same time a command may only be destined for specifc client, and not necessarily, by the Client that sent the command - therefore you need to replace _session with the one that belongs to the target client.
You can obtain _session for each connected client, using the status node on the connect event, as that will include the session data msg.status._session
MQTT out node says connected to my DIY broker (All it does at moment is send a [32,2,0,0] CONNACK packet but at least the MQTT out node thinks its connected to a real broker
Having spent all weekend trying out using JSONata and contrib nodes to parse and extract data from messages, I've decided life is too short and I'm going to have to write some proper code
Of course, by proper code, I mean use the Blockly node
I'm sure you'd be able to come up with something but that would negate my goal of this being a fun exercise for me.
Your help in the other thread at least showed me that JSONata has possibilities of parsing it but I just struggle with using it beyond simple stuff
But, if you want some fun yourself consider a buffer
[130,9,220,88,0,4,116,101,115,116,2]
arriving at a change node - the variable text "test" always starts at byte 6, the length (16bit be encoded) is in bytes 4 and 5
So we need to extract the length and then extract the text string
I am not into reinventing the wheel, so best to use a language best suited. Blockly may do it if you can slice and spread the buffer and convert sting.fromCharCode(). JS in a function may be simpler. I know you have an aversion to function nodes, so good luck with Blockly
untested, written on phone by the beach, while listening to manic street preachers
In a future version of buffer parser I intend on letting users chose msg.xyz for the start/length/type etc. to do that currently is rather complex (need to send full specification to buffer parser as an object)
Your probably want to use .toString('binary') if you don't want to let utf-8 mess thing up... but then again you may not, depending on how you encoded it in the first place... mqtt payloads are just bytes so could be encoded strings or not.
@cymplecy I know that you started all of this as a fun project. But I am very interested too.
Also, if you search for MQTT in the Manage Pallet there are a number of nodes that have been created. Some of them parse the MQTT messages. You can probably find some methods to use.
@cymplecy are you planing on publishing your work? This sounds super interesting for lazy people like me who don't want to setup mosquito (or some other mqtt broker) but still want to have multiple instances of Node-RED communicating with one another.