有没有办法从节点红色转换为纯代码?

时间:2018-08-06 10:58:28

标签: javascript node-red

由于能够使用gui,我目前正在使用node-red来实现我的目标,但理想情况下,我想摆脱这一点,只希望拥有1个无缝系统,而不是在系统之间来回移动

我的当前流量如下。

[{"id":"c97e8fad.1ccfc","type":"change","z":"9b2b789d.df51e8","name":"strip the $","rules":[{"t":"change","p":"payload","pt":"msg","from":"$","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":280,"wires":[["843b2c33.a8bf4","2e80c1f.d012c3e"]]},{"id":"b4bb90cd.d114b","type":"function","z":"9b2b789d.df51e8","name":"test","func":"var raw = msg.payload;\nmsg.length = raw.length;\nmsg.raw = raw;\nvar data = {};\ndata.mac = raw.substring(5,17);\ndata.hostname = raw.substring(18,30);\ndata.minor = raw.slice(-8,-4);\nvar rssi = raw.substring(31,34);\n\n\nfunction calculateDistance(rssi) {\n  \n  var txPower = -69 //hard coded power value. Usually ranges between -59 to -65\n  \n  if (rssi === 0) {\n    return -1.0; \n  }\n\n  var ratio = rssi*1.0/txPower;\n  if (ratio < 1.0) {\n    return Math.pow(ratio,10);\n  }\n  else {\n    var distance =  (0.89976)*Math.pow(ratio,7.7095) + 0.111;    \n    return distance;\n  }\n}\n\nvar str = data.hostname;\nvar location = str.replace(`C129E53D0F45`, `pink`)\n                .replace(`FD139CD46385`, `DARKORANGE`)\n                .replace(`EB72F2609789`, `DEEPSKYBLUE`)\n                .replace(`DBECEE45AE6F`, `RED`)\n                .replace(`E47D6D760A7F`, `WHITE`)\n                .replace(`C3D7EDB7EF28`, `WHITE`)\n                .replace(`E3A3BD636EA3`, `GREEN`)\n                .replace(`D6F579FC35C9`, `YELLOW`);\n             \nvar beacon = parseInt(data.minor ,16);\n\nvar str = calculateDistance(rssi).toFixed(2);\n\nvar msg = {\ntopic : \"INSERT INTO `test`.`test` (`location`,`beacon`,`distance`,`mac`,`rssi`) VALUES ('\"+location+\"','\"+beacon+\"','\"+str+\"','\"+data.mac+\"','\"+rssi+\"');\"\n}    \nreturn msg;","outputs":1,"noerr":0,"x":590,"y":280,"wires":[["db372be3.5fc8b8","b94d67a3.a0b158"]]},{"id":"b94d67a3.a0b158","type":"mysql","z":"9b2b789d.df51e8","mydb":"d985d62d.44b738","name":"","x":730,"y":280,"wires":[["42241d06.676ad4"]]},{"id":"42241d06.676ad4","type":"debug","z":"9b2b789d.df51e8","name":"","active":true,"console":"false","complete":"false","x":890,"y":340,"wires":[]},{"id":"db372be3.5fc8b8","type":"debug","z":"9b2b789d.df51e8","name":"","active":false,"console":"false","complete":"false","x":750,"y":240,"wires":[]},{"id":"72a43fbc.c3b06","type":"mqtt in","z":"9b2b789d.df51e8","name":"","topic":"test","qos":"0","broker":"d3121fa0.40fac","x":90,"y":280,"wires":[["c97e8fad.1ccfc"]]},{"id":"843b2c33.a8bf4","type":"debug","z":"9b2b789d.df51e8","name":"","active":false,"console":"false","complete":"false","x":430,"y":320,"wires":[]},{"id":"2e80c1f.d012c3e","type":"change","z":"9b2b789d.df51e8","name":"Fix for minor values","rules":[{"t":"change","p":"payload","pt":"msg","from":"001600E5","fromt":"str","to":"0016001D","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"001600CE","fromt":"str","to":"00160006","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"00160101","fromt":"str","to":"00160039","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"001600CB","fromt":"str","to":"00160003","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"0016003B","fromt":"str","to":"00160073","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":280,"wires":[["b4bb90cd.d114b"]]},{"id":"d985d62d.44b738","type":"MySQLdatabase","z":"c1373fb6.410bd","host":"127.0.0.1","port":"3306","db":"test","tz":""},{"id":"d3121fa0.40fac","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"tracked","birthQos":"0","birthPayload":""}]

它包含如下显示 Node-Flow

我曾经设法使用websocket编写系统来显示mqtt数据,但后来无法将其推送到mysql数据库中。

1 个答案:

答案 0 :(得分:2)

否,您不能将Node-RED流编译/导出为独立应用程序。

我们正在努力将编辑器GUI与实际运行该流程的后端分开,但这是针对将来的发行版的。同时,您当前可以通过更改settings.js文件来禁用编辑器。

...
// The following property can be used to disable the editor. The admin API
// is not affected by this option. To disable both the editor and the admin
// API, use either the httpRoot or httpAdminRoot properties
//disableEditor: false,
...