Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
crankyC

cranky

@cranky
About
Posts
41
Topics
10
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • FastLED / Neopixel (ws2811) Node, From Arduino code to Web page (with API)
    crankyC cranky

    I can change it back to a 1.5.* code. It'll be a day or so, as I'm busy right now (homework, etc).

    Node-RED

  • ioBroker = Home automation/Node ALL in ONE/ for noobs https +Let's encrypt/MQTT/Node Red/
    crankyC cranky

    I'm honestly torn on making Windows/Linux programs. I certainly get the idea why you would want something like that, but I'd much rather have an HTML5 website that does that instead of an x86 program...

    Web browsers are on everything, whereas the idea of fat binaries is still a very rare one.

    My underlying works revolve in making web APIs, so I can create websites and scripts that can do "stuff" without me even hitting buttons.

    For example, I'd like to have an IoT doorbell. Simple. When it triggers, a flow interrogates if there is anybody in the house. If yes, ring the doorbell. Also, when doorbell is triggered, take a photo from the door and run it through a facial recognizer and send to me.

    ... And that's just a doorbell.

    My Project

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    Ok, as you saw, I got the MQTT<-->TCP connector done , and that's live :)

    Now, I have my GH up and populated. It's pretty sparse with documentation right now, but that will change.
    https://github.com/jwcrawley/node-red-mysensors-flows/

    What's cool is I can use a the "Watch" NR node and watch for updates in my working directory and auto-push :-D

    All you need is your SSH keys set up.

    Then you watch for /.git/COMMIT_EDITMSG and when a change hits that, do a

    git add (repo directory)
    

    Then read the /.git/COMMIT_EDITMSG into msg.payload and then send it to an EXEC node as

    git commit -m {{payload}}
    

    And then

    git push origin master
    

    ..... And there you have it: automated local to Github.

    Node-RED

  • Windows GUI/Controller for MySensors
    crankyC cranky

    @tekka You might not have to. I've been working on Node-Red as a controller and more.

    With my kit, you need Node-Red, node-red-contrib-mysensors , Mosquitto, and some of my flows which I have available ( http://forum.mysensors.org/topic/2802/flow-to-turn-serialgateway-into-mqtt-serialgateway ).

    And it makes this:
    http://forum.mysensors.org/topic/2815/flow-to-turn-serialgateway-with-mqtt-flow-to-ethernetgateway

    The only flaw is that when you first connect MYSController, you need to send a junk topic so that MYSController can receive data. It's a bug/peculiarity with Node-Red, but honestly not a big deal. I'm also working on how to fix even that.

    Controllers myscontroller mysbootloader

  • "Sketch Time" (I_TIME) Handler
    crankyC cranky

    Ah cool :) So yes, make the user do it. I like the sound of that.

    Time stinks. Only thing I can say about that is, "Never again."

    Node-RED

  • "Sketch Time" (I_TIME) Handler
    crankyC cranky

    Really? I'd rather handle absolute time of "Seconds since the Epoch". If you use that, there's no reason or need to mess with DST, time zones, or anything else. It's only when you convert "Seconds Since Epoch"->"String of Current time/date" do you get into having to deal with TZdata and all that garbage.

    Then, on the local device, the user can bake in the Arduino sketch the timezone they are using. Of course, then they have to deal with the horrors of DST and timezones... that is if they want to.

    I log most of my data in seconds(or ms) since epoch. All my logs are then completely synchronized, as much as an NTP client can manage.

    Sincerely,
    Cranky

    Node-RED

  • Flow to turn SerialGateway with MQTT-FLOW to EthernetGateway
    crankyC cranky

    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 :-D

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

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    Unfortunately, I do not. Until when I just looked at the source "MyGatewayTransportEthernet.cpp", I mistakenly assumed that it too published to an MQTT broker.

    It doesn't look too terribly hard to do; with UDP being easier. But my main caveat here is that I don't have an SPI ethernet port for an arduino. That means I wouldn't be able to test my code.

    If there was a packet documentation for TCP and UDP, I could write code for the reference. Again, past library and serial documentation, there is none I can refer to.

    Of if some hardware fairy would be willing to send me a compatible SPI ethernet port, I could do it :-D


    documentation

    MY_PORT = (default) 5003
    (TCP/UDP) choice
    (server mode / client mode) choice. IP dest. reqd for being client
    buffer receiving: 100 B
    buffer sending: 120 B

    Node-RED

  • "Sketch Config" (I_CONFIG) Handler
    crankyC cranky

    Not yet, but that was my goal tomorrow.

    My GH account is https://github.com/jwcrawley

    It'll be obvious when I add in the repo :) I'll also mention it here.

    Sincerely,
    Cranky

    Node-RED

  • "Sketch Config" (I_CONFIG) Handler
    crankyC cranky

    This flow takes care of the challenge/response for when a sensor asks what config to use (Metric or imperial).

    By default, the code returns M for metric. I don't believe Imperial is used anywhere, but it can be changed to I... if you support it in your code. (Honestly, no clue, but some sketches do make use of the call getConfig() .)

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"57ad0c01.895c9c","type":"mqtt in","z":"63842e72.893f78","name":"Sensor Requests Config","topic":"MySensors/+/255/3/0/6","broker":"8e3e8f02.7fd0c","x":105,"y":993,"wires":[["cd60b38.ef7405"]]},{"id":"86a8016b.bd47a","type":"mqtt out","z":"63842e72.893f78","name":"","topic":"","qos":"","retain":"","broker":"8e3e8f02.7fd0c","x":672,"y":993,"wires":[]},{"id":"65a6cc53.392ccc","type":"function","z":"63842e72.893f78","name":"Metric/Imperial definition","func":"var config = \"M\" ; //M for metric, and I for imperial\n\nmsg.payload = config + \"\\n\";\nreturn msg;","outputs":1,"noerr":0,"x":488,"y":993,"wires":[["86a8016b.bd47a","165c11cd.40adbe"]]},{"id":"165c11cd.40adbe","type":"debug","z":"63842e72.893f78","name":"","active":true,"console":"false","complete":"false","x":692,"y":952,"wires":[]},{"id":"cd60b38.ef7405","type":"delay","z":"63842e72.893f78","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":295,"y":993,"wires":[["65a6cc53.392ccc"]]},{"id":"9687065f.28c08","type":"comment","z":"63842e72.893f78","name":"I_CONFIG handler ([0-255];255;3;0;6;[M or I])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;6;(null),\n\nThe cntroller returns a M for metric or I for imperial. \nTo my understanding, imperial measurement reportings aren't used.\n\n\nA rate limiter was required as to keep NR and the sensor from a spam-loop","x":298,"y":1030,"wires":[]}]```
    Node-RED

  • "Sketch Time" (I_TIME) Handler
    crankyC cranky

    This flow takes care of the I_TIME call made to the gateway.

    The confusing part about this Internal call is: do we return UTC, or local time? It would be trivial to have a sensor pass as

    [id];255;3;0;1;(timezone)

    rather than

    [id];255;3;0;1;\n

    so that Time local to where the sensor was placed could be recorded. The only caveat is that DST would mess it up... However, since the Arduino sketch "Time Aware Sensor" polls the gateway every hour for time, at most your logs/data will be off by at most 1 hour. This can easily be changed to the tolerance your need desires.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"71e13b71.966fa4","type":"mqtt in","z":"63842e72.893f78","name":"Sensor Requests Time ","topic":"MySensors/+/255/3/0/1","broker":"8e3e8f02.7fd0c","x":102,"y":852,"wires":[["24b5e719.a8a1d8"]]},{"id":"92a5ad9d.a8b328","type":"function","z":"63842e72.893f78","name":"seconds since epoch","func":"var timezone_offset = -5  // As hours against UTC\n\nmsg.payload = Math.floor( Date.now() / 1000 ); // seconds since jan 1 1970\nmsg.payload = msg.payload + ( timezone_offset * 3600);\nreturn msg;","outputs":1,"noerr":0,"x":465,"y":851,"wires":[["b7cc49b4.1520c8","4686a23a.28493c"]]},{"id":"b7cc49b4.1520c8","type":"mqtt out","z":"63842e72.893f78","name":"Time to Topic","topic":"","qos":"","retain":"","broker":"8e3e8f02.7fd0c","x":657,"y":850,"wires":[]},{"id":"e059f1d.9421f1","type":"comment","z":"63842e72.893f78","name":"I_TIME handler ([0-255];255;3;0;1;[sec since epoch])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;1;(null),\nit returns to the same topic the amount of seconds since Jan 1 1970 (also called Epoch)\n\nA rate limiter was required as to keep NR and the sensor from a spam-loop","x":301,"y":899,"wires":[]},{"id":"4686a23a.28493c","type":"debug","z":"63842e72.893f78","name":"","active":false,"console":"false","complete":"false","x":642,"y":817,"wires":[]},{"id":"24b5e719.a8a1d8","type":"delay","z":"63842e72.893f78","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":284,"y":852,"wires":[["92a5ad9d.a8b328"]]},{"id":"46b988b9.969a88","type":"comment","z":"63842e72.893f78","name":"Change timezone here","info":"","x":450,"y":818,"wires":[]}]
    
    Node-RED

  • "Sketch Version" (I_SKETCH_VERSION) Handler
    crankyC cranky

    I extended the /root/leases.file to also include a 3rd field for version. Now you can update nodes and see the version change as you update (or view unupdated ones).

    It is functionally very similar to that of I_SKETCH_NAME handler.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"21742d0e.25817a","type":"mqtt in","z":"63842e72.893f78","name":"Rename sensor in file","topic":"MySensors/+/255/3/0/12","broker":"8e3e8f02.7fd0c","x":106,"y":630,"wires":[["8a1e6bb3.db726"]]},{"id":"8a1e6bb3.db726","type":"function","z":"63842e72.893f78","name":"message to edit","func":"var splitTopic= msg.topic.split(\"\\/\");\nmsg.payload = msg.payload.replace(\"\\n\", \"\");\nmsg.edit = {col1:splitTopic[1] , col3:msg.payload}; \n// msg.edit carries over the next 2 nodes to \"find edit and replace\" function node\nreturn msg;","outputs":1,"noerr":0,"x":352,"y":629,"wires":[["cb5f1a37.6ab65"]]},{"id":"cb5f1a37.6ab65","type":"file in","z":"63842e72.893f78","name":"","filename":"/root/leases.file","format":"utf8","x":528,"y":630,"wires":[["77038207.b61144"]]},{"id":"77038207.b61144","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"col1,col2,col3","x":113,"y":701,"wires":[["f2858e20.0e9b18"]]},{"id":"f2858e20.0e9b18","type":"function","z":"63842e72.893f78","name":"find edit and replace","func":"for(var i = 0; i < msg.payload.length; i++){\n    if( msg.edit.col1 == msg.payload[i].col1 ){\n        msg.payload[i].col3 = msg.edit.col3;\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":282,"y":701,"wires":[["2ef32bcf.fefb74"]]},{"id":"321725f3.9ad162","type":"file","z":"63842e72.893f78","name":"","filename":"/root/leases.file","appendNewline":true,"createDir":false,"overwriteFile":"true","x":644,"y":702,"wires":[]},{"id":"6404769b.fdaff8","type":"debug","z":"63842e72.893f78","name":"","active":true,"console":"false","complete":"false","x":634,"y":741,"wires":[]},{"id":"2ef32bcf.fefb74","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"col1,col2,col3","x":449,"y":701,"wires":[["321725f3.9ad162","6404769b.fdaff8"]]},{"id":"aaea7f9c.a0adf","type":"comment","z":"63842e72.893f78","name":"I_SKETCH_VERSION handler ([0-255];255;3;0;12;[name])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;11;[name from presentation],\nit modifies field 2 for that appropriate sensor. \n\nThe resulting modification is then saved.","x":304,"y":743,"wires":[]}]
    
    Node-RED

  • "Sketch Name" (I_SKETCH_NAME) Handler
    crankyC cranky

    Debugged, changelog 13 jan2016.

    Added 3rd field, for version. Fixed \n being passed and messing up CSV file.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"2b18ee58.b63042","type":"mqtt in","z":"63842e72.893f78","name":"Rename sensor in file","topic":"MySensors/+/255/3/0/11","broker":"8e3e8f02.7fd0c","x":147,"y":347,"wires":[["34a4252.48ed9da"]]},{"id":"34a4252.48ed9da","type":"function","z":"63842e72.893f78","name":"message to edit","func":"var splitTopic= msg.topic.split(\"\\/\");\nmsg.edit = {col1:splitTopic[1] , col2:msg.payload}; \n// msg.edit carries over the next 2 nodes to \"find edit and replace\" function node\nreturn msg;","outputs":1,"noerr":0,"x":349,"y":346,"wires":[["2032129a.b17cfe"]]},{"id":"2032129a.b17cfe","type":"file in","z":"63842e72.893f78","name":"","filename":"/root/leases.file","format":"utf8","x":525,"y":347,"wires":[["2c70d9c7.e8d2ee"]]},{"id":"2c70d9c7.e8d2ee","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"col1,col2,col3","x":110,"y":418,"wires":[["f17d2f12.1254c8"]]},{"id":"f17d2f12.1254c8","type":"function","z":"63842e72.893f78","name":"find edit and replace","func":"for(var i = 0; i < msg.payload.length; i++){\n    if( msg.payload[i].col1 == msg.edit.col1 ){\n        msg.payload[i].col2 = msg.edit.col2;\n        return msg;\n    }\n    if( msg.payload[i].col1 > msg.edit.col1 ){\n        msg.payload.splice(i,0, {col1: (i-1), col2: msg.edit.col2, col3: \"\"}) ;\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":279,"y":418,"wires":[["c2871f53.c8caa"]]},{"id":"55feab8a.9176ac","type":"file","z":"63842e72.893f78","name":"","filename":"/root/leases.file","appendNewline":true,"createDir":false,"overwriteFile":"true","x":641,"y":419,"wires":[]},{"id":"7263dd71.ca4b94","type":"debug","z":"63842e72.893f78","name":"","active":true,"console":"false","complete":"false","x":631,"y":458,"wires":[]},{"id":"c2871f53.c8caa","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"col1,col2,col3","x":446,"y":418,"wires":[["55feab8a.9176ac","7263dd71.ca4b94"]]},{"id":"852f49a7.0d18c","type":"comment","z":"63842e72.893f78","name":"I_SKETCH_NAME handler ([0-255];255;3;0;11;[name])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;11;[name from presentation],\nit modifies field 2 for that appropriate sensor. \n\nThe resulting modification is then saved.","x":310,"y":456,"wires":[]}]
    
    Node-RED

  • Can not see my Humidity sensor
    crankyC cranky

    If you open up a serial console with the SerialGateway, you can respond with the following

    255;255;3;0;4;[ID you want it to have]

    And then the ID will be copied into EEprom on the sensor and then work as that ID number you assign it.

    Domoticz

  • "Sketch Name" (I_SKETCH_NAME) Handler
    crankyC cranky

    This is to be used in conjunction with:

    http://forum.mysensors.org/topic/2803/dhcp-i_id_request-handler
    http://forum.mysensors.org/topic/2802/flow-to-turn-serialgateway-into-mqtt-serialgateway
    ... As well as have a file "/root/leases.file" be readable/writable from your node-red user.

    This flow relabels the sensors in your sensor lease file to the correct name you provided in the Presentation section of your arduino code. The file, /root/leases.file is a simple CSV file. column 1 is ID and column 2 is sensor_name

    I usually run the "DHCP" and this script on the same flow sheet.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"2b18ee58.b63042","type":"mqtt in","z":"63842e72.893f78","name":"Rename sensor in file","topic":"MySensors/+/255/3/0/11","broker":"8e3e8f02.7fd0c","x":147,"y":347,"wires":[["34a4252.48ed9da"]]},{"id":"34a4252.48ed9da","type":"function","z":"63842e72.893f78","name":"message to edit","func":"var splitTopic= msg.topic.split(\"\\/\");\nmsg.edit = {col1:splitTopic[1] , col2:msg.payload}; \n// msg.edit carries over the next 2 nodes to \"find edit and replace\" function node\nreturn msg;","outputs":1,"noerr":0,"x":349,"y":346,"wires":[["2032129a.b17cfe"]]},{"id":"2032129a.b17cfe","type":"file in","z":"63842e72.893f78","name":"","filename":"/root/leases.file","format":"utf8","x":525,"y":347,"wires":[["2c70d9c7.e8d2ee"]]},{"id":"2c70d9c7.e8d2ee","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"","x":110,"y":418,"wires":[["f17d2f12.1254c8"]]},{"id":"f17d2f12.1254c8","type":"function","z":"63842e72.893f78","name":"find edit and replace","func":"for(var i = 0; i < msg.payload.length; i++){\n    if( (msg.edit.col1 == msg.payload[i].col1) && (msg.payload[i].col2 == \"temporary\") ){\n        msg.payload[i].col2 = msg.edit.col2;\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":279,"y":418,"wires":[["c2871f53.c8caa"]]},{"id":"55feab8a.9176ac","type":"file","z":"63842e72.893f78","name":"","filename":"/root/leases.file","appendNewline":true,"createDir":false,"overwriteFile":"true","x":641,"y":419,"wires":[]},{"id":"7263dd71.ca4b94","type":"debug","z":"63842e72.893f78","name":"","active":true,"console":"false","complete":"false","x":631,"y":458,"wires":[]},{"id":"c2871f53.c8caa","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"col1,col2","x":446,"y":418,"wires":[["55feab8a.9176ac","7263dd71.ca4b94"]]},{"id":"852f49a7.0d18c","type":"comment","z":"63842e72.893f78","name":"I_SKETCH_NAME handler ([0-255];255;3;0;11;[name])","info":"Whenever a sensor announces itself to the network as [any];255;3;0;11;[name from presentation],\nit modifies field 2 for that appropriate sensor. \n\nThe resulting modification is then saved.","x":369,"y":510,"wires":[]}]
    
    Node-RED

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    Gladly :) There's more coming out. I just provided the flow to handle "DHCP" sensors (or the ones that do REQ ID 255;255;3;0;3;\n)

    One step at a time....

    Node-RED

  • "DHCP" (I_ID_REQUEST) Handler
    crankyC cranky

    This code is to be used in conjunction of a set up MQTT broker (Mosquitto) and the prior flow listed in "Flow to turn SerialGateway into MQTT-SerialGateway"

    This watches all data coming in from topic MySensors/255/255/3/0/3/ and does a lookup in the DB for a new unused ID. Then it assigns the sensors the ID as well as updating the DB.

    There may be some bugs, as testing this code requires extra work.

    Essentially, in a location in EEprom lives the assigned ID number. So in order to test this, you need to:

    load ClearEEPROM sketch. open Serial console and wait till done.
    Then load a sketch that doesn't have the Node ID set (#define NODE_ID 1.6 and gw.begin(NULL, AUTO) in 1.5)
    Assigning happens once. If messed up, load clearEEPROM and do again

    BIG NOTE: You do need read/write access to file /root/leases.file from whatever user you are running in Node-Red. I chose /root/leases.file because I wanted it easy to find and of indication that it is an important file. You can change it, but make sure to catch all the file nodes that reference to it.

    [{"id":"8e3e8f02.7fd0c","type":"mqtt-broker","z":"63842e72.893f78","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":"778435ae.0d9c4c","type":"mqtt in","z":"63842e72.893f78","name":"Incoming DHCP request","topic":"MySensors/255/255/3/+/3","broker":"8e3e8f02.7fd0c","x":112.5,"y":136,"wires":[["c77f47f6.5dcc1"]]},{"id":"c77f47f6.5dcc1","type":"file in","z":"63842e72.893f78","name":"","filename":"/root/leases.file","format":"utf8","x":307,"y":137,"wires":[["a09e2794.97bca8"]]},{"id":"a09e2794.97bca8","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"","x":450,"y":136,"wires":[["f33caa99.b57308"]]},{"id":"f33caa99.b57308","type":"function","z":"63842e72.893f78","name":"Saves and emits assigned ID","func":"var lease = -1 ;\nvar splitString;\n\nfor (var i=0; (i<msg.payload.length) && (lease == -1);i++){\n    if(msg.payload[i].col1 != i){\n        msg.payload.splice(i,0, {col1: i, col2:\"temporary\"});\n        lease = i ;\n    }\n}\n\nif (lease == -1){ // means there's no holes in the lease file\n    lease = msg.payload.length ;\n    msg.payload.push( {col1: lease, col2:\"temporary\"} ); // returns next number in order\n}\n\nvar msg2 = { payload:lease};\n\nreturn [msg, msg2];","outputs":"2","noerr":0,"x":640,"y":136,"wires":[["15c23ce9.f74c03","ccd034fb.54b728"],["50521f88.55082","ccd034fb.54b728"]]},{"id":"15c23ce9.f74c03","type":"csv","z":"63842e72.893f78","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"col1,col2","x":663,"y":96,"wires":[["2092d4a1.661c84"]]},{"id":"2092d4a1.661c84","type":"file","z":"63842e72.893f78","name":"","filename":"/root/leases.file","appendNewline":false,"createDir":false,"overwriteFile":"true","x":670,"y":55,"wires":[]},{"id":"50521f88.55082","type":"mqtt out","z":"63842e72.893f78","name":"","topic":"MySensors/255/255/3/0/4","qos":"","retain":"","broker":"8e3e8f02.7fd0c","x":636,"y":199,"wires":[]},{"id":"ccd034fb.54b728","type":"debug","z":"63842e72.893f78","name":"DHCP result","active":false,"console":"false","complete":"payload","x":865,"y":135,"wires":[]},{"id":"420b8cdd.3a696c","type":"comment","z":"63842e72.893f78","name":"I_ID_REQUEST handler (255;255;3;0;3 , 255;255;3;0;4;[ID])","info":"Beginning listens to messages of 255;255;3;0;3;\\n , which is broadcast request for ID\nLeases file is read, and interpreted as CSV. \nFunction block does 2 things:\n    1. Adds new sensor's ID to lease file\n    2. Sends back to MQTT the ID the device is granted to 255;255;3;0;4;[ID]\\n","x":272,"y":83,"wires":[]}]
    
    
    Node-RED

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    @barduino . How peculiar. I think it might be the way RasPi chose to include Node-red. It appears that you might need to do my above npm command with sudo... You shouldn't need to hand-create node_modules or node-red-contrib-mysensors. npm should have done that all for you, along with any potential dependencies. Adafruit's help goes into Pi-weirdness: https://learn.adafruit.com/raspberry-pi-hosting-node-red/installing-further-plugins

    But I hope the mysensors removal works well. Like I said, haven't tested it yet :P

    Good luck!
    Cranky

    Node-RED

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    Oh, it's that error :p

    Delete the sheet, and re-copy. It will show up then. That, btw, is an existing bug in NR.

    Node-RED

  • Flow to turn SerialGateway into MQTT-SerialGateway
    crankyC cranky

    if you do

    npm install node-red-contrib-mysensors
    

    It should work. If it doesn't, can you post the full text of the error please?

    Oh, also, I chopped out the requirements for node-red-contrib-mysensors. Now, you should only need Serial, Function, MQTT, and Debug. Try this. Beware, I didn't test it, as I don't have easy remote access to my Broker.

    [{"id":"938db5f1.fc32d","type":"mqtt-broker","z":"61b3db25.ac0dcc","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":"e8212410.a623d","type":"serial-port","z":"61b3db25.ac0dcc","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"142d3129.87f8a7","type":"debug","z":"61b3db25.ac0dcc","name":"Serial to MQTT debug","active":false,"console":"false","complete":"true","x":791,"y":214,"wires":[]},{"id":"3637dd4b.cb9c4a","type":"serial in","z":"61b3db25.ac0dcc","name":"","serial":"e8212410.a623d","x":255,"y":264,"wires":[["e3ff437d.acd2a"]]},{"id":"40b2ff18.06e41","type":"mqtt in","z":"61b3db25.ac0dcc","name":"","topic":"MySensors/#","broker":"938db5f1.fc32d","x":271.5,"y":324,"wires":[["f638c51f.95fb78"]]},{"id":"f638c51f.95fb78","type":"function","z":"61b3db25.ac0dcc","name":"convert topic to Serial protocol","func":"msg.topic = msg.topic.replace(\"MySensors\\/\", \"\"); // Gets rid of MySensors preamble\nfor (i=0;i<4;i++){\n    msg.topic = msg.topic.replace(\"\\/\", \";\");\n}\nmsg.payload = msg.topic + \";\" + msg.payload + \"\\n\";\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":324,"wires":[["4b33e37a.1bab14","51bc5462.90ca1c"]]},{"id":"4b33e37a.1bab14","type":"debug","z":"61b3db25.ac0dcc","name":"MQTT to Serial debug","active":false,"console":"false","complete":"true","x":756,"y":373,"wires":[]},{"id":"51bc5462.90ca1c","type":"serial out","z":"61b3db25.ac0dcc","name":"","serial":"e8212410.a623d","x":718,"y":323,"wires":[]},{"id":"e6240f60.af5c78","type":"mqtt out","z":"61b3db25.ac0dcc","name":"","topic":"To MQTT","qos":"","retain":"","broker":"938db5f1.fc32d","x":770,"y":264,"wires":[]},{"id":"e3ff437d.acd2a","type":"function","z":"61b3db25.ac0dcc","name":"Formats MQTT topic","func":"var sensor = msg.payload.split(\";\");\nmsg.topic = \"MySensors\" + \"/\" + sensor[0] + \"/\" + sensor[1] + \"/\" + sensor[2] + \"/\" + sensor[3] + \"/\" + sensor[4];\nmsg.payload = sensor[5];\nreturn msg;","outputs":1,"noerr":0,"x":498,"y":265,"wires":[["e6240f60.af5c78","142d3129.87f8a7"]]}]
    
    Node-RED
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular