Flow to turn SerialGateway with MQTT-FLOW to EthernetGateway
-
Whew. This is a hard one, and not completely debugged. But as of right now, I can receive and send data through MYSController!
You will need:
http://forum.mysensors.org/topic/2802/flow-to-turn-serialgateway-into-mqtt-serialgateway
mosquitto MQTT broker (server)
node-red-contrib-mysensors
download of MYSControllerWhat you get:
Serial communication (duh!)
MQTT communication
TCP server that MYSController speaks ------ WOOT
~and you can connect as many clients to this TCP server as you want O_oThe current topology is that I'm using a SerialGateway. All data to and from this goes into a Mosquitto MQTT broker. From then on, I only work with the broker, and not serial ports.
This flow is the same: this should work with any MQTT implementation. Do note, my root topic is named MySensors/ . If yours is different, you will have to find and replace in my code.
And yes, MYSController works well on WINE
KNOWN BUG: Because of the way Node-Red tracks connections, you MUST send a packet from MYScontroller after connecting in order to capture the session. From then on, everything will work. If you do not do this, then you will not be able to receive any data in MYSController.
[{"id":"72a5a797.020098","type":"mqtt-broker","z":"b2cff5f2.9cc8b","broker":"localhost","port":"8883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"5d726ee1.43674","type":"mqtt-broker","z":"316a4c44.7a9114","broker":"localhost","port":"8883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"e7324836.248338","type":"mqtt in","z":"316a4c44.7a9114","name":"","topic":"MySensors/#","broker":"5d726ee1.43674","x":80,"y":216,"wires":[["a009a85d.aa4b58"]]},{"id":"a009a85d.aa4b58","type":"function","z":"316a4c44.7a9114","name":"MQTT to MYS Serial","func":"var splitTopic= msg.topic.split(\"\\/\");\n\n// splitTopic[0] is the MySensors/ preamble. #1 is NODE_ID and on up. \nmsg.payload = splitTopic[1] + \";\" + splitTopic[2] + \";\" + splitTopic[3] + \";\" + splitTopic[4] + \";\" + splitTopic[5] + \";\" + msg.payload ;\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":216,"wires":[["87d95f68.d5bf28"]]},{"id":"61cc3040.0a2ce","type":"mqtt out","z":"316a4c44.7a9114","name":"To MQTT","topic":"","qos":"","retain":"","broker":"72a5a797.020098","x":700,"y":148,"wires":[]},{"id":"57b96ecb.e396f","type":"mysdecenc","z":"316a4c44.7a9114","name":"","x":340,"y":148,"wires":[["2d0808fa.b5f988"]]},{"id":"2d0808fa.b5f988","type":"function","z":"316a4c44.7a9114","name":"Formats MQTT topic","func":"msg.topic = \"MySensors\" + \"/\" + msg.nodeId + \"/\" + msg.childSensorId + \"/\" + msg.messageType + \"/\" + msg.ack + \"/\" + msg.subType;\nreturn msg;","outputs":1,"noerr":0,"x":525,"y":148,"wires":[["61cc3040.0a2ce"]]},{"id":"172ecad5.7d5e7d","type":"debug","z":"316a4c44.7a9114","name":"","active":true,"console":"false","complete":"true","x":568,"y":287,"wires":[]},{"id":"e374dc2e.759fe8","type":"tcp out","z":"316a4c44.7a9114","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":560,"y":218,"wires":[]},{"id":"d8774c60.3e3718","type":"tcp in","z":"316a4c44.7a9114","name":"","server":"server","host":"","port":"5003","datamode":"stream","datatype":"utf8","newline":"\\n","topic":"","base64":false,"x":76,"y":146,"wires":[["2cdfadb8.70f112","73ae599e.322238"]]},{"id":"2cdfadb8.70f112","type":"debug","z":"316a4c44.7a9114","name":"","active":true,"console":"false","complete":"true","x":218,"y":89,"wires":[]},{"id":"73ae599e.322238","type":"function","z":"316a4c44.7a9114","name":"","func":"context.global.tcpsess = context.global.tcpsess || msg._session;\nreturn msg;","outputs":1,"noerr":0,"x":204,"y":147,"wires":[["57b96ecb.e396f"]]},{"id":"87d95f68.d5bf28","type":"function","z":"316a4c44.7a9114","name":"","func":"msg._session = context.global.tcpsess;\nreturn msg;","outputs":1,"noerr":0,"x":432,"y":217,"wires":[["e374dc2e.759fe8","172ecad5.7d5e7d"]]}]
-
Suggested Topics
-
Join the Project Contest 2014 - ENDED
Announcements • 8 Apr 2014, 08:03 • hek 13 May 2014, 21:48 -
Thanks for node-red-contrib-mysensors and a question regarding collections or arrays
Node-RED • 25 Oct 2020, 07:44 • Joost 25 Oct 2020, 08:36 -
[Solved] Beginner receive() question
Node-RED • 14 Mar 2021, 15:10 • Alberto77 14 Mar 2021, 20:48 -
multiple gateways on lan
Node-RED • 8 Jun 2019, 07:57 • sotiriszegiannis 10 Jun 2019, 20:20 -
node-red-contrib-mysensors release thread
Node-RED • 24 Apr 2018, 20:06 • tbowmo 4 May 2021, 10:25 -
NodeID assignment not working? MY_INCLUSION_MODE_FEATURE enabled
Node-RED • 6 Apr 2020, 09:37 • bebr 6 Apr 2020, 11:35