Changing maths, triggers logic dynamically

I need to have a capability within the software to receive a json into node red stored with persistence with data about the rules of logic gates, maths that have affect on the output. The node red is not meant to be re deployed. But always use same deployed code. I’d like it be able to change part of it dynamically

So what I’m doing is interfacing 20 digital channels and couple analog channels into raspberry pi. Without the redeployment I would like to change the logic and, or,nand, nor... and maths more than, less than, equals and so on relational logic + maths from external payload.

Any ideas how to approach the problem?

How would you send this "logic" payload?

I would do a http get request or last resort subscribe to mqtt topic.

The logic would have a format for example
Channel 1 AND Channel 2
Channel 2 OR Channel 3
Analog >30

There are a number of possibilities.

You could for example...

Request js (string) that you store in file and execute using eval or exec

Incorporate a plc emulator (there are a few js/node based PLC emulators)?

you could request a node-red flow that you save to file system then restart node-red to run it.

You could write a logic parser with pure nodes.

You could implement a state machine (there are some state machine nodes already for node-red)

You could have 2 node-red instances. Instance 1 requests a flow file, saves it to a ram disk (or persistent file) then launches 2nd node-red instance & specifies the flow file that was saved.

I don't think I am scratching the surface.

It all depends how complex you expect the logic to become over time.

Wow thanks that’s a lot more detail that I was expecting.

In the first method is that setting up the logic testing in the bash somehow or is that a way of redeploying the flow with the use of bash?

PLC additional hardware is outside the budget. Unless is that some free software that can be interfaced with node red in a simple way for me to understand and code the logic.

I was thinking about downloading another flow file with wget and running a command for redeploy in a single line &&. This is last resort at the moment.

How would the state machines be updated? With the overwriting the flow file or using another software? Could you pls give a example.

For 2 node red instances what would be the best way of communicating between them is there a build in way or tcpip

PLC: I wasn't talking about hardware, but a js emulator. Search NPM.

As for the other questions (i.e. your thought of using wget) suggests you don't realise how much you can actually achieve in node-red without resorting to spawning out to the likes of wget. Are you new to node-red? If so, I'd recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

For the 2 node-red solution, there would be no need to communicate between them (but you could via a local broker) but my proposal was you'd only use the first instance to grab (http request) the (dynamic) flow from (wherever) for the 2nd to run. Like a coordinator.

I can't / won't go into details, just trying to spark some ideas for you.

Oh, and before I forget, when I first read you request, I thought it quite specific (you have some potentially IP reason for the architecture you are aiming at) but I will mention in case you don't realise, it is possible to post (via the admin API) a flow to node-red.

Yes I should have started I'm a beginner.
You have mentioned a lot of useful information and sparked a lot of ideas so I will try to digest that and maybe ask some follow up questions. :+1:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.