[{"id":"5b2a05b4.67becc","type":"mqtt-broker","broker":"quickstart.messaging.internetofthings.ibmcloud.com","port":"1883","clientid":"a:quickstart:myApplicationId"},{"id":"3fb9c8bd.91bf88","type":"function","name":"Post xDotEtc Data","func":"var mac=context.global.evb_info.macAddress;\nmsg.payload={ \n d: {\n light: msg[\"evb\"].light.lux|0,\n moisture:msg.evb.barometer.pa, \n temperature:(msg.evb.temperature.c) ,\n x_acc: msg.evb.accelerometer.x, \n y_acc: msg.evb.accelerometer.y, \n z_acc: msg.evb.accelerometer.z\n }\n}\n\nif (context.global.evb_info[msg.eui].msg_counter == null){\n context.global.evb_info[msg.eui].msg_counter = 0;\n}\n// iot-2/type/mosquitto/id/myDeviceId/evt/helloworld/fmt/json\nmsg.topic = \"iot-2/type/mosquitto/id/\" + \n mac + \n \"/evt/datapoint/\" + \n \"fmt/json\";\n\ncontext.global.evb_info[msg.eui][\"msg_counter\"] += 1.0 ;\nreturn msg;\n","outputs":"1","noerr":0,"x":642,"y":467,"z":"6a88065d.baaaf8","wires":[["a861b8ca.d57968","e654b676.958408"]]},{"id":"e654b676.958408","type":"debug","name":"Posted xDotEtc Data","active":true,"console":"false","complete":"payload","x":980,"y":539,"z":"6a88065d.baaaf8","wires":[]},{"id":"b7eef807.7c5078","type":"lora in","name":"","datatype":"bytes","x":91,"y":478,"z":"6a88065d.baaaf8","wires":[["cb71b0bf.6f807"]]},{"id":"cb71b0bf.6f807","type":"function","name":"Lora Payload Process","func":"if ( context.global.evb_info[msg.eui] == null) {\n context.global.evb_info[msg.eui] = { msg_counter: 0 };\n \n}\n\nvar evb_info = context.global.evb_info ;\nvar evb_sensors = {};\n\n/*\n * Evaluation board properties.\n */\nvar EVB_TYPE = {\n none: 0,\n led_1: 1,\n led_2: 2,\n lux_max: 3,\n lux_min: 4,\n lux: 5,\n barometer_max: 6,\n barometer_min: 7,\n barometer: 8,\n temperature_max: 9,\n temperature__min: 10,\n temperature: 11,\n accelerometer_max: 12,\n accelerometer_min: 13,\n accelerometer: 14,\n tx_interval: 15,\n amps_max: 16,\n amps_min: 17,\n amps: 18,\n m2x_device: 19,\n m2x_key: 20,\n};\n\n/*\n * Process the EVB LoRa payload.\n *\n * EVB payload contains one or more TLV fields.\n *\n * []\n * []\n * []\n * \n */\nfor (var index = 0; index < msg.payload.length; ) {\n var type = msg.payload[index++];\n// var length = msg.payload[index++];\n var value;\n console.log(\"type: \" + type + \" length: \" );\n\n switch (type) {\n case EVB_TYPE.lux:\n if (typeof(evb_sensors.light) == \"undefined\") {\n evb_sensors.light = {};\n }\n\n value = msg.payload[index++] << 8;\n value |= msg.payload[index++];\n value = value * 0.24;\n\n evb_sensors.light.lux = value;\n break;\n case EVB_TYPE.barometer:\n if (typeof(evb_sensors.barometer) == \"undefined\") {\n evb_sensors.barometer = {};\n }\n\n value = msg.payload[index++] << 16;\n value |= msg.payload[index++] << 8;\n value |= msg.payload[index++];\n value = value * 0.00025;\n\n evb_sensors.barometer.pa = value;\n break;\n case EVB_TYPE.accelerometer:\n if (typeof(evb_sensors.accelerometer) == \"undefined\") {\n evb_sensors.accelerometer = {};\n }\n // evb_sensors.accelerometer.x = (msg.payload[index++] << 24) >> 16;\n var x1 = evb_sensors.accelerometer.x = msg.payload[index++] ;\n // x1 = ~x1 ; \n // x1 = ( x1 + 1 ) % 256; \n evb_sensors.accelerometer.x = x1 * 0.0625//; / 15;\n // evb_sensors.accelerometer.y = (msg.payload[index++] << 24) >> 16;\n var y1 = evb_sensors.accelerometer.y = msg.payload[index++] ;\n // y1 = ~ y1 ; \n // y1 = ( y1 + 1 ) % 256;\n \n var y1 = evb_sensors.accelerometer.y = y1 * 0.0625 ; // / 15 ;\n\n // evb_sensors.accelerometer.z = (msg.payload[index++] << 24) >> 16;\n var z1 = evb_sensors.accelerometer.z = msg.payload[index++] ;\n // z1 = ~ z1 ; \n // z1 = ( z1 + 1 ) % 256; \n // z1 = z1 - 128;\n var z1 = evb_sensors.accelerometer.z = z1 * 0.0625; // / 15;\n break;\n case EVB_TYPE.temperature:\n if (typeof(evb_sensors.temperature) == \"undefined\") {\n evb_sensors.temperature = {};\n }\n\n value = (msg.payload[index++] << 24) >> 16;\n value |= msg.payload[index++];\n value = value * 0.0625;\n\n evb_sensors.temperature.c = value;\n break;\n case EVB_TYPE.tx_interval:\n evb_sensors.tx_timer = msg.payload[index++];\n break;\n case EVB_TYPE.m2x_device:\n value = msg.payload.slice(index, index + length);\n evb_info[msg.eui].m2x_device = \"\";\n for (var j = 0; j < length; j++) {\n evb_info[msg.eui].m2x_device += String.fromCharCode(value[j]);\n }\n break;\n case EVB_TYPE.m2x_key:\n value = msg.payload.slice(index, index + length);\n evb_info[msg.eui].m2x_key = \"\";\n for (var j = 0; j < length; j++) {\n evb_info[msg.eui].m2x_key += String.fromCharCode(value[j]);\n }\n break;\n default:\n index += length;\n break;\n }\n}\n\nif (typeof(evb_info[msg.eui].m2x_device) == \"undefined\") {\n console.log(\"No m2x_device registered for \" + msg.eui);\n// return null;\n}\nif (typeof(evb_info[msg.eui].m2x_key) == \"undefined\") {\n console.log(\"No m2x_key registered for \" + msg.eui);\n// return null;\n}\nmsg.m2x_device = evb_info[msg.eui].m2x_device;\nmsg.m2x_key = evb_info[msg.eui].m2x_key;\nmsg.evb = evb_sensors;\n\n/*\n * Return msg to continue the flow\n */\nif (typeof msg.evb != \"undefined\"){\n return msg; \n}\n","outputs":1,"noerr":0,"x":373,"y":471,"z":"6a88065d.baaaf8","wires":[["3fb9c8bd.91bf88","f74d4804.753d38"]]},{"id":"f9f255fc.fa9678","type":"comment","name":"Start Here","info":"Welcome to the Multitech Conduit Lora Starter Kit\nNode Red flow \n\nThis \"flow\" is actually a small javascript \napplication. \n\nOn the left is a lora node. This node listens to\nthe LoRa radio for incoming messages. When it\nreceives a lora packet, it sends it from its output which\nis connected to the \"Lora Payload Process\",\nwhere the original binary messages is translated\ninto a javascript object for easier use.\n\nThe output of this function is then fed into the node\n\"Post xDotEtc Data\" \n\nThe output of this node is connected to the IOT Foundation\nxDotEtc node, which uses the MQTT protocol to send the \nprepared packet of data to IBM's Bluemix. \n\n\n\n\n","x":653,"y":49,"z":"6a88065d.baaaf8","wires":[]},{"id":"80f4040a.f7d8b8","type":"inject","name":"Run once at Startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":123,"y":203,"z":"6a88065d.baaaf8","wires":[["93d47e24.9dc9c"]]},{"id":"12d17dd5.4635e2","type":"function","name":"Initialization","func":"var system=JSON.parse(msg.payload).result;\n\n// create \nif (typeof context.global.evb_info == \"undefined\") {\n context.global.evb_info = {};\n}\nwhile (system.macAddress.indexOf(\":\") > -1 ){\n system.macAddress=system.macAddress.replace(\":\",\"-\") \n}\ncontext.global.evb_info['macAddress']=system.macAddress.replace(\":\",\"-\"); \nif ( context.global.evb_info[\"simulated\"]==null ){\n context.global.evb_info[\"simulated\"] = {};\n}\nmsg=system;\nreturn msg;","outputs":1,"noerr":0,"x":566,"y":204,"z":"6a88065d.baaaf8","wires":[["d387c450.341908"]]},{"id":"a861b8ca.d57968","type":"mqtt out","name":"MQTT Quickstart","topic":"","qos":"0","retain":"","broker":"5b2a05b4.67becc","x":983,"y":364,"z":"6a88065d.baaaf8","wires":[]},{"id":"f74d4804.753d38","type":"debug","name":"","active":false,"console":"false","complete":"true","x":584,"y":608,"z":"6a88065d.baaaf8","wires":[]},{"id":"93d47e24.9dc9c","type":"http request","name":"get mac address","method":"GET","ret":"txt","url":"http://localhost/api/system","x":355,"y":203,"z":"6a88065d.baaaf8","wires":[["12d17dd5.4635e2"]]},{"id":"d387c450.341908","type":"debug","name":"","active":true,"console":"false","complete":"true","x":802,"y":204,"z":"6a88065d.baaaf8","wires":[]}]