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