-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.json
1 lines (1 loc) · 35.5 KB
/
flow.json
1
[{"id":"35ebdcf3.1264b4","type":"tab","label":"Check sensorStatus","disabled":false,"info":""},{"id":"1fb4a826.643528","type":"tab","label":"forcescanfishbed","disabled":false,"info":""},{"id":"4b81fb0f.775f54","type":"tab","label":"Receive telegram commands","disabled":false,"info":""},{"id":"bc77d77f.c10f58","type":"tab","label":"Get IgrValue plot","disabled":false,"info":""},{"id":"4cec58dc.b0b798","type":"tab","label":"Receive XBee packet","disabled":false,"info":""},{"id":"7e776643.b34338","type":"tab","label":"Receive web command","disabled":false,"info":""},{"id":"cb92b403.8033c8","type":"tab","label":"Commands Queue Handler","disabled":false,"info":""},{"id":"39fe4e64.ac2042","type":"tab","label":"Add command to commandsQueue","disabled":false,"info":""},{"id":"9bbf0afd.b70828","type":"xbee-config","z":"","apiMode":"2","rawFrames":false,"convertAdc":true,"vrefAdc":"1200","serialPort":"/dev/serial0","lock":true,"baudRate":"9600","dataBits":"8","stopBits":"1","parity":"none","bufferSize":"65536","rtscts":false,"xon":false,"xoff":false,"xany":false,"vmin":"1","vtime":"0"},{"id":"655f1840.25d818","type":"wiotp-credentials","z":"","name":"","org":"8eg0a9","serverName":"","devType":"aquaponics","devId":"aquaponics","keepalive":"300","cleansession":true,"tls":"","usetls":false},{"id":"2ef313b0.86cd1c","type":"telegram bot","z":"","botname":"makeaqwertybot","usernames":"350858271","chatids":"350858271","baseapiurl":"","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"verboselogging":false},{"id":"b179303c.248b3","type":"inject","z":"35ebdcf3.1264b4","name":"Sensor Status","topic":"","payload":"","payloadType":"date","repeat":"300","crontab":"","once":true,"onceDelay":"60","x":122.80157470703125,"y":134.547607421875,"wires":[["9f002f80.bfda8"]]},{"id":"ee38198.f236fe8","type":"comment","z":"35ebdcf3.1264b4","name":"Check Sensor Status every 5 minutes","info":"","x":410.6349182128906,"y":58.047607421875,"wires":[]},{"id":"6fcc200f.59cd5","type":"inject","z":"bc77d77f.c10f58","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 23 * * *","once":false,"x":140.5,"y":152,"wires":[["4f86add6.8a35c4"]]},{"id":"4f86add6.8a35c4","type":"python-function","z":"bc77d77f.c10f58","name":"Get IgrValue plot","func":"import requests\nimport plotly.plotly as py\nimport plotly.graph_objs as go\nfrom datetime import datetime\n\n# Define cloudant username\nuser = \"b75ed432-525e-4bf7-bcc7-1146c4634da8-bluemix\"\n\n# Define cloudant password\npasswd = \"8e1da5fba2be2e5798322931d17cc29179281c99cf2d0d50860fb099b904ee86\"\n\n# Define cloudant host\nhost = user+\".cloudant.com\"\n\n\ni = datetime.now()\n\nyear = i.strftime(\"%Y\")\nmonth = i.strftime(\"%m\")\nday = i.strftime(\"%d\")\n\nnode.warn(\"Today is \" + year + \"-\" + month + \"-\" + day)\n\n# Define cloudant db name\ndb = \"iotp_8eg0a9_aquaponics_\" + str(year) + \"-\" + str(month) + \"-\" + str(day)\n\n# Define view variable to contain the Map View Name\nview = \"by-date\"\n\n# Frame the URL using above defned variables values\nurl = 'https://'+host+'/'+db+'/_design/iotp/_view/'+view\n\n# Define args variable to store required parameter values\nargs = { 'descending' : 'false' }\n\n# Invoke HTTP GET request with all required parameters\nresponse = requests.get(url,params=args,auth=(user,passwd))\n\nigrValue1 = [];\nigrValue2 = [];\nigrValue3 = [];\nigrValue4 = [];\nigrTime = [];\n\n# Check the response status code, should be 200 to proceed further\nif ( response.status_code == 200):\n # Get the response data in JSON format\n jsonData = response.json()\n # Get the device data records which are JSON array of rows with in jsonData\n records = jsonData['rows']\n # For each record, get deviceType, deviceID and devicedata from the records\n for record in records:\n dType = record['value']['deviceType']\n \n node.warn(\"Value:\" + str(record['value']['data']['d']['igrValueArray']))\n dTimestamp = record['value']['timestamp']\n igrTime.append(dTimestamp);\n \n dValue1 = record['value']['data']['d']['igrValueArray']['igrValue1']\n igrValue1.append(dValue1);\n \n dValue2 = record['value']['data']['d']['igrValueArray']['igrValue2']\n igrValue2.append(dValue2);\n \n dValue3 = record['value']['data']['d']['igrValueArray']['igrValue3']\n igrValue3.append(dValue3);\n \n dValue4 = record['value']['data']['d']['igrValueArray']['igrValue4']\n igrValue4.append(dValue4);\n \n \n #node.warn(\"igrValue1=\" + str(dValue1) + \", igrValue2=\" + str(dValue2) + \", timestamp=\" + str(dTimestamp) )\n #print \"Device Type: %s Device Id: %s Value: %s\" %(dType,dID,str(dValue))\nelse:\n #print \"HTTP GET Failed with Status Code - %s\" %(response.status_code)\n node.warn(\"HTTP GET Failed with Status Code - \" + response.status_code)\n\npy.sign_in('braghettos', 'HjPGCZef6HXIro7lRf4L') # Replace the username, and API key with your credentials.\n\ntrace1 = go.Scatter(x=igrTime, y=igrValue1)\ntrace2 = go.Scatter(x=igrTime, y=igrValue2)\ntrace3 = go.Scatter(x=igrTime, y=igrValue3)\ntrace4 = go.Scatter(x=igrTime, y=igrValue4)\ndata = [trace1, trace2, trace3, trace4]\nlayout = go.Layout(title='IgrValue Plot', width=800, height=640)\nfig = go.Figure(data=data, layout=layout)\n\npy.image.save_as(fig, filename='/tmp/igrvalue-plot-' + year + '-' + month + '-' + day + '.png')\n\nnode.warn(\"img created!\");\n\nreturn msg","outputs":1,"x":370.5,"y":175,"wires":[["a5d61930.4e86d8"]]},{"id":"9f002f80.bfda8","type":"function","z":"35ebdcf3.1264b4","name":"set sensorStatus command","func":"var msg = { payload: \n {\n command: \"sensorStatus\" // Can either be string or byte array. \n } \n};\n\nreturn msg;","outputs":1,"noerr":0,"x":327.2777786254883,"y":314.66667556762695,"wires":[["754dcc79.61cef4"]]},{"id":"d9a62160.0040e","type":"telegram command","z":"bc77d77f.c10f58","name":"","command":"/getigrvalueplot","bot":"2ef313b0.86cd1c","x":127.5,"y":244,"wires":[["4f86add6.8a35c4"],[]]},{"id":"a5d61930.4e86d8","type":"function","z":"bc77d77f.c10f58","name":"Send IgrValue plot via Telegram","func":"d = new Date();\n\nlet month = String(d.getMonth() + 1);\nlet day = String(d.getDate());\nconst year = String(d.getFullYear());\n\nif (month.length < 2) month = '0' + month;\nif (day.length < 2) day = '0' + day;\n\nnode.warn(year + \"-\" + month + \"-\" + day);\n\nvar msg = { payload: \n {\n type: 'photo', \n content: '/tmp/igrvalue-plot-' + year + '-' + month + '-' + day + '.png',\n chatId: 350858271\n } \n};\n\n\n/* type can be one of the following\nphoto\naudio\nvideo\nsticker\nvoice\ndocument\n*/\n\nreturn msg;","outputs":1,"noerr":0,"x":456.5,"y":273,"wires":[["7fb3eef2.7b5e4"]]},{"id":"7fb3eef2.7b5e4","type":"telegram sender","z":"bc77d77f.c10f58","name":"","bot":"2ef313b0.86cd1c","x":599.5,"y":349,"wires":[["e77a3be1.e9e528"]]},{"id":"e77a3be1.e9e528","type":"debug","z":"bc77d77f.c10f58","name":"telegram sender debug","active":true,"console":"true","complete":"true","x":621.5,"y":448,"wires":[]},{"id":"6eeb4a59.5f5564","type":"xbee-rx","z":"4cec58dc.b0b798","name":"","xBee":"9bbf0afd.b70828","x":115,"y":135,"wires":[["e7aa6f2.8ddac9","dad0464c.e2f358"]]},{"id":"e7aa6f2.8ddac9","type":"function","z":"4cec58dc.b0b798","name":"XBee Received data","func":"var firstChar;\nvar lastChar;\nvar newMsg;\nvar payloadAppend = context.get('payloadAppend')||'';\n\n//node.warn('first char=' + firstChar);\n\nif (msg.payload.type === 144) {\n \n firstChar = msg.payload.data.toString().substr(0, 1);\n lastChar = msg.payload.data.toString().substr(msg.payload.data.length-1, msg.payload.data.length);\n \n node.warn(\"payload received=\" + msg.payload.data.toString() + \", length=\" + msg.payload.data.length);\n \n if(firstChar == \"|\" && lastChar == \"|\" ){\n \n var payload = msg.payload.data.toString().substr(1, msg.payload.data.length-2);\n \n node.warn(\"payload PRE 1 (single message)=\" + payload);\n \n //payloadAppend = msg.payload.data.toString();\n payloadAppend = payload;\n newMsg = { payload: payloadAppend };\n context.set('payloadAppend','');\n } else if(firstChar == \"|\" ){\n \n var payload = msg.payload.data.toString().substr(1, msg.payload.data.length);\n \n node.warn(\"payload PRE 2=\" + payload);\n \n //payloadAppend += msg.payload.data.toString();\n payloadAppend += payload;\n context.set('payloadAppend',payloadAppend);\n } else if(lastChar == \"|\" ){\n \n var payload = msg.payload.data.toString().substr(0, msg.payload.data.length-1);\n \n node.warn(\"payload PRE 3=\" + payload);\n \n //payloadAppend += ',' + msg.payload.data.toString();\n payloadAppend += ',' + payload;\n newMsg = { payload: payloadAppend };\n context.set('payloadAppend','');\n } else {\n payloadAppend += ',' + msg.payload.data.toString();\n \n node.warn(\"payload PRE 4=\" + msg.payload.data.toString());\n \n context.set('payloadAppend',payloadAppend);\n }\n \n node.warn(\"msg.payload.data=\" + msg.payload.data.toString() + \", firstChar=\" + firstChar + \", lastChar=\" + lastChar + \", payloadAppend POST =\" + payloadAppend);\n \n}\n\nreturn newMsg;","outputs":1,"noerr":0,"x":314.2777633666992,"y":207.11111640930176,"wires":[["1e802eac.ca6bc1","c8b6b4a0.618c08"]]},{"id":"dad0464c.e2f358","type":"debug","z":"4cec58dc.b0b798","name":"input raw frame","active":true,"console":"false","complete":"true","x":638.1666641235352,"y":137.00000190734863,"wires":[]},{"id":"1e802eac.ca6bc1","type":"debug","z":"4cec58dc.b0b798","name":"New payload","active":true,"console":"false","complete":"payload","x":628.8888854980469,"y":208.99999618530273,"wires":[]},{"id":"bf77ef14.64446","type":"json","z":"4cec58dc.b0b798","name":"","pretty":true,"x":369.7222366333008,"y":370.44444847106934,"wires":[["a4825809.18cf98","56ea5282.d70c7c","68862f09.8edac","94507cc4.3d8a9","2429492b.4bc436"]]},{"id":"a4825809.18cf98","type":"debug","z":"4cec58dc.b0b798","name":"json validator","active":true,"console":"false","complete":"true","x":624.611083984375,"y":301,"wires":[]},{"id":"3a63d8d0.cd3528","type":"wiotp out","z":"4cec58dc.b0b798","authType":"d","qs":"false","qsDeviceId":"","deviceKey":"655f1840.25d818","deviceType":"raspberrypi","deviceId":"raspberrypi3","event":"aquaponicsensor","format":"json","qos":"0","name":"","x":670,"y":700,"wires":[]},{"id":"c8b6b4a0.618c08","type":"switch","z":"4cec58dc.b0b798","name":"if payload is final json message","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"}","vt":"str"}],"checkall":"true","outputs":1,"x":296.7777786254883,"y":284.55556297302246,"wires":[["bf77ef14.64446"]]},{"id":"20322d1d.340ae2","type":"comment","z":"4cec58dc.b0b798","name":"Read XBee packet and send it to Watson IoT Platform","info":"","x":386.6666793823242,"y":60.55555725097656,"wires":[]},{"id":"e9fef15c.7b619","type":"http in","z":"7e776643.b34338","name":"","url":"/command","method":"post","upload":true,"swaggerDoc":"","x":134.38890838623047,"y":111.88884925842285,"wires":[["2bdeb8cb.5a6da8","c5b90144.33989"]]},{"id":"2bdeb8cb.5a6da8","type":"debug","z":"7e776643.b34338","name":"Command from web","active":true,"console":"false","complete":"true","x":399.4444580078125,"y":111.77775573730469,"wires":[]},{"id":"93bc006a.b0a4d","type":"comment","z":"7e776643.b34338","name":"Execute command from Watson IoT Platform","info":"","x":418.8333435058594,"y":54.444435119628906,"wires":[]},{"id":"c5b90144.33989","type":"link out","z":"7e776643.b34338","name":"","links":["4215b5ab.b4713c"],"x":313.8888645172119,"y":200.00001525878906,"wires":[]},{"id":"754dcc79.61cef4","type":"link out","z":"35ebdcf3.1264b4","name":"","links":["4215b5ab.b4713c"],"x":617.8889122009277,"y":314.6666793823242,"wires":[]},{"id":"56ea5282.d70c7c","type":"switch","z":"4cec58dc.b0b798","name":"check command","property":"payload.command","propertyType":"msg","rules":[{"t":"eq","v":"sensorstatus","vt":"str"},{"t":"cont","v":"time","vt":"str"},{"t":"cont","v":"TIME","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":290,"y":540,"wires":[["3a63d8d0.cd3528","a8adf386.cb1fb"],[],[],["e72afd54.9cd81"]]},{"id":"a40d4743.e50508","type":"telegram sender","z":"4cec58dc.b0b798","name":"","bot":"2ef313b0.86cd1c","x":640,"y":900,"wires":[["21dc2c9c.cba534"]]},{"id":"21dc2c9c.cba534","type":"debug","z":"4cec58dc.b0b798","name":"telegram sender debug","active":true,"console":"true","complete":"true","x":866,"y":961,"wires":[]},{"id":"59e93abb.1e55c4","type":"function","z":"4cec58dc.b0b798","name":"Send payload via Telegram","func":"var newmsg = { payload: \n {\n type: 'message', \n content: msg.payload,\n chatId: 350858271\n } \n};\n\nreturn newmsg;","outputs":1,"noerr":0,"x":419,"y":843,"wires":[["a40d4743.e50508"]]},{"id":"e72afd54.9cd81","type":"json","z":"4cec58dc.b0b798","name":"","property":"payload","action":"","pretty":false,"x":358.5,"y":756,"wires":[["59e93abb.1e55c4"]]},{"id":"10ac3cfc.868c73","type":"function","z":"cb92b403.8033c8","name":"XBee Transmit Request","func":"var commands = global.get(\"commandsQueue\");\nvar command = commands[0];\nglobal.set(\"commandRunning\",true);\n\nnode.warn(\"commandsQueue=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length + \", commandRunning=\" + global.get(\"commandRunning\"));\n\nvar newMsg = { payload: \n {\n type: 0x10, // xbee_api.constants.FRAME_TYPE.ZIGBEE_TRANSMIT_REQUEST \n id: 0x01, // optional, nextFrameId() is called per default \n destination64: \"0013A200408BB14C\",\n destination16: \"fffe\", // optional, \"fffe\" is default \n broadcastRadius: 0x00, // optional, 0x00 is default \n options: 0x00, // optional, 0x00 is default \n //data: msg.payload.command.toString().toLowerCase() // Can either be string or byte array. \n data: command\n } \n};\n\nreturn newMsg;","outputs":1,"noerr":0,"x":930,"y":540,"wires":[["3d50778b.a475f8","4dc514a8.de97bc"]]},{"id":"3d50778b.a475f8","type":"debug","z":"cb92b403.8033c8","name":"XBee packet to send","active":true,"console":"false","complete":"payload","x":1240,"y":540,"wires":[]},{"id":"4dc514a8.de97bc","type":"xbee-tx","z":"cb92b403.8033c8","name":"","xBee":"9bbf0afd.b70828","x":1197.9444580078125,"y":626.2222323417664,"wires":[]},{"id":"68862f09.8edac","type":"function","z":"4cec58dc.b0b798","name":"remove command to commandsQueue","func":"var commands = global.get(\"commandsQueue\")||[0];\n\nvar command = msg.payload.command.toLowerCase();\n\nvar index = commands.indexOf(command);\n\nnode.warn(\"commandsQueue PRE=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length + \", commandRunning=\" + global.get(\"commandRunning\"));\n\nif (index > -1) {\n commands.splice(index, 1);\n global.set(\"commandRunning\",false);\n node.warn(\"command \" + command + \" removed, commandRunning=\" + global.get(\"commandRunning\") + \", commandsQueue POST=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length);\n return [msg,null];\n} else {\n node.error(\"command \" + command + \" not found in queue, commandRunning=\" + global.get(\"commandRunning\") + \", commandsQueue POST=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length);\n return [null,msg];\n}\n","outputs":"2","noerr":0,"x":713,"y":424,"wires":[["364ab04d.9ac97"],["364ab04d.9ac97"]]},{"id":"cc43ac21.602f1","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":280,"wires":[["5a5cb75.45ebd48"]]},{"id":"d5deda0.e872728","type":"telegram command","z":"4b81fb0f.775f54","name":"/gohome","command":"/gohome","bot":"2ef313b0.86cd1c","x":320,"y":240,"wires":[["cc43ac21.602f1"],[]]},{"id":"5a5cb75.45ebd48","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":340,"wires":[["a0ca4341.7565f"]]},{"id":"a0ca4341.7565f","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":400,"wires":[["c0ada0ad.feae4"]]},{"id":"c0ada0ad.feae4","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'gohome';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":480,"wires":[["fe9baa4b.ce3dc8"],[]]},{"id":"fe9baa4b.ce3dc8","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":474,"wires":[]},{"id":"725c9192.656c4","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":560,"wires":[["6095651a.3ced2c"]]},{"id":"24e67e54.3bbcc2","type":"telegram command","z":"4b81fb0f.775f54","name":"/sensorstatus","command":"/sensorstatus","bot":"2ef313b0.86cd1c","x":330,"y":520,"wires":[["725c9192.656c4"],[]]},{"id":"6095651a.3ced2c","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":620,"wires":[["a37010b8.297a5"]]},{"id":"a37010b8.297a5","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":680,"wires":[["c9ca3cfb.31f0e"]]},{"id":"c9ca3cfb.31f0e","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'sensorstatus';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":760,"wires":[["2b3a4fd5.4b317"],[]]},{"id":"2b3a4fd5.4b317","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":754,"wires":[]},{"id":"3fa7b98b.6a1676","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":840,"wires":[["aad1ab1e.471ec8"]]},{"id":"722e4e43.3ebfe","type":"telegram command","z":"4b81fb0f.775f54","name":"/switchonpump","command":"/switchonpump","bot":"2ef313b0.86cd1c","x":340,"y":800,"wires":[["3fa7b98b.6a1676"],[]]},{"id":"aad1ab1e.471ec8","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":900,"wires":[["20b5593.b43cea6"]]},{"id":"20b5593.b43cea6","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":960,"wires":[["b29d473e.c7dba8"]]},{"id":"b29d473e.c7dba8","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'switchonpump';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":1040,"wires":[["af6643f6.fd5ac"],[]]},{"id":"af6643f6.fd5ac","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":1034,"wires":[]},{"id":"1bc19a47.b93de6","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":1120,"wires":[["c4f690bd.06f8d"]]},{"id":"3e436c6b.9d88f4","type":"telegram command","z":"4b81fb0f.775f54","name":"/switchoffpump","command":"/switchoffpump","bot":"2ef313b0.86cd1c","x":340,"y":1080,"wires":[["1bc19a47.b93de6"],[]]},{"id":"c4f690bd.06f8d","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":1180,"wires":[["20d868b6.5cb9e8"]]},{"id":"20d868b6.5cb9e8","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":1240,"wires":[["88ba451a.46eb08"]]},{"id":"88ba451a.46eb08","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'switchoffpump';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":1320,"wires":[["a8b08f76.e8009"],[]]},{"id":"a8b08f76.e8009","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":1314,"wires":[]},{"id":"35ffe429.05000c","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":1380,"wires":[["eae45e60.41fda"]]},{"id":"2c8cabb3.05fdc4","type":"telegram command","z":"4b81fb0f.775f54","name":"/getigrvalue","command":"/getigrvalue","bot":"2ef313b0.86cd1c","x":330,"y":1340,"wires":[["35ffe429.05000c"],[]]},{"id":"eae45e60.41fda","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":1440,"wires":[["8aa904ea.e393a8"]]},{"id":"8aa904ea.e393a8","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":1500,"wires":[["b11015e0.f24b98"]]},{"id":"b11015e0.f24b98","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'getigrvalue';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":1580,"wires":[["493b94c3.83fb4c"],[]]},{"id":"493b94c3.83fb4c","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":1574,"wires":[]},{"id":"64488e1.3df827","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":1680,"wires":[["ac762160.03d7b"]]},{"id":"21115ec1.4cfc72","type":"telegram command","z":"4b81fb0f.775f54","name":"/getigrvaluethreshold","command":"/getigrvaluethreshold","bot":"2ef313b0.86cd1c","x":360,"y":1640,"wires":[["64488e1.3df827"],[]]},{"id":"ac762160.03d7b","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":1740,"wires":[["5869a3d8.590e6c"]]},{"id":"5869a3d8.590e6c","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":1800,"wires":[["7650e493.cad98c"]]},{"id":"7650e493.cad98c","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'Yes' || msg.payload.content === 'yes')\n{\n msg.payload.command = 'getigrvaluethreshold';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":1880,"wires":[["97c264fd.6b76f8"],[]]},{"id":"97c264fd.6b76f8","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":1874,"wires":[]},{"id":"ab01f11c.a7a43","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'What is the max threshold?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":480,"y":2000,"wires":[["7233bcc1.497684"]]},{"id":"3e618a5b.8f9326","type":"telegram command","z":"4b81fb0f.775f54","name":"/startscanfishbed","command":"/startscanfishbed","bot":"2ef313b0.86cd1c","x":340,"y":1960,"wires":[["ab01f11c.a7a43"],[]]},{"id":"7233bcc1.497684","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":580,"y":2060,"wires":[["6414b9f.8ab3248"]]},{"id":"6414b9f.8ab3248","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":680,"y":2120,"wires":[["faec9d3b.e8237"]]},{"id":"faec9d3b.e8237","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content > 0)\n{\n msg.payload.command = 'startscanfishbed' + msg.payload.content;\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":800,"y":2200,"wires":[["ed931aa.e4ebde8"],[]]},{"id":"ed931aa.e4ebde8","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1015,"y":2194,"wires":[]},{"id":"7948becc.14115","type":"debug","z":"cb92b403.8033c8","name":"Filter by time debug","active":true,"console":"false","complete":"payload","x":920,"y":441,"wires":[]},{"id":"74af21d0.c6fa5","type":"function","z":"cb92b403.8033c8","name":"Filter by time","func":"var d = new Date();\nvar n = d.getHours();\n\nvar commandToAdd;\n\n\ncommandToAdd = global.get(\"commandsQueue\")[0];\nnode.warn(\"commandToAdd=\" + commandToAdd);\n\n\nif ((n > 6 && n < 24) || (commandToAdd.toLowerCase() === \"sensorstatus\") || (commandToAdd.toLowerCase() === \"reset\")){\n node.warn(\"command \"+ commandToAdd + \" passing, hour=\" + n);\n return msg;\n}\nelse {\n node.error(\"command \" + commandToAdd + \" BLOCKED, hour=\" + n);\n return null;\n}\n ","outputs":1,"noerr":0,"x":570,"y":440,"wires":[["7948becc.14115","16e3f86c.3c1c38","10ac3cfc.868c73"]]},{"id":"22deb1ca.607f2e","type":"function","z":"cb92b403.8033c8","name":"Forward web command via Telegram","func":"var newmsg = { payload: \n {\n type: 'message', \n content: 'Just received the following message: ' + msg.payload,\n chatId: 350858271\n } \n};\n\nreturn newmsg;","outputs":1,"noerr":0,"x":1190,"y":260,"wires":[["e1db1d8d.6684d","a41a06bf.598b68"]]},{"id":"e1db1d8d.6684d","type":"telegram sender","z":"cb92b403.8033c8","name":"","bot":"2ef313b0.86cd1c","x":1313,"y":336,"wires":[["aefc3413.711ce8"]]},{"id":"aefc3413.711ce8","type":"debug","z":"cb92b403.8033c8","name":"telegram sender debug","active":true,"console":"true","complete":"true","x":1335,"y":435,"wires":[]},{"id":"16e3f86c.3c1c38","type":"json","z":"cb92b403.8033c8","name":"","pretty":false,"x":870,"y":335,"wires":[["fe44a336.896d9","42171d1.aed23e4"]]},{"id":"fe44a336.896d9","type":"switch","z":"cb92b403.8033c8","name":"Check command is not sensorstatus","property":"payload.command","propertyType":"msg","rules":[{"t":"eq","v":"sensorstatus","vt":"str"}],"checkall":"true","outputs":1,"x":1010,"y":180,"wires":[["22deb1ca.607f2e"]]},{"id":"42171d1.aed23e4","type":"debug","z":"cb92b403.8033c8","name":"","active":true,"console":"false","complete":"false","x":1066.9999999999998,"y":355.99999999999994,"wires":[]},{"id":"a41a06bf.598b68","type":"debug","z":"cb92b403.8033c8","name":"Forward web command via Telegram","active":true,"console":"false","complete":"payload","x":1550.5,"y":246,"wires":[]},{"id":"f57016d8.225158","type":"inject","z":"cb92b403.8033c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":190,"y":220,"wires":[["4c406b8c.164fb4"]]},{"id":"3d527c56.779904","type":"switch","z":"39fe4e64.ac2042","name":"Check msg is not null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":277,"y":106,"wires":[["7f6c6c95.077df4"],[]]},{"id":"7f6c6c95.077df4","type":"function","z":"39fe4e64.ac2042","name":"add command to commandsQueue","func":"var commands = global.get(\"commandsQueue\");\n\nif (typeof commands == 'undefined'){\n commands = [];\n}\n\nvar commandToAdd = msg.payload.command.toString().toLowerCase();\n\nvar found = commands.includes(commandToAdd);\n\nif(!found){\n \n node.warn(\"command \"+ commandToAdd + \" not found, adding it to the queue\");\n \n if(commandToAdd === \"sensorstatus\"){\n commands.unshift(commandToAdd);\n } else {\n commands.push(commandToAdd);\n }\n \n global.set(\"commandsQueue\",commands);\n \n} else {\n node.warn(\"command \"+ commandToAdd + \" already in queue! Wasting..\");\n}\n\nnode.warn(\"commandsQueue=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length + \", commandRunning=\" + global.get(\"commandRunning\"));\n\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":100,"wires":[["5ff16fc7.87b5e"]]},{"id":"5ff16fc7.87b5e","type":"debug","z":"39fe4e64.ac2042","name":"","active":true,"console":"false","complete":"false","x":910,"y":100,"wires":[]},{"id":"364ab04d.9ac97","type":"function","z":"4cec58dc.b0b798","name":"display commandsQueue debug","func":"node.warn(\"commandsQueue=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length + \", commandRunning=\" + global.get(\"commandRunning\"));\n\nvar msg = \"\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1110,"y":560,"wires":[["cf719fe6.edf0d"]]},{"id":"cf719fe6.edf0d","type":"debug","z":"4cec58dc.b0b798","name":"display commandsQueue debug","active":true,"console":"false","complete":"payload","x":1424.5,"y":618,"wires":[]},{"id":"7506618c.a1d8e","type":"switch","z":"cb92b403.8033c8","name":"Check commandsQueue length > 0","property":"commandsQueue.length","propertyType":"global","rules":[{"t":"gt","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":380,"wires":[["74af21d0.c6fa5"]]},{"id":"4c406b8c.164fb4","type":"switch","z":"cb92b403.8033c8","name":"Check commandRunning is false","property":"commandRunning","propertyType":"global","rules":[{"t":"false"},{"t":"null"}],"checkall":"true","outputs":2,"x":340,"y":300,"wires":[["7506618c.a1d8e"],["7506618c.a1d8e"]]},{"id":"4215b5ab.b4713c","type":"link in","z":"39fe4e64.ac2042","name":"Add command to commandsQueue","links":["754dcc79.61cef4","c5b90144.33989","41494733.cc0df8","c1bf40c8.29492","ed931aa.e4ebde8","97c264fd.6b76f8","493b94c3.83fb4c","a8b08f76.e8009","af6643f6.fd5ac","2b3a4fd5.4b317","fe9baa4b.ce3dc8"],"x":95,"y":106,"wires":[["3d527c56.779904"]]},{"id":"94507cc4.3d8a9","type":"switch","z":"4cec58dc.b0b798","name":"TIME_REQUEST","property":"payload.command","propertyType":"msg","rules":[{"t":"eq","v":"TIME_REQUEST","vt":"str"},{"t":"else"}],"checkall":"true","outputs":2,"x":644.5,"y":364,"wires":[["d36fe54.a0cae18"],[]]},{"id":"d36fe54.a0cae18","type":"exec","z":"4cec58dc.b0b798","command":"/usr/bin/sudo","addpay":false,"append":"date +T%s","useSpawn":"false","timer":"","oldrc":false,"name":"date","x":834.5,"y":360.5,"wires":[["162d64b4.7b3f1b","18aa9625.799caa"],[],[]]},{"id":"162d64b4.7b3f1b","type":"debug","z":"4cec58dc.b0b798","name":"date debug","active":true,"console":"false","complete":"payload","x":1034.5,"y":324,"wires":[]},{"id":"18aa9625.799caa","type":"function","z":"4cec58dc.b0b798","name":"set time_response command","func":"node.warn(\"time_response=\" + msg.payload.toString().substring(0,msg.payload.length-1));\n\nvar newmsg = { payload: \n {\n command: \"time_response\" + msg.payload.toString().substring(0,msg.payload.length-1)// Can either be string or byte array. \n } \n};\n\nreturn newmsg;","outputs":1,"noerr":0,"x":1097,"y":411,"wires":[["a1ce8e33.0e601","b06b395f.1f5d68"]]},{"id":"b06b395f.1f5d68","type":"function","z":"4cec58dc.b0b798","name":"add time_response to commandsQueue","func":"var commands = global.get(\"commandsQueue\");\n\nif (typeof commands == 'undefined'){\n commands = [];\n}\n\nvar commandToAdd = msg.payload.command.toString().toLowerCase();\n\nvar found = commands.includes(commandToAdd);\n\nif(!found){\n \n node.warn(\"command \"+ commandToAdd + \" not found, adding it to the queue\");\n \n commands.unshift(commandToAdd);\n \n global.set(\"commandsQueue\",commands);\n \n} else {\n node.warn(\"command \"+ commandToAdd + \" already in queue! Wasting..\");\n}\n\nnode.warn(\"commandsQueue=\" + global.get(\"commandsQueue\").toString() + \", length=\" + global.get(\"commandsQueue\").length + \", commandRunning=\" + global.get(\"commandRunning\"));\n\nreturn msg;","outputs":1,"noerr":0,"x":1320,"y":480,"wires":[[]]},{"id":"a1ce8e33.0e601","type":"debug","z":"4cec58dc.b0b798","name":"","active":true,"console":"false","complete":"false","x":1350.5,"y":387,"wires":[]},{"id":"4dea6ac0.8b10b4","type":"inject","z":"1fb4a826.643528","name":"forcescanfishbed","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":178,"y":125,"wires":[["3abb08f4.ba4b48"]]},{"id":"3abb08f4.ba4b48","type":"function","z":"1fb4a826.643528","name":"set forcescanfishbed command","func":"var msg = { payload: \n {\n command: \"forcescanfishbed\" // Can either be string or byte array. \n } \n};\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":300,"wires":[["41494733.cc0df8"]]},{"id":"41494733.cc0df8","type":"link out","z":"1fb4a826.643528","name":"","links":["4215b5ab.b4713c"],"x":675,"y":300,"wires":[]},{"id":"49e87615.97f958","type":"function","z":"4b81fb0f.775f54","name":"create question","func":"msg.payload.type = 'message';\nmsg.payload.content = 'Really?';\nmsg.payload.options = {reply_to_message_id : msg.payload.messageId}\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":486.6666564941406,"y":2304.4443359375,"wires":[["5f0dc844.9dca88"]]},{"id":"8858af9b.336e4","type":"telegram command","z":"4b81fb0f.775f54","name":"/forcescanfishbed","command":"/forcescanfishbed","bot":"2ef313b0.86cd1c","strict":false,"x":350,"y":2240,"wires":[["49e87615.97f958"],[]]},{"id":"5f0dc844.9dca88","type":"telegram sender","z":"4b81fb0f.775f54","name":"send question","bot":"2ef313b0.86cd1c","x":586.6666564941406,"y":2364.4443359375,"wires":[["224c10f7.32329"]]},{"id":"224c10f7.32329","type":"telegram reply","z":"4b81fb0f.775f54","name":"get reply","bot":"2ef313b0.86cd1c","x":686.6666564941406,"y":2424.4443359375,"wires":[["382a0314.15964c","b49a591e.8fd7d8"]]},{"id":"382a0314.15964c","type":"function","z":"4b81fb0f.775f54","name":"switch answer","func":"if(msg.payload.content === 'yes')\n{\n msg.payload.command = 'forcescanfishbed';\n return [msg, null]; \n}\nelse\n{\n return [null, msg]; \n}\n","outputs":"2","noerr":0,"x":806.6666564941406,"y":2504.4443359375,"wires":[["c1bf40c8.29492"],[]]},{"id":"c1bf40c8.29492","type":"link out","z":"4b81fb0f.775f54","name":"","links":["4215b5ab.b4713c"],"x":1021.6666564941406,"y":2498.4443359375,"wires":[]},{"id":"2429492b.4bc436","type":"switch","z":"4cec58dc.b0b798","name":"restart","property":"payload.command","propertyType":"msg","rules":[{"t":"eq","v":"restart","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":480,"wires":[["836235da.4768a8","b0fe74f4.1e5938"],[]]},{"id":"836235da.4768a8","type":"debug","z":"4cec58dc.b0b798","name":"restart command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":780,"y":480,"wires":[]},{"id":"b0fe74f4.1e5938","type":"exec","z":"4cec58dc.b0b798","command":"kill $(pidof node-red)","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Restart Node-RED command","x":820,"y":580,"wires":[[],[],[]]},{"id":"b49a591e.8fd7d8","type":"debug","z":"4b81fb0f.775f54","name":"get reply","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":920,"y":2420,"wires":[]},{"id":"a8adf386.cb1fb","type":"debug","z":"4cec58dc.b0b798","name":"aquaponicsensor payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":760,"wires":[]}]