I'm sorry, I could not be more specific in the previuos post. I just posted a small portion of my flow in the previous post.
[{"id":"223ced0e.462472","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"47ecb492.c9102c","type":"http in","z":"223ced0e.462472","name":"","url":"/hello-json","method":"get","upload":false,"swaggerDoc":"","x":380,"y":900,"wires":[["7a118fd5.d3ddc"]]},{"id":"d8d2976e.972a98","type":"change","z":"223ced0e.462472","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":900,"wires":[["2d66c3bc.4e255c"]]},{"id":"2d66c3bc.4e255c","type":"http response","z":"223ced0e.462472","name":"","statusCode":"","headers":{},"x":870,"y":900,"wires":[]},{"id":"7a118fd5.d3ddc","type":"template","z":"223ced0e.462472","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{ \"ip\": \"10.0.9.37\", \"rssi\": \"54\", \"tc\": \"37.1\", \"insol\": \"543\", \"imot\": 0.06, \"volt\": \"26.9\", \"modrv\": \"0\", \"hotp\": \"146\", \"timesrc\": \"1\", \"drvprb\": \"\", \"sv30\": \"\", \"sv20\": \"\", \"exmma\": \"\", \"imma\": \"\", \"tsl\": \"\", \"lc\": \"\", \"tcm\": \"\", \"rtc\": \"\", \"hmc\": \"\", \"dte\": \"\", \"dtw\": \"\", \"inclu\": \"\", \"incld\": \"\", \"tpf\": \"\", \"tpd\": \"\", \"mdf\": \"\", \"mdd\": \"\", \"lwf\": \"\", \"lwd\": \"\", \"dorop\": \"\", \"dorcl\": \"\", \"lmc\": \"\", \"dailyt\": \"\", \"incl\": \"\", \"tp\": \"\", \"md\": \"\", \"lw\": \"\", \"dor\": \"\" }, { \"ip\": \"10.0.4.18\", \"rssi\": \"62\", \"tc\": \"33.4\", \"insol\": \"543\", \"imot\": 0, \"volt\": \"24.7\", \"modrv\": \"0\", \"hotp\": \"144\", \"timesrc\": \"1\", \"drvprb\": \"\", \"sv30\": \"\", \"sv20\": \"\", \"exmma\": \"\", \"imma\": \"\", \"tsl\": \"\", \"lc\": \"\", \"tcm\": \"\", \"rtc\": \"\", \"hmc\": \"\", \"dte\": \"\", \"dtw\": \"\", \"inclu\": \"\", \"incld\": \"\", \"tpf\": \"\", \"tpd\": \"\", \"mdf\": \"\", \"mdd\": \"\", \"lwf\": \"\", \"lwd\": \"\", \"dorop\": \"\", \"dorcl\": \"\", \"lmc\": \"\", \"dailyt\": \"\", \"incl\": \"\", \"tp\": \"\", \"md\": \"\", \"lw\": \"\", \"dor\": \"\" }","output":"str","x":560,"y":900,"wires":[["d8d2976e.972a98"]]},{"id":"9da811d0.2c8e8","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":200,"wires":[]},{"id":"95a1669b.53a008","type":"udp in","z":"223ced0e.462472","name":"receiver","iface":"","port":"12345","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":330,"y":200,"wires":[["9da811d0.2c8e8","4235acd8.779a44"]]},{"id":"bc483968.c64bf8","type":"comment","z":"223ced0e.462472","name":"1) UDP messages from sensors & camera are received here","info":"","x":520,"y":140,"wires":[]},{"id":"4235acd8.779a44","type":"function","z":"223ced0e.462472","name":"Fetch_info_data_json","func":"var diship19 = flow.get('diship19') || 0;\nvar diship18 = flow.get('diship18') || 0;\nvar diship20 = flow.get('diship20') || 0;\nvar diship21 = flow.get('diship21') || 0;\nvar diship22 = flow.get('diship22') || 0;\nvar diship23 = flow.get('diship23') || 0;\nvar diship11 = flow.get('diship11') || 0;\nvar diship16 = flow.get('diship16') || 0;\n\nvar infoArr;\nvar info = msg.payload;\nvar errbuf;\nvar drnoArr;\nvar imot;\nvar volt;\nvar insol;\nvar rot_angl;\nvar temp;\nvar motordrv;\nvar hotp;\nvar errorflag;\nvar rssi;\nvar power;\nvar timesrc;\nvar ip;\nvar tc;\n\nvar drvprb;\nvar sv30;\nvar sv20;\nvar ct;\nvar hmc;\nvar dte;\nvar dtw;\nvar inclu;\nvar incld;\nvar tpf;\nvar tpd;\nvar mdf;\nvar mdd;\nvar lwf;\nvar lwd;\nvar dorop;\nvar dorcl;\n\nvar lmc;\nvar dailyt;\nvar incl;\nvar tp;\nvar md;\nvar lw;\nvar dor;\nvar exmma;\nvar imma;\nvar tsl;\nvar lc;\nvar tcm;\nvar rtc;\nvar NULL;\n\n\nconst conditionsArray = [\n (msg.ip !== diship19), \n (msg.ip !== diship18),\n (msg.ip !== diship20),\n (msg.ip !== diship21), \n (msg.ip !== diship22),\n (msg.ip !== diship23),\n (msg.ip !== diship11),\n (msg.ip !== diship16),\n (msg.ip !== \"10.0.0.18\"), \n (msg.ip !== \"10.0.0.19\"),\n (msg.ip !== \"10.0.0.20\"),\n (msg.ip !== \"10.0.0.21\"), \n (msg.ip !== \"10.0.0.22\"),\n (msg.ip !== \"10.0.0.23\"),\n (msg.ip !== \"10.0.65.11\"),\n (msg.ip !== \"10.0.0.16\"),\n]\n\n\nif (conditionsArray.indexOf(false) === -1) {\n \n infoArr = info.split(';');\n errbuf = Buffer.from(info);\n imot = infoArr[2]/100;\n volt = infoArr[3];\n insol = infoArr[4];\n temp = infoArr[5];\n rot_angl = infoArr[6];\n motordrv = infoArr[8];\n hotp = infoArr[11];\n errorflag = infoArr[18];\n rssi = infoArr[23];\n power = infoArr[24];\n timesrc = infoArr[27];\n //msg.payload = errbuf[0];\n \n} else {\n \n return [null];\n}\n\n ip = msg.ip;\n drnoArr = msg.ip.split('.');\n var dno = drnoArr[3];\n var num = Number(drnoArr[2]) + Number(64);\n var rno = String.fromCharCode(num);\n\n\n if ((errorflag & (Math.pow(2, 3))) > 0) {\n drvprb = \"Driver problem\";\n } else {\n drvprb = \"\";\n }\n \n if ((errorflag & (Math.pow(2, 4))) > 0) {\n sv30 = \"Supply voltage >30V\";\n } else {\n sv30 = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 5))) > 0) {\n sv20 = \"Supply voltage <20V\";\n } else {\n sv20 = \"\";\n }\n \n if ((errorflag & (Math.pow(2, 6))) > 0) {\n ct = \"Chip temperature >70°C\";\n } else {\n ct = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 0))) > 0) {\n hmc = \"High motor current\"; \n } else { \n if (hmc === undefined){\n hmc = \"\";\n } \n } \n \n if ((errorflag & (Math.pow(2, 8))) > 0) {\n dte = \"Daily tracking east\";\n } else {\n dte = \"\";\n } \n\n if ((errorflag & (Math.pow(2, 7))) > 0) {\n dtw = \"Daily tracking west\";\n } else {\n dtw = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 9))) > 0) {\n inclu = \"Inclination up\";\n } else {\n inclu = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 10))) > 0) {\n incld = \"Inclination down\";\n } else {\n incld = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 11))) > 0) {\n tpf = \"Top flat\";\n } else {\n tpf = \"\";\n }\n\n if ((errorflag & (Math.pow(2 ^ 12))) > 0) {\n tpd = \"Top deep\";\n } else {\n tpd = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 13))) > 0) {\n mdf = \"Mid flat\";\n } else {\n mdf = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 14)) > 0)) {\n mdd = \"Mid deep\";\n } else {\n mdd = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 15))) > 0) {\n lwf = \"Low flat\";\n } else {\n lwf = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 16))) > 0) {\n lwd = \"Low deep\";\n } else {\n lwd = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 17))) > 0) {\n dorop =\"Door open\";\n } else {\n dorop = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 18))) > 0) {\n dorcl =\"Door close\";\n } else {\n dorcl = \"\";\n }\n\n\tif ((errorflag & (Math.pow(2, 2))) > 0) {\n\t lmc = \"Low motor current\";\n\t} else {\n\t lmc = \"\";\n\t}\n\n if ((errorflag & (Math.pow(2, 19))) > 0) {\n dailyt = \"Daily tracking\";\n } else {\n dailyt = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 20))) > 0) {\n incl = \"Inclination\";\n } else {\n incl = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 21))) > 0) {\n tp = \"Top\";\n } else {\n tp = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 22))) > 0 ) {\n md = \"Mid\";\n } else {\n md = \"\";\n }\n \n\n if ((errorflag & (Math.pow(2, 23))) > 0) {\n lw = \"Low\";\n } else {\n lw = \"\";\n }\n\n if ((errorflag & (Math.pow(2, 24))) > 0) {\n dor = \"Door\";\n } else {\n dor = \"\";\n }\n \n if (((errorflag & (Math.pow(2, 25))) === 0) && (errbuf[0] == 3)) {\n exmma = \"External MMA8452 failed\";\n } else {\n exmma = \"\";\n }\n\n if (((errorflag & (Math.pow(2, 26))) === 0) && (errbuf[0] == 3)) {\n imma = \"Internal MMA8452 failed\";\n } else {\n imma = \"\";\n }\n\n if (((errorflag & (Math.pow(2, 27))) === 0) && (errbuf[0] == 3)) {\n tsl = \"TSL256 failed\";\n } else {\n tsl = \"\";\n }\n\n if (((errorflag & (Math.pow(2, 28))) === 0) && (errbuf[0] == 3)) {\n lc = \"24LC16 failed\";\n } else {\n lc = \"\";\n }\n\n if (((errorflag & (Math.pow(2, 29))) === 0) && (errbuf[0] == 3)) {\n tcm = \"TCM8240 failed\";\n } else {\n tcm = \"\";\n }\n\n if (((errorflag & (Math.pow(2, 30))) === 0) && (errbuf[0] == 3)) {\n rtc = \"RTC error\";\n } else {\n rtc = \"\";\n }\n\n\nif (errbuf[0] == 3) {\n var myJSON = {ip: msg.ip,rssi: rssi,tc: temp,insol: insol,imot: imot,volt: volt,modrv: motordrv,hotp: hotp,timesrc: timesrc,drvprb: drvprb,sv30: sv30,sv20: sv20,exmma: exmma,imma: imma,tsl: tsl,lc: lc,tcm: tcm,rtc: rtc,hmc: hmc,dte: dte,dtw: dtw,inclu: inclu,incld: incld,tpf: tpf,tpd: tpd,mdf: mdf,mdd: mdd,lwf: lwf,lwd: lwd,dorop: dorop,dorcl: dorcl,lmc: lmc,dailyt: dailyt,incl: incl,tp: tp,md: md,lw: lw,dor: dor};\n\n msg.payload = myJSON;\n \n var newMsg = {topic: \"INSERT INTO info (ipadd, imot, volt, insol, rot_angl, mo_drv, hpx, rssi, timesrc, drvprb, sv3, sv2, exmma, imma, tsl, lc, tcm, rtc, hmc, dte, dtw, inclu, incld, tpf, tpd, mdf, mdd, lwf, lwd, lmc, dailyt, incl, tp, md, lw, dno, rno) VALUES ('\"+ ip +\"', '\"+ imot +\"', '\"+ volt +\"', '\"+ insol +\"', '\"+ rot_angl +\"', '\"+ motordrv +\"', '\"+ hotp +\"', '\"+ rssi +\"', '\"+ timesrc +\"', '\"+ drvprb +\"', '\"+ sv30 +\"', '\"+ sv20 +\"', '\"+ exmma +\"', '\"+ imma +\"', '\"+ tsl +\"', '\"+ lc +\"', '\"+ tcm +\"', '\"+ rtc +\"', '\"+ hmc +\"', '\"+ dte +\"', '\"+ dtw +\"', '\"+ inclu +\"', '\"+ incld +\"', '\"+ tpf +\"', '\"+ tpd +\"', '\"+ mdf +\"', '\"+ mdd +\"', '\"+ lwf +\"', '\"+ lwd +\"', '\"+ lmc +\"', '\"+ dailyt +\"', '\"+ incl +\"', '\"+ tp +\"', '\"+ md +\"', '\"+ lw +\"', '\"+ dno +\"', '\"+ rno +\"')\"};\n return [newMsg, msg];\n \n}else{\n \n return [null,null];\n}\n\n\nreturn [newMsg, msg];\n","outputs":2,"noerr":0,"x":400,"y":300,"wires":[["a54dc2ce.a7b5"],["60aff87e.29ba38","14f2be9d.233cf1"]]},{"id":"e9bfec2.436a11","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":320,"wires":[]},{"id":"a54dc2ce.a7b5","type":"mysql","z":"223ced0e.462472","mydb":"59d95a8f.fc3194","name":"","x":700,"y":320,"wires":[["e9bfec2.436a11"]]},{"id":"60aff87e.29ba38","type":"debug","z":"223ced0e.462472","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":551.4285888671875,"y":430,"wires":[]},{"id":"a7ec5679.219a98","type":"json","z":"223ced0e.462472","name":"","property":"payload","action":"str","pretty":true,"x":810,"y":480,"wires":[["fd02d274.853d2","40332400.384cec"]]},{"id":"fd02d274.853d2","type":"DataIn","z":"223ced0e.462472","collection":"c9de68d4.2e9f18","name":"deb","update":false,"path":"/","x":890,"y":540,"wires":[]},{"id":"14f2be9d.233cf1","type":"function","z":"223ced0e.462472","name":"capture data","func":"var index = (flow.get(\"udpindex\") || 0);\nvar udpdata = flow.get(\"udpdata\") || [];\n\nudpdata[index] = msg.payload;\n\nindex++;\nflow.set(\"udpindex\", index);\nflow.set(\"udpdata\", udpdata);\n\n\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":480,"wires":[["ab7d8285.6fb7a"]]},{"id":"ab7d8285.6fb7a","type":"change","z":"223ced0e.462472","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"udpdata","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":600,"wires":[["a7ec5679.219a98"]]},{"id":"40332400.384cec","type":"debug","z":"223ced0e.462472","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":702.5,"y":420,"wires":[]},{"id":"5f4ad968.a8d068","type":"function","z":"223ced0e.462472","name":"","func":"msg.payload = \": \" + msg.payload;\nmsg.payload = '\"DISH\"' + msg.payload;\nmsg.payload = \"{ \" + msg.payload;\nmsg.payload = msg.payload + \" }\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":500,"wires":[[]]},{"id":"7590d7fe.f8ab38","type":"http in","z":"223ced0e.462472","name":"","url":"/deb","method":"get","upload":false,"swaggerDoc":"","x":440,"y":740,"wires":[["37df543b.08bb2c"]]},{"id":"5f6fdbec.24fed4","type":"http response","z":"223ced0e.462472","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":750,"y":740,"wires":[]},{"id":"37df543b.08bb2c","type":"DataOut","z":"223ced0e.462472","collection":"c9de68d4.2e9f18","name":"deb","path":"/","error":true,"x":590,"y":740,"wires":[["5f6fdbec.24fed4"]]},{"id":"354a764b.78139a","type":"comment","z":"223ced0e.462472","name":"Sensors data is stored here in json file","info":"","x":1030,"y":620,"wires":[]},{"id":"6600f282.93264c","type":"comment","z":"223ced0e.462472","name":"2) Sensors data is sent to http response","info":"","x":370,"y":700,"wires":[]},{"id":"87b66ea5.57dbf","type":"comment","z":"223ced0e.462472","name":"3) Trying to query data here","info":"Out of the total data received in json file we are trying to query for a particular data, identified by a unique identifier - ip address of the sensor in this case. ","x":315.71429443359375,"y":815.7142944335938,"wires":[]},{"id":"59d95a8f.fc3194","type":"MySQLdatabase","z":"","name":"Ima_21","host":"10.0.64.21","port":"3306","db":"IMATRACK","tz":""},{"id":"c9de68d4.2e9f18","type":"json-db-collection","z":"","name":"deb","collection":"deb","save":true}]
Now I have attached my entire flow here. By going through the flow you might understand what I'm trying to achieve. My flow could be divided into the following parts -
-
Getting sensor data in UDP and sending it to database and json file.
-
The stored data in json file is then sent to http response
-
Trying to query for a particular data.
We are not fetching data from any API, rather we are trying to create an API out of the data we are receiving from the sensors. I think this makes sense.
Now the problematic part is the third part in the flow where out of the total data received in json file we are trying to query for a particular data, identified by a unique identifier - "ip address" of the sensor in this case. But when we try to do so we are getting error and not getting the desired result.
Thanks in advance.