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 MYSController

    What 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_o

    The 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.

    ethernetGateway.png

    Screenshot_2016-01-14_09-55-07.png

    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"]]}]
    


  • 👍


Log in to reply
 

Suggested Topics

  • 9
  • 2
  • 2
  • 6
  • 5
  • 9

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts