Guys,
Is there a way to find what tab/function is updating a global variable ? i am up to about 40 tabs now and trying to track down where/what is updating a couple of globals is doing my head in !
Craig
Guys,
Is there a way to find what tab/function is updating a global variable ? i am up to about 40 tabs now and trying to track down where/what is updating a couple of globals is doing my head in !
Craig
If you enter global.set in the search field it will give you a list of all nodes including that statement. Thats one way. Another is if you open the flow file in a text editior and search for the same phrase, then you also see "more inside" where it happens so to say
Thanks - Much appreciated - it would be a nice feature in the Debug window/COntext browser to be able to highlight the variable and click on it.
Craig
Just to add that I found I was getting to a similar position, not just with context variables but also MQTT topics. So I started adding a standard function to all updates that add an updated timestamp and an updatedBy which indicates the node-red instance, tab name and roughly what function/node did the update. That way, I don't have to keep searching for things but can see at a glance what updated what.
That sounds like a great idea. Using the new User Properties feature of MQTT 5 I think I should be able to add those as User Properties so avoiding the requirement to modify the payload, which would mess up existing flows.
On MQTT, they are extra topics beneath the main topic. I sometimes add them using a function late in the flow.
I typically make my global vars match the structure of my MQTT topics which minimises flow complexity.
Julian - could you give me an example of a MQTT topic and the corresponding Global that you would use ?
Craig
Here is an extract from the known_devices
global var showing the same data as my MQTT example:
The main difference between MQTT topics and JS objects is that while you can have a value on a parent topic in MQTT (as you see in the wiser topic structure), you can't do that exactly the same on a JS object. So the equivalent object for something like the wiser data (actually I don't happen to keep that as a global var because I just keep the whole wiser object that is updated every minute whereas the mqtt topics shown are useful because they are only updated when necessary) would be something like:
...
BatteryLevel: {
value: 'Normal',
updated: ...,
updatedBy: ...
}
Thanks for this info Julian
Craig
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.