[{"id":"19211dbb.e6dee2","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"6a3ddc99.95c224","type":"subflow","name":"timestamp v2","info":"Input:\n- \"msg.payload\" is input string to be stored in\nlog file.\n- log file stored per msg.filename\n\n\nOutput:\n- timestamp and inputstring stored in logfile\n- ","in":[{"x":60,"y":160,"wires":[{"id":"e1df7f5f.1e208"}]}],"out":[{"x":600,"y":200,"wires":[{"id":"d8b6a947.274958","port":0}]}]},{"id":"d8b6a947.274958","type":"function","z":"6a3ddc99.95c224","name":"add timestamp v2","func":"var now = new Date();\nif (msg.filename === undefined) {\n msg.filename = \"/home/pi/data/undefined.log\";\n }\nmsg.payload = now.toString() + \"\\t\" + now.valueOf() + \"\\t\" + msg.payload;\nreturn msg;","outputs":"1","noerr":0,"x":430,"y":160,"wires":[["94bd61ac.6b42a"]]},{"id":"94bd61ac.6b42a","type":"file","z":"6a3ddc99.95c224","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","x":630,"y":140,"wires":[]},{"id":"e1df7f5f.1e208","type":"switch","z":"6a3ddc99.95c224","name":"Drop \"Null\"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"false","outputs":2,"x":210,"y":160,"wires":[["d8b6a947.274958"],[]]},{"id":"be2acc38.41d53","type":"subflow:6a3ddc99.95c224","z":"fa6d6521.059298","name":"","x":770,"y":700,"wires":[[]]},{"id":"75705061.8a8fb","type":"inject","z":"fa6d6521.059298","name":"Power Now","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":120,"wires":[["e8d8266.f1727d8"]]},{"id":"6bbdd1f8.94423","type":"xml","z":"fa6d6521.059298","name":"","attr":"","chr":"","x":290,"y":340,"wires":[["123f319f.edc0ce"]]},{"id":"11399809.eec668","type":"rbe","z":"fa6d6521.059298","name":"Ignore repeat values","func":"rbe","gap":"","start":"","x":540,"y":220,"wires":[["6bbdd1f8.94423"]]},{"id":"e883d58e.177c28","type":"http request","z":"fa6d6521.059298","name":"","method":"POST","ret":"txt","url":"http://192.168.40.111/cgi-bin/post_manager","x":490,"y":120,"wires":[["13ecabb2.ec1354","4ac38957.b53c78"]]},{"id":"e8d8266.f1727d8","type":"function","z":"fa6d6521.059298","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"\\n\";\ncommand += \" get_instantaneous_demand\\n\";\ncommand += \" d8d5b90000006770\\n\";\ncommand += \"\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":120,"wires":[["e883d58e.177c28"]]},{"id":"123f319f.edc0ce","type":"function","z":"fa6d6521.059298","name":"Calc Demand Value","func":"msg.filename = \"/home/pi/data/RainForest.log\"\n//ignore bad data\nif (!msg.payload.InstantaneousDemand) \n{\n return;\n}\n\n//parse response\nstrDemand=msg.payload.InstantaneousDemand.Demand[0];\nintDemand=parseInt(strDemand,16);\n\nstrMultiplier=msg.payload.InstantaneousDemand.Multiplier[0];\nintMultiplier=parseInt(strMultiplier,16);\n\nstrDivisor=msg.payload.InstantaneousDemand.Divisor[0];\nintDivisor=parseInt(strDivisor,16);\n\nif (intDemand>2147483647) { // largest number allowed 0x7FFFFFFF\n intDemand = 0;\n}\n\nif (intMultiplier===0) {\n intMultiplier = 1;\n} \n\nif (intDivisor===0) {\n intDivisor = 1;\n}\n\nmsg.payload = (intDemand * intMultiplier) / intDivisor;\n\nmsg.payload = msg.payload * 1000; // output in Watts not kW\n\nreturn msg;","outputs":"1","noerr":0,"x":450,"y":340,"wires":[["e72c0f58.18d3f"]]},{"id":"4461bcc8.bb9e44","type":"debug","z":"fa6d6521.059298","name":"calc debug","active":true,"console":"false","complete":"payload","x":770,"y":300,"wires":[]},{"id":"13ecabb2.ec1354","type":"function","z":"fa6d6521.059298","name":"Ignore bad data","func":"//ignore bad data\nif (!msg.payload || msg.payload === null || msg.payload === '') \n{\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":220,"wires":[["11399809.eec668"]]},{"id":"7b4d336a.84b2cc","type":"comment","z":"fa6d6521.059298","name":"Read Me: Notes (please retain these notes if distributing the flows)","info":"Author: Mike Thompson, GitHub: mike-linus\nDate: 24/2/2016\n\nThese examples show how to extract data and control the Rainforest Eagle using\nthe recommended HTTP Rest API both locally and via the Internet Gateway.\n\nFor those of you trying to get the most out of the Rainforest Eagle, these\nexample Node-Red flows should get you going. Having the flows in Node-Red\nopens up a huge range of automation possibilities. Enjoy :)\n\nTo use the flows:\n1. Modify the 'Format Request' function nodes to your specific credentials. For local requests, you need to add your own MAC address. For the Relay Gateway, the message headers need to be altered to your Gateway account.\n2. For all flows except the Gateway flow, modify the 'http request' nodes, tick 'use basic authentication?', add your 'Cloud ID' as the username, your 'Installation Code' as the password and your Eagle's IP address.\n3. For the Gateway flow, basic authentication is not used as the credentials are passed in the message header.\n4. To automate the flows, simply modify the 'inject node' to repeat at the required interval.\n5. To publish the data on a MQTT topic, just replace the debug node with an MQTT node.\n\nCreating your own commands simply requires creating the appropriate command string in the 'Format request' node. Refer to the Eagle Rest API documentation for more information.","x":276,"y":37,"wires":[]},{"id":"4ac38957.b53c78","type":"debug","z":"fa6d6521.059298","name":"http debug","active":false,"console":"false","complete":"payload","x":670,"y":80,"wires":[]},{"id":"762a2166.89d5e","type":"function","z":"fa6d6521.059298","name":"Format request 2","func":"//Create Eagle command XML fragment\nvar command = \"\\n\";\ncommand += \" get_current_summation\\n\";\ncommand += \" d8d5b90000006770\\n\";\ncommand += \"\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":480,"wires":[["8669bd1.f79964"]]},{"id":"489d932.fb7626c","type":"inject","z":"fa6d6521.059298","name":"Total kWh","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":120,"y":480,"wires":[["762a2166.89d5e"]]},{"id":"8669bd1.f79964","type":"http request","z":"fa6d6521.059298","name":"","method":"POST","ret":"txt","url":"http://192.168.40.111/cgi-bin/post_manager","x":490,"y":480,"wires":[["d36c3b7f.2c93c8"]]},{"id":"d36c3b7f.2c93c8","type":"xml","z":"fa6d6521.059298","name":"","attr":"","chr":"","x":210,"y":600,"wires":[["46874204.b978bc"]]},{"id":"46874204.b978bc","type":"function","z":"fa6d6521.059298","name":"Calc Current Summation","func":"msg.filename = \"/home/pi/data/RainForest.log\"\n//ignore bad data\nif (!msg.payload.CurrentSummation) \n{\n return;\n}\n\n//parse response\nstrDelivered=msg.payload.CurrentSummation.SummationDelivered[0];\nintDelivered=parseInt(strDelivered,16);\n\nstrMultiplier=msg.payload.CurrentSummation.Multiplier[0];\nintMultiplier=parseInt(strMultiplier,16);\n\nstrDivisor=msg.payload.CurrentSummation.Divisor[0];\nintDivisor=parseInt(strDivisor,16);\n\nif (intDelivered>2147483647) { // largest number allowed 0x7FFFFFFF\n intDelivered = 0;\n}\n\nif (intMultiplier===0) {\n intMultiplier = 1;\n} \n\nif (intDivisor===0) {\n intDivisor = 1;\n}\n\nmsg.payload = (intDelivered * intMultiplier) / intDivisor;\n\nreturn msg;","outputs":"1","noerr":0,"x":390,"y":600,"wires":[["856a3171.7a95d"]]},{"id":"9392f723.6c6d08","type":"debug","z":"fa6d6521.059298","name":"calc debug 2","active":true,"console":"false","complete":"payload","x":770,"y":560,"wires":[]},{"id":"c5cd6847.3a3298","type":"mqtt out","z":"fa6d6521.059298","name":"","topic":"emon/RF2/energy_kWh","qos":"","retain":"","broker":"19211dbb.e6dee2","x":810,"y":600,"wires":[]},{"id":"5f184625.a0e7b8","type":"mqtt out","z":"fa6d6521.059298","name":"","topic":"emon/RF2/power1","qos":"","retain":"","broker":"19211dbb.e6dee2","x":790,"y":340,"wires":[]},{"id":"adc764b8.523898","type":"inject","z":"fa6d6521.059298","name":"","topic":"","payload":"","payloadType":"str","repeat":"60","crontab":"","once":false,"x":110,"y":180,"wires":[["e8d8266.f1727d8","7a22181f.85dde8"]]},{"id":"7a22181f.85dde8","type":"delay","z":"fa6d6521.059298","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":400,"wires":[["762a2166.89d5e"]]},{"id":"9a26382f.65d9c8","type":"inject","z":"fa6d6521.059298","name":"Reboot Eagle","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":840,"wires":[["53e776ff.ac1888"]]},{"id":"53e776ff.ac1888","type":"function","z":"fa6d6521.059298","name":"Format request","func":"//Create Eagle command XML fragment\nvar command = \"\\n\";\ncommand += \" reboot\\n\";\ncommand += \" d8d5b90000006770\\n\";\ncommand += \" Eagle\\n\";\ncommand += \"\\n\";\n\nmsg.payload = command;\n\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":840,"wires":[["e69ea7bf.196158"]]},{"id":"e69ea7bf.196158","type":"http request","z":"fa6d6521.059298","name":"","method":"POST","ret":"txt","url":"http://192.168.40.111/cgi-bin/post_manager","x":470,"y":840,"wires":[["fdfde235.02022"]]},{"id":"fdfde235.02022","type":"debug","z":"fa6d6521.059298","name":"","active":true,"console":"false","complete":"false","x":630,"y":840,"wires":[]},{"id":"856a3171.7a95d","type":"rbe","z":"fa6d6521.059298","name":"","func":"rbe","gap":"","start":"","inout":"out","x":570,"y":600,"wires":[["c5cd6847.3a3298","9392f723.6c6d08","be2acc38.41d53"]]},{"id":"e72c0f58.18d3f","type":"rbe","z":"fa6d6521.059298","name":"","func":"rbe","gap":"","start":"","inout":"out","x":610,"y":340,"wires":[["5f184625.a0e7b8","4461bcc8.bb9e44","be2acc38.41d53"]]}]