"Sketch Name" (I_SKETCH_NAME) Handler



  • 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":[]}]
    


  • 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":[]}]
    

 

271
Online

8.3k
Users

9.1k
Topics

96.8k
Posts