-
Notifications
You must be signed in to change notification settings - Fork 0
/
flows.json
1 lines (1 loc) · 12.2 KB
/
flows.json
1
[{"type":"tab","id":"9dd46f05.622b9","label":"Sheet 1"},{"type":"tab","id":"e310b1d0.1cef5","label":"Sheet 2"},{"id":"114c2a58.eeb3d6","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"e8630dd4.179cf","type":"postgresdb","hostname":"localhost","port":"5432","db":"sociopatterns1"},{"id":"592cc43a.a6d33c","type":"websocket-listener","path":"","wholemsg":"false"},{"id":"dfa1be41.205e4","type":"udp in","name":"","iface":"","port":"2342","datatype":"buffer","multicast":"false","group":"","x":103,"y":42,"z":"9dd46f05.622b9","wires":[["38ef3b06.c710c4","98107d14.67ef8"]]},{"id":"8f02d749.70fd28","type":"debug","name":"contacts","active":false,"console":"false","complete":"false","x":1008,"y":429,"z":"9dd46f05.622b9","wires":[]},{"id":"727b4cec.8d84b4","type":"switch","name":"","property":"packet_proto","rules":[{"t":"eq","v":24,"v2":0},{"t":"eq","v":69,"v2":0},{"t":"else"}],"checkall":"false","outputs":3,"x":337,"y":626,"z":"9dd46f05.622b9","wires":[["9fc49de5.603b6"],["c3e6bdc4.3c194"],["ebfdf731.140208"]]},{"id":"c3e6bdc4.3c194","type":"function","name":"parse contact packet","func":"buf = msg.payload.packet_raw;\n\nseen_list= []\n\nseen_list.push( buf.readUInt16BE(6) );\nseen_list.push( buf.readUInt16BE(8) );\nseen_list.push( buf.readUInt16BE(10) );\n\nvar contact_list = [];\nvar tag_list = [];\n\nfor (index = 0; index < 3; ++index) {\n\tseen = seen_list[index];\n\t\n seen_id = seen & 0x07FF;\n seen_pwr = seen >> 14;\n seen_cnt = (seen >> 11) & 0x07;\n \n if (seen_id != 0) {\n \tcontact_list.push( [seen_id, seen_pwr, seen_cnt] );\n \ttag_list.push(seen_id);\n }\t\n}\n\nvar packet = {\n\ttype: \"contact\",\n\tproto: buf.readUInt8(0),\n\tid: buf.readUInt16BE(1),\n\tboot_count: buf.readUInt16BE(3),\n\tflags: buf.readUInt8(5),\n\tcontacts: contact_list,\n\tseq: buf.readUInt16BE(12),\n\tcrc: buf.readUInt16BE(14)\n\t};\n\t\nmsg.payload.packet = packet;\n\ntag_list.push(packet.id);\nmsg.payload.tags = tag_list;\n\ndelete msg.packet_proto;\n\nreturn msg;\n","outputs":1,"x":596,"y":627,"z":"9dd46f05.622b9","wires":[["8f02d749.70fd28","cded5f5b.3212a","d0baaecd.2f455","f460b074.0b9f5"]]},{"id":"98107d14.67ef8","type":"debug","name":"","active":false,"console":"false","complete":"true","x":460,"y":42,"z":"9dd46f05.622b9","wires":[]},{"id":"9fc49de5.603b6","type":"function","name":"parse sighting packet","func":"var buf = msg.payload.packet_raw;\n\nvar packet = {\n\ttype: \"sighting\",\n\tproto: buf.readUInt8(0),\n\tid: buf.readUInt16BE(1),\n\tboot_count: buf.readUInt16BE(3),\n\tflags: buf.readUInt8(5),\n\tstrength: buf.readUInt8(6),\n\tid_last_seen: buf.readUInt16BE(7),\n\treserved: buf.readUInt8(9),\n\tseq: buf.readUInt32BE(10),\n\tcrc: buf.readUInt16BE(14)\n\t};\n\t\nmsg.payload.packet = packet;\nmsg.payload.tags = [ packet.id ];\n\ndelete msg.packet_proto;\n\nreturn msg;","outputs":1,"x":597,"y":566,"z":"9dd46f05.622b9","wires":[["c2684c2a.3d97b","b9c9419d.4636c","7e304dd0.81cfb4","f460b074.0b9f5"]]},{"id":"ebfdf731.140208","type":"debug","name":"invalid protocol","active":true,"console":"false","complete":"true","x":581,"y":699,"z":"9dd46f05.622b9","wires":[]},{"id":"c2684c2a.3d97b","type":"debug","name":"sightings","active":false,"console":"false","complete":"false","x":1010,"y":364,"z":"9dd46f05.622b9","wires":[]},{"id":"98e8491a.6717b8","type":"debug","name":"packet CRC error","active":true,"console":"false","complete":"false","x":981,"y":140,"z":"9dd46f05.622b9","wires":[]},{"id":"a3208e84.5cdf7","type":"function","name":"parse reader envelope","func":"var buf = msg.payload;\n\nvar reader_info = {\n\tcrc: buf.readUInt16BE(0),\n\tproto: buf.readUInt8(2),\n\tiface: buf.readUInt8(3),\n\tid: buf.readUInt16BE(4),\n\tsize: buf.readUInt16BE(6),\n\tseq: buf.readUInt32BE(8),\n\ttimestamp: buf.readUInt32BE(12),\n\tip: msg.ip\n\t};\n\t\nvar packet = buf.slice(16);\n\nvar newMsg = {\n\tpayload: {\n\t\ttimestamp: Date.now(),\n\t\treader_raw: buf,\n\t\tpacket_raw: packet,\n\t\treader: reader_info\n\t\t},\n\tpacket_proto: packet.readUInt8(0)\n\t};\n \nreturn newMsg;\n","outputs":1,"x":549,"y":189,"z":"9dd46f05.622b9","wires":[["a7a3edf1.585c1"]]},{"id":"e3f44179.1c0bc","type":"debug","name":"reader envelope CRC error","active":true,"console":"false","complete":"false","x":957,"y":72,"z":"9dd46f05.622b9","wires":[]},{"id":"38ef3b06.c710c4","type":"function","name":"check envelope CRC","func":"var buf = msg.payload;\n\nvar crc = 0xFFFF;\n\nfor (var i = 2; i < buf.length ; i++) {\n\tcrc = (crc >> 8) | ((crc << 8) & 0xFFFF);\n\tcrc = crc ^ buf[i];\n\tcrc = crc ^ ((crc & 0xFF) >> 4);\n\tcrc = crc ^ ((crc << 12) & 0xFFFF);\n\tcrc = crc ^ (((crc & 0xFF) << 5) & 0xFFFF);\n}\n\ncrc = crc ^ 0xFFFF;\n\nif (crc == buf.readUInt16BE(0)) {\n return [ msg, null ];\n} else {\n return [ null, msg ];\n}\n","outputs":"2","x":354,"y":106,"z":"9dd46f05.622b9","wires":[["a3208e84.5cdf7"],["e3f44179.1c0bc"]]},{"id":"fbb65c73.0449a","type":"debug","name":"","active":false,"console":"false","complete":"false","x":1026,"y":211,"z":"9dd46f05.622b9","wires":[]},{"id":"a7a3edf1.585c1","type":"function","name":"check packet CRC","func":"var buf = msg.payload.packet_raw;\n\nvar crc = 0xFFFF;\n\nfor (var i = 0; i < buf.length-2 ; i++) {\n\tcrc = (crc >> 8) | ((crc << 8) & 0xFFFF);\n\tcrc = crc ^ buf[i];\n\tcrc = crc ^ ((crc & 0xFF) >> 4);\n\tcrc = crc ^ ((crc << 12) & 0xFFFF);\n\tcrc = crc ^ (((crc & 0xFF) << 5) & 0xFFFF);\n}\n\nif (crc == buf.readUInt16BE(14)) {\n return [ msg, null ];\n} else {\n return [ null, msg ];\n}\n","outputs":"2","x":761,"y":279,"z":"9dd46f05.622b9","wires":[["fbb65c73.0449a","727b4cec.8d84b4"],["98e8491a.6717b8"]]},{"id":"b9c9419d.4636c","type":"function","name":"create tag sighting streams","func":"var newMsg = {\n\t\t'payload': msg.payload,\n\t\t'topic': \"sociopatterns/tag/\" + msg.payload.packet.id + \"/sighting\"\n\t\t};\n\t\t\nreturn newMsg;\n","outputs":1,"x":1039,"y":536,"z":"9dd46f05.622b9","wires":[["52e6bf9e.ad194"]]},{"id":"52e6bf9e.ad194","type":"mqtt out","name":"SocioPatterns streams","topic":"","broker":"114c2a58.eeb3d6","x":1384,"y":576,"z":"9dd46f05.622b9","wires":[]},{"id":"7e304dd0.81cfb4","type":"function","name":"create reader sighting streams","func":"var newMsg = {\n\t\t'payload': msg.payload,\n\t\t'topic': \"sociopatterns/reader/\" + msg.payload.reader.id + \"/sighting\"\n\t\t};\n\t\t\nreturn newMsg;\n\t\t","outputs":1,"x":1045,"y":586,"z":"9dd46f05.622b9","wires":[["52e6bf9e.ad194"]]},{"id":"cded5f5b.3212a","type":"function","name":"create reader contact streams","func":"var newMsg = {\n\t\t'payload': msg.payload,\n\t\t'topic': \"sociopatterns/reader/\" + msg.payload.reader.id + \"/contact\"\n\t\t};\n\t\t\nreturn newMsg;\n","outputs":1,"x":1043,"y":689,"z":"9dd46f05.622b9","wires":[["52e6bf9e.ad194"]]},{"id":"fa88ce18.05773","type":"postgres","postgresdb":"e8630dd4.179cf","name":"SocioPatterns DB","output":false,"outputs":0,"x":1398,"y":776,"z":"9dd46f05.622b9","wires":[]},{"id":"d0baaecd.2f455","type":"function","name":"create tag contact streams","func":"var msg_list = [];\n\nmsg_list.push(\n{\n\t'payload': msg.payload,\n\t'topic': \"sociopatterns/tag/\" + msg.payload.packet.id + \"/contact\"\n}\n);\n\nfor (i=0; i<msg.payload.tags.length; ++i) {\n\ttag_id = msg.payload.tags[i];\n\tvar newMsg = {\n\t\t'payload': msg.payload,\n\t\t'topic': \"sociopatterns/tag/\" + tag_id + \"/related\"\n\t\t};\n\t\n\tmsg_list.push(newMsg);\n}\n\nreturn [ msg_list ];\n","outputs":1,"x":1044,"y":636,"z":"9dd46f05.622b9","wires":[["52e6bf9e.ad194"]]},{"id":"f460b074.0b9f5","type":"json","name":"","x":878,"y":778,"z":"9dd46f05.622b9","wires":[["e99cdf60.16632"]]},{"id":"f963ac59.069c5","type":"debug","name":"","active":false,"console":"false","complete":"false","x":1396,"y":848,"z":"9dd46f05.622b9","wires":[]},{"id":"5b371e79.a4c8e","type":"inject","name":"test query","topic":"","payload":"INSERT INTO run1 VALUES ( '{\"reader_raw\":[144,23,1,0,1,161,0,32,0,1,154,40,5,190,162,33,24,6,107,0,5,0,1,7,32,0,0,226,85,161,149,117],\"packet_raw\":[24,6,107,0,5,0,1,7,32,0,0,226,85,161,149,117],\"reader\":{\"crc\":36887,\"proto\":1,\"iface\":0,\"id\":417,\"size\":32,\"seq\":105000,\"timestamp\":96379425,\"ip\":\"10.254.0.100\"},\"packet\":{\"type\":\"sighting\",\"proto\":24,\"id\":1643,\"boot_count\":5,\"flags\":0,\"strength\":1,\"id_last_seen\":1824,\"reserved\":0,\"seq\":14833057,\"crc\":38261},\"tags\":[1643]}' );","payloadType":"string","repeat":"","crontab":"","once":false,"x":1108,"y":843,"z":"9dd46f05.622b9","wires":[["fa88ce18.05773"]]},{"id":"e99cdf60.16632","type":"function","name":"write INSERT query","func":"newMsg = { payload: \"INSERT INTO run1 VALUES ( '\" + msg.payload + \"');\" };\n\nreturn newMsg;","outputs":1,"x":1085,"y":777,"z":"9dd46f05.622b9","wires":[["fa88ce18.05773","f963ac59.069c5"]]},{"id":"2d6f7310.d2908c","type":"debug","name":"","active":false,"console":"false","complete":"false","x":511,"y":90,"z":"e310b1d0.1cef5","wires":[]},{"id":"3c3b7663.c3c48a","type":"mqtt in","name":"contact events","topic":"sociopatterns/tag/+/contact","broker":"114c2a58.eeb3d6","x":186,"y":202,"z":"e310b1d0.1cef5","wires":[["2d6f7310.d2908c","7cac7aee.835384"]]},{"id":"3c067f83.c3f98","type":"inject","name":"test OBG packet","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":139,"y":260,"z":"9dd46f05.622b9","wires":[["79113f83.86eec"]]},{"id":"79113f83.86eec","type":"function","name":"create packet","func":"newMsg = {\n\tpayload: new Buffer([61,251,1,0,1,161,0,32,0,1,198,52,6,29,58,250,69,7,32,0,8,0,102,107,0,0,0,0,98,97,14,123]),\n\tip: \"10.254.0.2\"\n\t};\n\t\nreturn newMsg;","outputs":1,"x":294,"y":379,"z":"9dd46f05.622b9","wires":[["38ef3b06.c710c4"]]},{"id":"a72d04a9.58d2f8","type":"function","name":"build contact network","func":"if (context.contact_network == null)\n\tcontext.contact_network = {};\n\n\nif (msg.topic == \"clock\") {\n\tcontact_network_copy = context.contact_network;\n\tcontext.contact_network = {};\n\treturn {payload: contact_network_copy};\n}\n\npkt = msg.payload.packet;\ntag1 = pkt.id;\n\nif (! (tag1 in context.contact_network))\n\tcontext.contact_network[tag1] = {};\n\nif (pkt.contacts != null) {\n\tfor (var i=0; i<pkt.contacts.length; i++) {\n\t\tvar c = pkt.contacts[i];\n\t\tif (c[1] == 1) {\n\t\t\ttag2 = c[0];\n\t\t\tif (! (tag2 in context.contact_network[tag1]))\n\t\t\t \tcontext.contact_network[tag1][tag2] = 0;\n\t\t\t \t\n\t\t\tcontext.contact_network[tag1][tag2]++;\t\t\t\n\t\t}\n\t}\n}\n\n","outputs":1,"x":715,"y":259,"z":"e310b1d0.1cef5","wires":[["12aac6ce.ed5539"]]},{"id":"f4ce1d25.0b31e","type":"inject","name":"aggregator clock","topic":"clock","payload":"","payloadType":"date","repeat":"20","crontab":"","once":true,"x":212,"y":303,"z":"e310b1d0.1cef5","wires":[["a72d04a9.58d2f8"]]},{"id":"12aac6ce.ed5539","type":"debug","name":"","active":true,"console":"false","complete":"false","x":1053,"y":259,"z":"e310b1d0.1cef5","wires":[]},{"id":"7cac7aee.835384","type":"json","name":"","x":411,"y":202,"z":"e310b1d0.1cef5","wires":[["a72d04a9.58d2f8","bc94f3f5.436b1"]]},{"id":"f660bbc3.099f48","type":"inject","name":"presence clock","topic":"clock","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"x":283,"y":628,"z":"e310b1d0.1cef5","wires":[["bc94f3f5.436b1"]]},{"id":"bc94f3f5.436b1","type":"function","name":"arrival/departure","func":"if (context.presence == null)\n\tcontext.presence = {};\n\nif (context.presence_old == null)\n\tcontext.presence_old = {};\n\nif (msg.topic == \"clock\") {\n\tvar arrived = [];\n\tvar left = [];\n\t\n\tfor (var tag_id in context.presence) {\n\t\tif (! (tag_id in context.presence_old))\n\t\t\tarrived.push(tag_id);\n\t}\n\t\n\tfor (var tag_id in context.presence_old) {\n\t\tif (! (tag_id in context.presence))\n\t\t\tleft.push(tag_id);\n\t}\n\t\n\tcontext.presence_old = context.presence;\n\tcontext.presence = {};\n\t\n\treturn {payload: {arrived: arrived, left: left}};\n}\t\n\ntag_id = msg.payload.packet.id;\nt = msg.payload.timestamp;\n\ncontext.presence[tag_id] = t;\n","outputs":1,"x":709,"y":492,"z":"e310b1d0.1cef5","wires":[["12aac6ce.ed5539"]]},{"id":"88336b91.77cc98","type":"mqtt in","name":"sighting events","topic":"sociopatterns/tag/+/sighting","broker":"114c2a58.eeb3d6","x":185,"y":498,"z":"e310b1d0.1cef5","wires":[["f4e73817.0b18c8"]]},{"id":"f4e73817.0b18c8","type":"json","name":"","x":409,"y":498,"z":"e310b1d0.1cef5","wires":[["bc94f3f5.436b1"]]}]