Avalon Parkes-barton
Avalon Parkes-barton

Reputation: 77

Is there a way to move from node-red to pure code?

Im currently using node-red to achieve my outcome due to being able to use the gui but ideally i want to move away from this and just have 1 seamless system rather than going back and forth between systems

my current flow is as below.

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

it contains display as below Node-Flow

i managed to write up a system previously using websocket to display mqtt data but i couldn't then push that through to the mysql database.

Upvotes: 1

Views: 1570

Answers (1)

hardillb
hardillb

Reputation: 59668

No, you can not compile/export a Node-RED flow as standalone application.

Work is being done to separate the editor GUI from the backend that actually runs the flow, but this targeted for a future release. In the mean time, you can currently disable the editor by changing the settings.js file.

...
// 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,
...

Upvotes: 2

Related Questions