Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"bfb81e59.ff7c6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"cfc3a91b.28b7e8","type":"http in","z":"bfb81e59.ff7c6","name":"Inn fra brewfather","url":"/brewfather","method":"post","upload":false,"swaggerDoc":"","x":220,"y":160,"wires":[["2c3e4eb9.5f4592","59f21c3.03377e4","e4eedc53.c4ebd"]]},{"id":"2c3e4eb9.5f4592","type":"http response","z":"bfb81e59.ff7c6","name":"Status response","statusCode":"200","headers":{},"x":460,"y":180,"wires":[]},{"id":"59f21c3.03377e4","type":"debug","z":"bfb81e59.ff7c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":220,"wires":[]},{"id":"e4eedc53.c4ebd","type":"function","z":"bfb81e59.ff7c6","name":"BF to BC","func":"//flow.set('recipe' , msg.payload.recipe.fermentation)\n//flow.set('fbeername' , msg.payload.recipe.name)\n\nfunction numberDes(a,b) {\n return b-a;\n }\n \nfunction stringsort(b,a) {\n return (Number(a.match(/(\\d+)/g)[0]) - Number((b.match(/(\\d+)/g)[0])));\n}\n \nfunction time_convert(num)\n { \n var hours = Math.floor(num / 60); \n var minutes = num % 60;\n return + hours + \":\" + minutes + \":00\"; \n}\nvar hopstandhoptime=[];\nvar hopstandhopname=[];\nvar hopstandhopamount=[];\nvar hopstand\nvar hopstandtemp\nif (msg.payload.recipe.hops.length > 0){\n if (msg.payload.recipe.hopStandMinutes > 0) {\n hopstand = true\n hopstandtemp = msg.payload.recipe.avgWeightedHopstandTemp\n for(var x=0; x<msg.payload.recipe.hops.length; x++){\n if (msg.payload.recipe.hops[x].use == \"Aroma\") {\n hopstandhoptime.push(msg.payload.recipe.hops[x].time)\n hopstandhopname.push(msg.payload.recipe.hops[x].name)\n hopstandhopamount.push(msg.payload.recipe.hops[x].amount)\n }\n }\n \n }\n else {\n hopstandtemp = 0\n hopstand = false\n }\n}\n\nconst {\n dupstand\n} = hopstandhoptime.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dupstand.push(curr)\n return acc\n }, {\n items: {},\n dupstand: []\n }\n)\n\nfor (x= 0; x<hopstandhoptime.length;x++){\n hopstandhopname[x] = hopstandhopamount[x]+\"g \"+hopstandhopname[x]\n}\n\n\nif (dupstand.length > 0) {\nfor (var i = 0; i<dupstand.length; i++) {\n for (x = (hopstandhoptime.indexOf(dupstand[i])); x < hopstandhoptime.lastIndexOf(dupstand[i]); x++) {\n hopstandhopname[hopstandhoptime.indexOf(dupstand[i])] += \" and \"+ hopstandhopname[x+1] \n delete hopstandhopname[x+1]\n delete hopstandhoptime[x+1]\n }\n} \n \n}\n\nfor (i=0; i<hopstandhoptime.length; i++) {\n if (hopstandhoptime[i] == null) {\n hopstandhoptime.splice(i,1);\n hopstandhopname.splice(i,1);\n i -= 1;\n }\n}\nfor (i=0; i<hopstandhoptime.length; i++) {\n hopstandhopname[i] = hopstandhoptime[i]+\"min \"+ hopstandhopname[i]\n}\n\nhopstandhoptime.sort(numberDes);\nhopstandhopname.sort(stringsort);\n\n\nhopstandhoptime.push(0,0,0,0,0,0,0,0,0,0)\nhopstandhoptime.length = 5\nhopstandhopname.push(\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\")\nhopstandhopname.length = 5\n\nvar firstwort\nvar firstworthopname=[];\nvar firstworthopamount=[];\nif (msg.payload.recipe.hops.length > 0){\n if (msg.payload.recipe.hops[0].use == \"First Wort\") {\n firstwort = true\n for( x=0; x<msg.payload.recipe.hops.length; x++){\n if (msg.payload.recipe.hops[x].use == \"First Wort\") {\n firstworthopname.push(msg.payload.recipe.hops[x].name)\n firstworthopamount.push(msg.payload.recipe.hops[x].amount)\n }\n }\n for (x= 0; x<firstworthopname.length;x++){\n firstworthopname[x] = firstworthopamount[x]+\"g \"+firstworthopname[x]\n } \n if (firstworthopname.length > 1) {\n for (x = 1; x <firstworthopname.length; x++) {\n firstworthopname[0] += \" and \"+ firstworthopname[x] \n //delete firstworthopname[x+1]\n }\n //for (i=0; i<firstworthopname.length; i++) {\n // if (firstworthopname[i] === null) {\n // firstworthopname.splice(i,1);\n // i -= 1;\n // } \n //}\n \n }\n }\n else {\n firstwort = false\n}\n //else {\n //firstwort = false\n }\n\n\nvar boilhoptime=[];\nvar boilhopname=[];\nvar boilhopamount=[];\nif (msg.payload.recipe.hops.length > 0){\nfor( x=0;x<msg.payload.recipe.hops.length;x++){\n if (msg.payload.recipe.hops[x].use == \"Boil\") {\n boilhoptime.push(msg.payload.recipe.hops[x].time);\n boilhopname.push(msg.payload.recipe.hops[x].name);\n boilhopamount.push(msg.payload.recipe.hops[x].amount);\n }\n} \n}\nif (msg.payload.batchMiscs.length > 0) {\n for ( x=0;x<msg.payload.batchMiscs.length;x++){\n if (msg.payload.batchMiscs[x].use == \"Boil\") {\n boilhoptime.push(msg.payload.batchMiscs[x].time)\n boilhopname.push(msg.payload.batchMiscs[x].name)\n boilhopamount.push(msg.payload.batchMiscs[x].amount)\n }\n }\n}\n\nconst {\n dup\n} = boilhoptime.reduce(\n (acc, curr) => {\n acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1\n if (acc.items[curr] === 2) acc.dup.push(curr)\n return acc\n }, {\n items: {},\n dup: []\n }\n)\n\nfor (x= 0; x<boilhoptime.length;x++){\n boilhopname[x] = boilhopamount[x]+\"g \"+boilhopname[x]\n}\n\nif (dup.length > 0) {\nfor (var i = 0; i<dup.length; i++) {\n for (x = (boilhoptime.indexOf(dup[i])); x < boilhoptime.lastIndexOf(dup[i]); x++) {\n boilhopname[boilhoptime.indexOf(dup[i])] += \" and \"+ boilhopname[x+1] \n delete boilhopname[x+1]\n delete boilhoptime[x+1]\n }\n} \n}\n\nfor (i=0; i<boilhoptime.length; i++) {\n if (boilhoptime[i] == null) {\n boilhoptime.splice(i,1);\n boilhopname.splice(i,1);\n i -= 1;\n }\n}\nfor (i=0; i<boilhoptime.length; i++) {\n boilhopname[i] = boilhoptime[i]+\"min \"+ boilhopname[i]\n}\n\nboilhoptime.sort(numberDes);\nboilhopname.sort(stringsort);\n\n\nboilhoptime.push(0,0,0,0,0,0,0,0,0,0)\nboilhoptime.length = 10\nboilhopname.push(\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\")\nboilhopname.length = 10\n\nvar mashtime=[];\nfor(var y=0;y<msg.payload.mashStepsCount;y++){\n mashtime[y]= msg.payload.recipe.mash.steps[y].stepTime;\n }\nmashtime.push(0,0,0,0,0);\nmashtime.length = 5\n\nvar mashsteps = msg.payload.mashStepsCount - 1;\nvar mashtemp=[];\nfor(var z=0;z<msg.payload.mashStepsCount;z++){\n mashtemp[z]= msg.payload.recipe.mash.steps[z].stepTemp;\n }\nmashtemp.push(mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps])\nmashtemp.length = 6\n\nmsg.payload = [ \n\n{ \"Name\": \"Preboil volume\", \"Value\": msg.payload.recipe.boilSize } , \n{ \"Name\": \"HLT fillvolume\" , \"Value\": msg.payload.recipe.data.hltWaterAmount } , \n{ \"Name\": \"Sparge volume\" , \"Value\": msg.payload.recipe.data.spargeWaterAmount } , \n{ \"Name\": \"Strike temp\" , \"Value\": msg.payload.recipe.data.strikeTemp } , \n{ \"Name\": \"Mash volume\" , \"Value\": msg.payload.recipe.data.mashWaterAmount } , \n{ \"Name\": \"Mash temp\" , \"Value\": mashtemp[0] } ,\n{ \"Name\": \"Mash temp1\" , \"Value\": mashtemp[1] } , \n{ \"Name\": \"Mash temp2\" , \"Value\": mashtemp[2] } ,\n{ \"Name\": \"Mash temp3\" , \"Value\": mashtemp[3] } ,\n{ \"Name\": \"Mash temp4\" , \"Value\": mashtemp[4] } ,\n{ \"Name\": \"Mash temp5\" , \"Value\": mashtemp[5] } ,\n{ \"Name\": \"Mash time1\" , \"Value\": time_convert(mashtime[0]) } ,\n{ \"Name\": \"Mash time2\" , \"Value\": time_convert(mashtime[1]) } ,\n{ \"Name\": \"Mash time3\" , \"Value\": time_convert(mashtime[2]) } ,\n{ \"Name\": \"Mash time4\" , \"Value\": time_convert(mashtime[3]) } ,\n{ \"Name\": \"Mash time5\" , \"Value\": time_convert(mashtime[4]) } ,\n{ \"Name\": \"Hop time0\" , \"Value\": time_convert(boilhoptime[0]) } ,\n{ \"Name\": \"Hop time1\" , \"Value\": time_convert(boilhoptime[1]) } ,\n{ \"Name\": \"Hop time2\" , \"Value\": time_convert(boilhoptime[2]) } ,\n{ \"Name\": \"Hop time3\" , \"Value\": time_convert(boilhoptime[3]) } ,\n{ \"Name\": \"Hop time4\" , \"Value\": time_convert(boilhoptime[4]) } ,\n{ \"Name\": \"Hop time5\" , \"Value\": time_convert(boilhoptime[5]) } ,\n{ \"Name\": \"Hop time6\" , \"Value\": time_convert(boilhoptime[7]) } ,\n{ \"Name\": \"Hop time8\" , \"Value\": time_convert(boilhoptime[8]) } ,\n{ \"Name\": \"Hop time9\" , \"Value\": time_convert(boilhoptime[9]) } ,\n{ \"Name\": \"Boilhopname0\" , \"Value\": boilhopname[0] } ,\n{ \"Name\": \"Boilhopname1\" , \"Value\": boilhopname[1] } ,\n{ \"Name\": \"Boilhopname2\" , \"Value\": boilhopname[2] } ,\n{ \"Name\": \"Boilhopname3\" , \"Value\": boilhopname[3] } ,\n{ \"Name\": \"Boilhopname4\" , \"Value\": boilhopname[4] } ,\n{ \"Name\": \"Boilhopname5\" , \"Value\": boilhopname[5] } ,\n{ \"Name\": \"Boilhopname6\" , \"Value\": boilhopname[6] } ,\n{ \"Name\": \"Boilhopname7\" , \"Value\": boilhopname[7] } ,\n{ \"Name\": \"Boilhopname8\" , \"Value\": boilhopname[8] } ,\n{ \"Name\": \"Boilhopname9\" , \"Value\": boilhopname[9] } ,\n{ \"Name\": \"Boilsteps\" , \"Value\": msg.payload.boilSteps.length } ,\n{ \"Name\": \"Hopstandtime0\" , \"Value\": time_convert(hopstandhoptime[0])},\n//{ \"Name\": \"Hopstandtime1\" , \"Value\": time_convert(hopstandhoptime[1])},\n//{ \"Name\": \"Hopstandtime2\" , \"Value\": time_convert(hopstandhoptime[2])},\n//{ \"Name\": \"Hopstandtime3\" , \"Value\": time_convert(hopstandhoptime[3])},\n//{ \"Name\": \"Hopstandtime4\" , \"Value\": time_convert(hopstandhoptime[4])},\n{ \"Name\": \"Hopstandhopname0\" , \"Value\": hopstandhopname[0]},//String(hopstandhopamount[0]) +\"g\" +\" \" +String(hopstandhopname[0]) } ,\n//{ \"Name\": \"Hopstandhopname2\" , \"Value\": hopstandhopname[1]},//String(hopstandhopamount[1]) +\"g\" +\" \" +String(hopstandhopname[1]) } ,\n//{ \"Name\": \"Hopstandhopname3\" , \"Value\": hopstandhopname[2]},//String(hopstandhopamount[2]) +\"g\" +\" \" +String(hopstandhopname[2]) } ,\n//{ \"Name\": \"Hopstandhopname4\" , \"Value\": hopstandhopname[3]},//String(hopstandhopamount[3]) +\"g\" +\" \" +String(hopstandhopname[3]) } ,\n//{ \"Name\": \"Hopstandhopname5\" , \"Value\": hopstandhopname[4]},//String(hopstandhopamount[4]) +\"g\" +\" \" +String(hopstandhopname[4]) } ,\n{ \"Name\": \"Hopstand\" , \"Value\": hopstand } ,\n{ \"Name\": \"Boil time\" , \"Value\": time_convert(msg. payload.recipe.boilTime) } ,\n{ \"Name\": \"Hopstand temp\" , \"Value\": hopstandtemp } ,\n{ \"Name\": \"First wort\" , \"Value\": firstwort } ,\n{ \"Name\": \"Status\" , \"Value\": new Date().toDateString()+\" \"+new Date().getHours()+\":\"+new Date().getMinutes()+\" \" +\"#\"+msg.topic+\" \"+msg.payload.recipe.name }\n\n];\n\nreturn msg;\n","outputs":1,"noerr":0,"x":440,"y":100,"wires":[["a38bd486.512748","4b0bb619.922ee8"]]},{"id":"a38bd486.512748","type":"http request","z":"bfb81e59.ff7c6","name":"Send til Brucontrol","method":"PUT","ret":"txt","paytoqs":false,"url":"http://192.168.77.246:8000/globals","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":100,"wires":[[]]},{"id":"4b0bb619.922ee8","type":"debug","z":"bfb81e59.ff7c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":160,"wires":[]}]
Add Comment
Please, Sign In to add comment