Can someone look at this flow and tell me what is wrong please?

#1

Guys,

I have a flow - 1st part runs once per second and sets a flow variable to Default - i use the moment node for this - this to enable me to use the formatted date time in a logging file.

I then have a 2nd flow that references this - but each time i try and grab it i am getting an undefined message

Can someone have a look at the two bits below and tell me where i am going wrong please ??

[{"id":"d6dfc259.d5a88","type":"moment","z":"6865126d.1bde1c","name":"Get the Date and time for the log","topic":"","input":"","inputType":"date","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD-MM-YY HH:mm","locale":"en_AU","output":"MyDateTiime","outputType":"flow","outTz":"Australia/Sydney","x":510,"y":240,"wires":[[]]},{"id":"c17c2fbe.8c5de","type":"inject","z":"6865126d.1bde1c","name":"Store Date and Time","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":180,"y":240,"wires":[["d6dfc259.d5a88"]]}]

Then the 2nd part (in the same flow) where i reference this - this is triggered by an incoming MQTT message

[{"id":"c27bb157.46dde","type":"debug","z":"6865126d.1bde1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":430,"y":640,"wires":[]},{"id":"c82a1ddf.22956","type":"mqtt in","z":"6865126d.1bde1c","name":"Incoming MQTT from Tank Pump","topic":"Tank_Top_Up_Pump/Tank_Relay/Switch","qos":"2","broker":"e2ed99fb.aa45d8","x":190,"y":640,"wires":[["c27bb157.46dde","99ce6aa4.7369b8"]]},{"id":"99ce6aa4.7369b8","type":"function","z":"6865126d.1bde1c","name":"Log runs to File","func":"var topic = msg.topic;\nif (msg.payload === \"1\") {\n var p = \"On\";\n } \nelse if (msg.payload === \"0\") { \n var p = \"Off\";\n }\nelse var p = \"Unknown\";\n\nvar d = flow.get('MyDateTime') || \"0\";\n\nvar payload = (d + \"Tank Pump is \" + p + \" Topic \" + msg.topic);\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":720,"wires":[["9fda007f.37ac4","9c9c07be.2df6a8"]]},{"id":"9fda007f.37ac4","type":"debug","z":"6865126d.1bde1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":720,"wires":[]},{"id":"9c9c07be.2df6a8","type":"file","z":"6865126d.1bde1c","name":"Log info the file","filename":"/home/pi/logs/Tank_Pump_Run_Stats","appendNewline":true,"createDir":true,"overwriteFile":"false","x":660,"y":680,"wires":[[]]},{"id":"cdb0d4e3.b4da48","type":"inject","z":"6865126d.1bde1c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":700,"wires":[["99ce6aa4.7369b8"]]},{"id":"e2ed99fb.aa45d8","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]

image

image

If i leave out the || on the flow.get from the context i get an undefined, if i put in the || (as seen in the debug) i get the 0 in the output.

I am therefore concluding that i am not able to access the variable - but do not understand why

Any ideas ??

regards

Craig

0 Likes

#2

How have you configured your context storage?

0 Likes

#3

MY default is to file - as per some info from Andrei earlier in the week (for persistence) on another bit of code i was wirting.

I am (ultimately) wanting to store this variable in RAM and read it back from there - but that would mean then using the named contexts - so i thought just leave it as default (File) for the time being

Craig

p.s. thanks for the quick response

0 Likes

#4

Can you share you exact contextStorage setting?

0 Likes

#5

Yep here it is - cut and paste straight out of the file

contextStorage: {
default: {
module: "localfilesystem"
},
memoryOnly: {
module: "memory"
}
}

0 Likes

#6

The first flow you've shared only has the Inject and Moment nodes - I don't see it doing anything with context.

0 Likes

#7

Here is a screenshot of the moment node

In the dropdown for storage i have chosen the default (not memory)

0 Likes

#8

And it seems to be working to set it as the info window on context is updating

image

0 Likes

#9

Ah - I don't have the Moment node installed, so didn't see that. I wasn't aware it let you output to context directly.

Looking at its source - this is a bug with the Moment node; it needs to be updated to handle the persistent context work. That said, there may be more we can do in the core to make it a bit more transparent to the node - will look at that for 0.19.4.

So don't have a quick resolution for you.

0 Likes

#10

Sorry - i have just looked at the raw flow - i have a typo there are two ii in the MyDateTime

Almost impossible to see in the visual editor - just picked it up in the raw flow

I am SO SORRY for wasting your VERY VERY valuable time - Nick

regards

Craig

0 Likes

#11

And just tested and works Ok now - i have spent about 3 hours going backwards and forwards trying to work out what was going on !!!

Craig

0 Likes

#12

Nick,

The moment node seems fine - it has the option in the dropdown to store to default or memory only (have not tried that yet) - will do so a little later today and report back

Craig

0 Likes

#13

Hmm, ok - I'm curious where the #:(memoryOnly)::CurrentDateTiime entry has come from - the #:(memoryOnly):: prefix is an internal thing that shouldn't appear.

0 Likes

#14

In my screenshot you mean ? That was me choosing it the first time i tried i.e. i thought i would store it to memory only rather than disk each second,

then when that did not work i decided to use the default incase i was doing something wrong and then finally i tried a different name in case i was hitting a reserved word etc

Out of instance - how do i clear those file entries from showing up in the debug/info window - they are redundant/not needed - so what is best practice to clear them up and delete the disk files ? i.e. is there a Delete/remove function ?

Craig

0 Likes

#15

I did update that moment node a little while ago.

I am also running on Node.js 10.10 - not sure if that would have any effect

Craig

0 Likes

#16

Just for the record - i just tried to change the Moment node to store to memoryOnly - that worked and i could see the new variable in memoryonly in the flow context

I then tried to use my function to retrieve it - used the name store as per the example below and put in memory (which is what is in my settings.js) and also tried memory.Only as that is what shows in the context browser - neither worked

var myCount = flow.get("count", storeName);

craig

0 Likes

#17

What exactly can you see in flow context?

If it has some form of #:(....):: at the front, then that's broken and will change in 0.19.4.

0 Likes

#18

Only just scanned this thread. Does the moment node need updating? If so, any clues - or even a PR would be nice :wink: but I'll endeavour to sort if needed.

0 Likes

#19

On reflection, this is on oversight on our part.

Whilst you could make some changes to handle multiple context stores properly, it is better for us to handle it for you. I've already pushed a fix to git and 0.19.4 will resolve it.

Appreciate that doesn't really get into the fine details of the issue, but it's late. Happy to share more details another time if anyone is interested.

1 Like

#20

Nick,

Here is what it looks like in the debug window

regards

Craig

0 Likes