[ { "id": "bfd8a0eb.33b9e", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"mag\"", "topic": "/ble/+/+/mag/#", "qos": "0", "broker": "1b431944.61f6af", "x": 90, "y": 100, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "9a04a604.5a6828", "type": "mqtt out", "z": "2511c21c.d364ee", "name": "mqtt \"mag\"", "topic": "", "qos": "1", "retain": "", "broker": "7882ae67.b58028", "x": 670, "y": 140, "wires": [] }, { "id": "480923bf.c49ac4", "type": "function", "z": "2511c21c.d364ee", "name": "/g/g/?/json/", "func": "//position [1]/ [2]/ [3]/[4]\n//example: ble/gateway/d3a2f322/mag\n//transform: g/ g/d3a2f322/mag\nvar words = msg.topic.split(\"/\");\nvar name_prefix = \"/g/g/\"\nvar name_suffix = \"/\"\nvar fulltopic = name_prefix + words[3]+\"/\"+words[4];\nvar newMsg = { topic: fulltopic};\nnewMsg.payload = msg.payload;\nreturn newMsg;\n", "outputs": 1, "noerr": 0, "x": 290, "y": 140, "wires": [ [ "b1deba96.ba375" ] ] }, { "id": "b1deba96.ba375", "type": "delay", "z": "2511c21c.d364ee", "name": "", "pauseType": "delay", "timeout": "100", "timeoutUnits": "milliseconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 490, "y": 140, "wires": [ [ "9a04a604.5a6828" ] ] }, { "id": "4bc37d0e.f13adc", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "de8a rssi", "topic": "/ble/+/f2a2df72de8a/rssi/#", "qos": "0", "broker": "1b431944.61f6af", "x": 80, "y": 420, "wires": [ [ "7911ca80.90f7cc" ] ] }, { "id": "dca59faf.2231b", "type": "function", "z": "2511c21c.d364ee", "name": "Global Variable Dog Location", "func": "var newMsg = { payload: msg.payload};\n//newMsg.topic=\"Nowhere\";\n//newMsg.payload=-110;\n\nvar dogLocGateway=\"Nowhere\";\n\n//var dogLocGateway= {payload: \"Nowhere\"};\n\nvar dogLocRSSI=-110;\n\n//dogLocRSSI=dogLocRSSI - 110.1;\n//var dogLocRSSI = {payload: \"-110\"};\n//global.set('dogLocGateway','NoWhere');\n//global.set('dogLocRSSI',5);\n\nglobal.set('dogLocGateway',msg.topic);\nglobal.set('dogLocRSSI',parseInt(msg.payload));\n\n//dogLocRSSI = -110;\nnode.warn(\"completed initialization\");\n//var dogLocGateway = this.context().global;\n//var dogLocRSSI = this.context().global;\n//var dogLocGateway = new Array(10);\n//var dogLocRSSI = new Array(10);\n//var dogLocTail = this.context().flow;\n//dogLocTail = 0;\n\n//flow.set(“dogLocGateway”,1);\n//flow.set(“dogLocRSSI”,1);\n//flow.set(“dogLocTail”,1);\n\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 380, "y": 320, "wires": [ [] ] }, { "id": "9fb7559.f1b3328", "type": "inject", "z": "2511c21c.d364ee", "name": "started", "topic": "NoWhere", "payload": "-110", "payloadType": "num", "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "x": 120, "y": 320, "wires": [ [ "dca59faf.2231b" ] ] }, { "id": "7911ca80.90f7cc", "type": "function", "z": "2511c21c.d364ee", "name": "save the strongest rssi", "func": "var newMsg = { payload: msg.payload};\n\n//get the previous strongest rssi value\nvar rssi_so_far = parseInt(global.get('dogLocRSSI'));\n\n//get the current RSSI\nvar incoming_rssi = parseInt(msg.payload);\n\nif (rssi_so_far < incoming_rssi) //replace\n{\n node.status({fill:\"red\",shape:\"ring\",text:\"replaced\"});\n \n //grab the gateway value to save\n //position [1]/ [2]/ [3]/[4]\n //example: ble/gateway/f2a2df72de8a/mag\n var words = msg.topic.split(\"/\");\n global.set('dogLocGateway', words[2]);\n global.set('dogLocRSSI', parseInt(incoming_rssi));\n\n newMsg.payload = incoming_rssi;\n newMsg.topic = words[2];\n node.warn(\"rssi bigger than data, replaced\");\n}\nelse\n{\n newMsg.payload = parseInt(global.get('dogLocRSSI'));\n newMsg.topic = global.get('dogLocGateway');\n node.status({fill:\"green\",shape:\"ring\",text:\"not replaced\"});\n //node.warn(\"no, rssi is smaller than data\");\n}\n\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 380, "y": 420, "wires": [ [] ] }, { "id": "d32a96ae.174368", "type": "debug", "z": "2511c21c.d364ee", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 650, "y": 420, "wires": [] }, { "id": "9821a4ed.3f853", "type": "comment", "z": "2511c21c.d364ee", "name": "Minimum RSSI", "info": "Place with minimum RSSI to interpret as \"present\"", "x": 100, "y": 360, "wires": [] }, { "id": "4de504c0.4cf70c", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"DIS\"", "topic": "/ble/+/+/DIS/#", "qos": "0", "broker": "1b431944.61f6af", "x": 90, "y": 160, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "4c634136.e77648", "type": "comment", "z": "2511c21c.d364ee", "name": "Global Sensor Topics - All Gateways", "info": "Take all MQTT topics originating from different BLE/LoRa gateways and publish all to the same generic topic.\n\nExample:\n/ble/livingroom/AABBCCDDEE/mag 1\n/ble/bathroom /AABBCCDDEE/mag 1\n/g / g /AABBCCDDEE/mag 1\n\nGenerically:\n/ble/**gateway / MAC Addr /json value\n/g / g / \" \" /\" \" \"\"\n\n", "x": 160, "y": 60, "wires": [] }, { "id": "d13b291d.7b402", "type": "inject", "z": "2511c21c.d364ee", "name": "Every 5 minutes", "topic": "/rssi_5_minutes", "payload": "", "payloadType": "date", "repeat": "180", "crontab": "", "once": false, "onceDelay": 0.1, "x": 130, "y": 500, "wires": [ [ "aca17f00.d6f62" ] ] }, { "id": "4c85a6cc.6aacd", "type": "mqtt out", "z": "2511c21c.d364ee", "name": "Dog Location", "topic": "/g/g/f2a2df72de8a/location", "qos": "", "retain": "", "broker": "d602c15f.8da268", "x": 610, "y": 500, "wires": [] }, { "id": "aca17f00.d6f62", "type": "function", "z": "2511c21c.d364ee", "name": "publish Location", "func": "var newMsg = { payload: msg.payload};\n\n//grab the gateway name with top rssi\nnewMsg.topic = \"/g/g/f2a2df72de8a/location\"\nnewMsg.payload = global.get('dogLocGateway');\n\n//reset the saved rssi and gateway\nglobal.set('dogLocGateway', \"Nowhere\");\nglobal.set('dogLocRSSI', -110);\n\n\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 380, "y": 500, "wires": [ [ "4c85a6cc.6aacd", "d32a96ae.174368" ] ] }, { "id": "c3616e38.796f8", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"TMP\"", "topic": "/ble/+/+/TMP/#", "qos": "0", "broker": "1b431944.61f6af", "x": 90, "y": 220, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "4441394e.a8f55", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"HUM\"", "topic": "/ble/+/+/HUM/#", "qos": "0", "broker": "1b431944.61f6af", "x": 270, "y": 220, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "bf0b4ee3.a4456", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"LUM\"", "topic": "/ble/+/+/LUM/#", "qos": "0", "broker": "1b431944.61f6af", "x": 430, "y": 220, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "759288a5.c327b8", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"BEA\"", "topic": "/ble/+/+/BEA", "qos": "0", "broker": "1b431944.61f6af", "x": 270, "y": 100, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "850bd1ea.abd6e8", "type": "mqtt in", "z": "2511c21c.d364ee", "name": "Global \"DIS\"", "topic": "/ble/+/+/dis/#", "qos": "0", "broker": "1b431944.61f6af", "x": 430, "y": 80, "wires": [ [ "480923bf.c49ac4" ] ] }, { "id": "1b431944.61f6af", "type": "mqtt-broker", "z": "", "name": "MQT 1.23", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "60", "cleansession": true, "willTopic": "", "willQos": "0", "willPayload": "", "birthTopic": "", "birthQos": "0", "birthPayload": "" }, { "id": "7882ae67.b58028", "type": "mqtt-broker", "z": "", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "60", "cleansession": true, "willTopic": "", "willQos": "0", "willPayload": "", "birthTopic": "", "birthQos": "0", "birthPayload": "" }, { "id": "d602c15f.8da268", "type": "mqtt-broker", "z": "", "name": "MQT 1.23", "broker": "192.168.2.46", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "60", "cleansession": true, "willTopic": "", "willQos": "0", "willPayload": "", "birthTopic": "", "birthQos": "0", "birthPayload": "" } ]