How to use websockets to send a reply back to client

So in my fun MQTT project I thought - lets try seeing if I can set it up to use websockets (just on LAN)

So, I created this little flow

[{"id":"99a9e9a5e664458a","type":"websocket out","z":"f7546f055375d300","name":"","server":"5ffaa82e38835477","client":"","x":1150,"y":600,"wires":[]},{"id":"c9a58f87db1d1413","type":"change","z":"f7546f055375d300","name":"set CONNACK","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\"0b00100000\",2,0,0]","tot":"bin"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":560,"wires":[["f9ae1ff880e022d1","99a9e9a5e664458a"]]},{"id":"3f40582d7a5603c2","type":"switch","z":"f7546f055375d300","name":"Test packet type","property":"payload.0","propertyType":"msg","rules":[{"t":"eq","v":"16","vt":"num"},{"t":"eq","v":"0xC0","vt":"num"},{"t":"gte","v":"0b00110000","vt":"num"},{"t":"eq","v":"0x82","vt":"num"},{"t":"eq","v":"0b10100010","vt":"num"},{"t":"eq","v":"0b11100000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":7,"x":675,"y":580,"wires":[["c9a58f87db1d1413"],[],[],[],[],[],[]],"l":false},{"id":"f9ae1ff880e022d1","type":"debug","z":"f7546f055375d300","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":970,"y":640,"wires":[]},{"id":"2251a27865d0e996","type":"join","z":"f7546f055375d300","name":"","mode":"custom","build":"buffer","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"bin","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":600,"wires":[["3f40582d7a5603c2","4ac41d3fa7382b13"]]},{"id":"4ac41d3fa7382b13","type":"junction","z":"f7546f055375d300","x":660,"y":640,"wires":[["f9ae1ff880e022d1"]]},{"id":"76eb165d46f3715b","type":"websocket in","z":"f7546f055375d300","name":"","server":"5ffaa82e38835477","client":"","x":440,"y":600,"wires":[["2251a27865d0e996"]]},{"id":"5ffaa82e38835477","type":"websocket-listener","path":"/ws/example","wholemsg":"true"}]

And it receives a connection message (but in two parts - hence need for join) and using my same switch that I used for TCP connections - I check the packet and then send an acknowledgement

But my client doesn't actually connect so I wondering if I've setup the websocket out node properly
image

The TCP out node has a reply mode but the websocket one seems to lack this

[edit] note - it may be an issue with my client but I just need to know whether I#ve setup NR correctly

I think I've got my answer - the out node show automagically send the response back to the connecting client

Will need to diagnose further why the CONNACK msg doesn't seem to being received

It was my fault - for some reason I'd selected entire message

image

Now works fine :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.