diff --git a/IoT & Edge Analytics Home Setup.docx b/IoT & Edge Analytics Home Setup.docx new file mode 100644 index 0000000..b7de00b Binary files /dev/null and b/IoT & Edge Analytics Home Setup.docx differ diff --git a/Louis Frolio/DevNet Create IoT Presentation.pptx b/Louis Frolio/DevNet Create IoT Presentation.pptx new file mode 100644 index 0000000..bf27b9d Binary files /dev/null and b/Louis Frolio/DevNet Create IoT Presentation.pptx differ diff --git a/Louis Frolio/create at home docs/IoT & Edge Analytics Home Setup.docx b/Louis Frolio/create at home docs/IoT & Edge Analytics Home Setup.docx new file mode 100644 index 0000000..b7de00b Binary files /dev/null and b/Louis Frolio/create at home docs/IoT & Edge Analytics Home Setup.docx differ diff --git a/Louis Frolio/create at home docs/readme.md b/Louis Frolio/create at home docs/readme.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Louis Frolio/create at home docs/readme.md @@ -0,0 +1 @@ + diff --git a/Louis Frolio/scripts/nodered/fullsolution.json b/Louis Frolio/scripts/nodered/fullsolution.json new file mode 100644 index 0000000..11f5f9b --- /dev/null +++ b/Louis Frolio/scripts/nodered/fullsolution.json @@ -0,0 +1 @@ +[{"id":"170f4113.a11aef","type":"tab","label":"Working Solution DevNet Create 2018","disabled":false,"info":""},{"id":"a0941111.6ca848","type":"mqtt in","z":"170f4113.a11aef","name":"dietpi-1 mqtt lux","topic":"cc2650/temp/546c0e53122d","qos":"0","broker":"8037e8c5.8bd49","x":140,"y":200,"wires":[["727a1a51.58f6dc","fbbcad8f.00ccf"]]},{"id":"da8854f9.b99ab8","type":"switch","z":"170f4113.a11aef","name":"Alarm Status","property":"payload.json_data.lux","propertyType":"msg","rules":[{"t":"gt","v":"150","vt":"str"},{"t":"btwn","v":"101","vt":"num","v2":"150","v2t":"num"},{"t":"lte","v":"100","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":670,"y":200,"wires":[["110040a6.1fc47f"],["6f0a713d.0e5e28"],["8470bff7.2e19e8"]]},{"id":"727a1a51.58f6dc","type":"json","z":"170f4113.a11aef","name":"","property":"payload","action":"obj","pretty":false,"x":290,"y":200,"wires":[["e3b7a99.7beeed8","c5bab3ab.9cee28","d3b3e3ae.d54bc8"]]},{"id":"110040a6.1fc47f","type":"exec","z":"170f4113.a11aef","command":"sudo python /home/pi//trafficlight.py red true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: ALARM","x":860,"y":120,"wires":[["22fac8dc.fa6638"],["a4638830.1afa5"],[]]},{"id":"8470bff7.2e19e8","type":"exec","z":"170f4113.a11aef","command":"sudo python /home/pi//trafficlight.py green true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: NORMAL","x":870,"y":280,"wires":[["da9a9d49.bbd768"],["cff89d7a.006238"],[]]},{"id":"22fac8dc.fa6638","type":"debug","z":"170f4113.a11aef","name":"redstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1040,"y":60,"wires":[]},{"id":"a4638830.1afa5","type":"debug","z":"170f4113.a11aef","name":"redstderror","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":100,"wires":[]},{"id":"da9a9d49.bbd768","type":"debug","z":"170f4113.a11aef","name":"greenstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":240,"wires":[]},{"id":"cff89d7a.006238","type":"debug","z":"170f4113.a11aef","name":"greenstderr","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":280,"wires":[]},{"id":"314fdf39.d45118","type":"pythonshell in","z":"170f4113.a11aef","name":"","pyfile":"/home/pi/bluepy/bluepy/cc2650.py","virtualenv":"","continuous":true,"x":140,"y":100,"wires":[["232716f8.4e9b62"]]},{"id":"232716f8.4e9b62","type":"debug","z":"170f4113.a11aef","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":350,"y":100,"wires":[]},{"id":"e3b7a99.7beeed8","type":"function","z":"170f4113.a11aef","name":"Time Series Format","func":"var data = msg.payload;\n\nfunction generateRandomId() {\n return Math.round (Math.random()*(1000000 - 1)+1);\n}\n\nvar randomId = generateRandomId();\n\nmsg.payload = {\n id: randomId,\n tstamp: {$data:(new Date()).getTime()},\n json_data : {\n lux:data.lux,\n ambient_temp:data.ambient_temp,\n humidity:data.humidity\n }\n};\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["da8854f9.b99ab8","a26c3186.8456","8c61f407.61ffd8"]]},{"id":"6f0a713d.0e5e28","type":"exec","z":"170f4113.a11aef","command":"sudo python /home/pi//trafficlight.py yellow true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: WARNING","x":870,"y":200,"wires":[["5e60abec.bad944"],["31f3890f.84504e"],[]]},{"id":"31f3890f.84504e","type":"debug","z":"170f4113.a11aef","name":"yellowstderr","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":200,"wires":[]},{"id":"5e60abec.bad944","type":"debug","z":"170f4113.a11aef","name":"yellowstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":160,"wires":[]},{"id":"a26c3186.8456","type":"timeseries out","z":"170f4113.a11aef","timeseries":"d6bddfb6.0d3778","name":"","baseTimeSeriesTable":"sensor","x":750,"y":340,"wires":[]},{"id":"fbbcad8f.00ccf","type":"debug","z":"170f4113.a11aef","name":"Raw MQTT Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":150,"y":320,"wires":[]},{"id":"8c61f407.61ffd8","type":"debug","z":"170f4113.a11aef","name":"Time Series Formated Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":740,"y":380,"wires":[]},{"id":"c5bab3ab.9cee28","type":"debug","z":"170f4113.a11aef","name":"Raw Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":380,"y":320,"wires":[]},{"id":"36c264e7.f69f3c","type":"cloudant out","z":"170f4113.a11aef","name":"Insert into Cloudant (Cloud)","cloudant":"27796c38.f5fc3c","database":"devnetcreate2018","service":"_ext_","payonly":false,"operation":"insert","x":1500,"y":820,"wires":[]},{"id":"874ea777.2ee5a8","type":"function","z":"170f4113.a11aef","name":"Lux: Z-Score","func":"//initialize a list that stores the last n values for the electric current by using the voltage parameter. In stream computing, this list is called a \"sliding window of fixed size.\" \nvar aggwindow = context.get('aggwindow')||[];\n\n//add values to that lis\naggwindow.push(msg.payload.lux); \n\n//Continue adding values to the list until we have exceeded 30 values, which defines the size of our sliding window. \nif (aggwindow.length> 3) {\n \n //To compute z-score, we need the mean and the standard deviation.\n sum = aggwindow.reduce((a,b)=>a+b,0);\n n = aggwindow.length;\n mean = sum/n;\n sd = Math.sqrt(aggwindow.map(x=>Math.pow(mean-x,2)).reduce((a,b)=>a+b,0));\n \n // get rid of the oldest element in the list, which resembles a LIFO. \n aggwindow.shift();\n \n //Perform Z-Score Calculation. Add a small value to standard deviation because the standard deviation can become zero, which is mathematically undefined\n msg.zscore = (mean-msg.payload.lux)/(sd+0.0001)\n}\n\n//store this list to a global context to preserve it over individual message lifetimes\ncontext.set('aggwindow',aggwindow);\n\n\n//output voltage and zscore\nmsg.payload = {\n [(\"zscore\")]:Math.abs(msg.zscore)\n }\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":440,"wires":[["c9a2c6cb.b5735","a7f099eb.0d99e","96d7b6d2.125578"]]},{"id":"c9a2c6cb.b5735","type":"debug","z":"170f4113.a11aef","name":"Z-Score","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.zscore","x":740,"y":440,"wires":[]},{"id":"fabdc6fd.2bb9f8","type":"debug","z":"170f4113.a11aef","name":"Average Lux","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":750,"y":500,"wires":[]},{"id":"d3b3e3ae.d54bc8","type":"switch","z":"170f4113.a11aef","name":"","property":"topic","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":440,"wires":[["5728dc9e.c64734","874ea777.2ee5a8","19f287b9.b2c73","3209e498.ac7844"]]},{"id":"5728dc9e.c64734","type":"debug","z":"170f4113.a11aef","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":220,"y":520,"wires":[]},{"id":"19f287b9.b2c73","type":"smooth","z":"170f4113.a11aef","name":"Lux: Moving Mean","property":"payload.lux","action":"mean","count":"3","round":"","mult":"multi","x":490,"y":500,"wires":[["fabdc6fd.2bb9f8","f64d640e.c6bfa","f69a62a4.6d31b8"]]},{"id":"3209e498.ac7844","type":"smooth","z":"170f4113.a11aef","name":"Lux: Standard Deviation","property":"payload.lux","action":"sd","count":"3","round":"","mult":"multi","x":510,"y":560,"wires":[["b7c34b84.b5ad98","921f1569.889cb","b09d41ba.8ebfa8"]]},{"id":"b7c34b84.b5ad98","type":"debug","z":"170f4113.a11aef","name":"Standard Deviation","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":770,"y":560,"wires":[]},{"id":"a7f099eb.0d99e","type":"function","z":"170f4113.a11aef","name":"Z-Score","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task1\";\nmsg.payload=msg.ID.zscore\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":720,"wires":[["b1747b8e.90a8f","31dda055.cc387"]]},{"id":"b1747b8e.90a8f","type":"debug","z":"170f4113.a11aef","name":"Z-Score Out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":540,"wires":[]},{"id":"f64d640e.c6bfa","type":"function","z":"170f4113.a11aef","name":"Moving Average","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task2\";\nmsg.payload=msg.ID.lux\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":760,"wires":[["7e513995.4b7478","45f35553.ba77d4"]]},{"id":"7e513995.4b7478","type":"debug","z":"170f4113.a11aef","name":"Mean Out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1020,"y":580,"wires":[]},{"id":"921f1569.889cb","type":"function","z":"170f4113.a11aef","name":"Standard Deviation","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task3\";\nmsg.payload=msg.ID.lux\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":800,"wires":[["4dc8eac1.c9a3a4","ed2f0ff5.617d58"]]},{"id":"4dc8eac1.c9a3a4","type":"debug","z":"170f4113.a11aef","name":"Standard Deviation","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":620,"wires":[]},{"id":"31dda055.cc387","type":"delay","z":"170f4113.a11aef","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"0","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":720,"wires":[["f029dfa.6fab42","277a70d0.a8c7"]]},{"id":"45f35553.ba77d4","type":"delay","z":"170f4113.a11aef","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":760,"wires":[["f029dfa.6fab42"]]},{"id":"ed2f0ff5.617d58","type":"delay","z":"170f4113.a11aef","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":800,"wires":[["f029dfa.6fab42"]]},{"id":"f029dfa.6fab42","type":"function","z":"170f4113.a11aef","name":"Wait for all tasks to finish","func":"QueryID = msg.ID;\ncontext.data = context.data || {};\ncontext.data[QueryID] = context.data[QueryID] || {tstamp:(new Date()).getTime(), zscore : null, weighted_mean: null, standard_dev: null, piname: context.global.os.hostname()};\n\nswitch (msg.topic) {\n case \"task1\":\n context.data[QueryID].zscore = msg.payload;\n msg = null;\n break;\n case \"task2\":\n context.data[QueryID].weighted_mean = msg.payload;\n msg = null;\n break;\n case \"task3\":\n context.data[QueryID].standard_dev = msg.payload;\n msg = null;\n break;\n case \"task4\":\n context.data[QueryID].piname = msg.payload;\n msg = null;\n break;\n default:\n msg = null;\n \tbreak;\n\n}\n\nif(context.data[QueryID].zscore !== null && context.data[QueryID].weighted_mean !== null && context.data[QueryID].standard_dev !== null) {\n\tmsg2 = {};\n msg2 = context.data[QueryID];\n delete context.data[QueryID];\n\treturn msg2;\n} else return msg;","outputs":1,"noerr":0,"x":1230,"y":760,"wires":[["1852fb9a.94a904","36c264e7.f69f3c"]]},{"id":"277a70d0.a8c7","type":"debug","z":"170f4113.a11aef","name":"Z with Delay","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1170,"y":680,"wires":[]},{"id":"1852fb9a.94a904","type":"debug","z":"170f4113.a11aef","name":"Combined","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1450,"y":700,"wires":[]},{"id":"96d7b6d2.125578","type":"function","z":"170f4113.a11aef","name":"Z-Score to Guage","func":"var fields = {payload: msg.payload.zscore};\nreturn fields;","outputs":1,"noerr":0,"x":1030,"y":400,"wires":[["7433d1c.657abb"]]},{"id":"d430b725.22b5b8","type":"ui_chart","z":"170f4113.a11aef","name":"","group":"f7b54de6.2a21d8","order":0,"width":0,"height":0,"label":"Lux Mean Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1300,"y":440,"wires":[[],[]]},{"id":"f69a62a4.6d31b8","type":"function","z":"170f4113.a11aef","name":"Lux Mean","func":"var fields = {payload: msg.payload.lux};\nreturn fields;","outputs":1,"noerr":0,"x":1000,"y":440,"wires":[["d430b725.22b5b8"]]},{"id":"b09d41ba.8ebfa8","type":"function","z":"170f4113.a11aef","name":"Standard Deviation","func":"var fields = {payload: msg.payload.lux};\nreturn fields;","outputs":1,"noerr":0,"x":1030,"y":480,"wires":[["8a50fef7.eedad"]]},{"id":"8a50fef7.eedad","type":"ui_chart","z":"170f4113.a11aef","name":"","group":"f7b54de6.2a21d8","order":0,"width":0,"height":0,"label":"Lux Standard Deviation Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1350,"y":480,"wires":[[],[]]},{"id":"7433d1c.657abb","type":"ui_chart","z":"170f4113.a11aef","name":"","group":"f7b54de6.2a21d8","order":0,"width":0,"height":0,"label":"Z-Score Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1300,"y":400,"wires":[[],[]]},{"id":"8037e8c5.8bd49","type":"mqtt-broker","z":"","name":"dietpi-1","broker":"192.168.51.27","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"d6bddfb6.0d3778","type":"timeseries","z":"","hostname":"192.168.51.27","port":"27018","db":"iot","name":"Insert to Informax (Local)"},{"id":"27796c38.f5fc3c","type":"cloudant","z":"","host":"5017a47e-4beb-49a9-b221-56de06629f80-bluemix.cloudant.com","name":"devnetcreate2018-cloudantdb"},{"id":"f7b54de6.2a21d8","type":"ui_group","z":"","name":"Dashboard","tab":"b741cd9c.dbfe28","order":1,"disp":true,"width":"6","collapse":false},{"id":"b741cd9c.dbfe28","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}] \ No newline at end of file diff --git a/Louis Frolio/scripts/nodered/nppBackup/fullsolution.json.2018-04-06_150340.bak b/Louis Frolio/scripts/nodered/nppBackup/fullsolution.json.2018-04-06_150340.bak new file mode 100644 index 0000000..e69de29 diff --git a/Louis Frolio/scripts/nodered/nppBackup/fullsolution.json.2018-04-06_201127.bak b/Louis Frolio/scripts/nodered/nppBackup/fullsolution.json.2018-04-06_201127.bak new file mode 100644 index 0000000..f8b3144 --- /dev/null +++ b/Louis Frolio/scripts/nodered/nppBackup/fullsolution.json.2018-04-06_201127.bak @@ -0,0 +1 @@ +[{"id":"88aeaed4.d841c","type":"tab","label":"Working Solution DevNet Create 2018","disabled":false,"info":""},{"id":"30a3631c.0085fc","type":"mqtt in","z":"88aeaed4.d841c","name":"dietpi-1 mqtt lux","topic":"cc2650/temp/546c0e531e46","qos":"0","broker":"10ab31e9.4a6ab6","x":140,"y":200,"wires":[["c739df9f.d6239","4111ab38.ae00d4"]]},{"id":"2a1b927.4882cee","type":"switch","z":"88aeaed4.d841c","name":"Alarm Status","property":"payload.json_data.lux","propertyType":"msg","rules":[{"t":"gt","v":"150","vt":"str"},{"t":"btwn","v":"101","vt":"num","v2":"150","v2t":"num"},{"t":"lte","v":"100","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":670,"y":200,"wires":[["26c93d16.15092a"],["efcfcd67.950c6"],["51b75cd5.0398e4"]]},{"id":"c739df9f.d6239","type":"json","z":"88aeaed4.d841c","name":"","property":"payload","action":"obj","pretty":false,"x":290,"y":200,"wires":[["da6172f3.d652","a5d3f01e.18ef4","1d6c4a1e.b2513e"]]},{"id":"26c93d16.15092a","type":"exec","z":"88aeaed4.d841c","command":"sudo python /home/pi/devnet2018/Create2018/Louis\\ Frolio/scripts/python/trafficlight.py red true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: ALARM","x":860,"y":120,"wires":[["802336fd.0eb4a8"],["c6c39e6e.9e6f08"],[]]},{"id":"51b75cd5.0398e4","type":"exec","z":"88aeaed4.d841c","command":"sudo python /home/pi/devnet2018/Create2018/Louis\\ Frolio/scripts/python/trafficlight.py green true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: NORMAL","x":870,"y":280,"wires":[["c6c2dc2d.110308"],["d5c961a5.69d68"],[]]},{"id":"802336fd.0eb4a8","type":"debug","z":"88aeaed4.d841c","name":"redstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1040,"y":60,"wires":[]},{"id":"c6c39e6e.9e6f08","type":"debug","z":"88aeaed4.d841c","name":"redstderror","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":100,"wires":[]},{"id":"c6c2dc2d.110308","type":"debug","z":"88aeaed4.d841c","name":"greenstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":240,"wires":[]},{"id":"d5c961a5.69d68","type":"debug","z":"88aeaed4.d841c","name":"greenstderr","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":280,"wires":[]},{"id":"28337d96.1231b2","type":"pythonshell in","z":"88aeaed4.d841c","name":"","pyfile":"/home/pi/bluepy/bluepy/cc2650.py","virtualenv":"","continuous":true,"x":160,"y":100,"wires":[["b071572.1a19628"]]},{"id":"b071572.1a19628","type":"debug","z":"88aeaed4.d841c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":100,"wires":[]},{"id":"da6172f3.d652","type":"function","z":"88aeaed4.d841c","name":"Time Series Format","func":"var data = msg.payload;\n\nfunction generateRandomId() {\n return Math.round (Math.random()*(1000000 - 1)+1);\n}\n\nvar randomId = generateRandomId();\n\nmsg.payload = {\n id: randomId,\n tstamp: {$data:(new Date()).getTime()},\n json_data : {\n lux:data.lux,\n ambient_temp:data.ambient_temp,\n humidity:data.humidity\n }\n};\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["2a1b927.4882cee","72a3d452.b7fbd4","7c057e21.53a61"]]},{"id":"efcfcd67.950c6","type":"exec","z":"88aeaed4.d841c","command":"sudo python /home/pi/devnet2018/Create2018/Louis\\ Frolio/scripts/python/trafficlight.py yellow true","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Status: WARNING","x":870,"y":200,"wires":[["b180ff4d.fe0088"],["f5edbb66.68246"],[]]},{"id":"f5edbb66.68246","type":"debug","z":"88aeaed4.d841c","name":"yellowstderr","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":200,"wires":[]},{"id":"b180ff4d.fe0088","type":"debug","z":"88aeaed4.d841c","name":"yellowstdout","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":160,"wires":[]},{"id":"72a3d452.b7fbd4","type":"timeseries out","z":"88aeaed4.d841c","timeseries":"4143b30d.84526c","name":"","baseTimeSeriesTable":"sensor_ts","x":760,"y":340,"wires":[]},{"id":"4111ab38.ae00d4","type":"debug","z":"88aeaed4.d841c","name":"Raw MQTT Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":150,"y":320,"wires":[]},{"id":"7c057e21.53a61","type":"debug","z":"88aeaed4.d841c","name":"Time Series Formated Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":740,"y":380,"wires":[]},{"id":"a5d3f01e.18ef4","type":"debug","z":"88aeaed4.d841c","name":"Raw Data","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":380,"y":320,"wires":[]},{"id":"e57717b1.a78c1","type":"cloudant out","z":"88aeaed4.d841c","name":"Insert into Cloudant (Cloud)","cloudant":"f99df1a6.8cce48","database":"devnetcreate2018","service":"_ext_","payonly":false,"operation":"insert","x":1500,"y":820,"wires":[]},{"id":"fb451243.ff1e28","type":"function","z":"88aeaed4.d841c","name":"Lux: Z-Score","func":"//initialize a list that stores the last n values for the electric current by using the voltage parameter. In stream computing, this list is called a \"sliding window of fixed size.\" \nvar aggwindow = context.get('aggwindow')||[];\n\n//add values to that lis\naggwindow.push(msg.payload.lux); \n\n//Continue adding values to the list until we have exceeded 30 values, which defines the size of our sliding window. \nif (aggwindow.length> 3) {\n \n //To compute z-score, we need the mean and the standard deviation.\n sum = aggwindow.reduce((a,b)=>a+b,0);\n n = aggwindow.length;\n mean = sum/n;\n sd = Math.sqrt(aggwindow.map(x=>Math.pow(mean-x,2)).reduce((a,b)=>a+b,0));\n \n // get rid of the oldest element in the list, which resembles a LIFO. \n aggwindow.shift();\n \n //Perform Z-Score Calculation. Add a small value to standard deviation because the standard deviation can become zero, which is mathematically undefined\n msg.zscore = (mean-msg.payload.lux)/(sd+0.0001)\n}\n\n//store this list to a global context to preserve it over individual message lifetimes\ncontext.set('aggwindow',aggwindow);\n\n\n//output voltage and zscore\nmsg.payload = {\n [(\"zscore\")]:Math.abs(msg.zscore)\n }\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":440,"wires":[["30f546ad.fe9f3a","abb569ad.4aeed8","e9090664.7a64b8"]]},{"id":"30f546ad.fe9f3a","type":"debug","z":"88aeaed4.d841c","name":"Z-Score","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.zscore","x":740,"y":440,"wires":[]},{"id":"89a70559.86e1d","type":"debug","z":"88aeaed4.d841c","name":"Average Lux","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":750,"y":500,"wires":[]},{"id":"1d6c4a1e.b2513e","type":"switch","z":"88aeaed4.d841c","name":"","property":"topic","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":440,"wires":[["7d274fa9.415b5","fb451243.ff1e28","f1b0e2b3.3eddd8","c026f52c.85c6b8"]]},{"id":"7d274fa9.415b5","type":"debug","z":"88aeaed4.d841c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":220,"y":520,"wires":[]},{"id":"f1b0e2b3.3eddd8","type":"smooth","z":"88aeaed4.d841c","name":"Lux: Moving Mean","property":"payload.lux","action":"mean","count":"3","round":"","mult":"multi","x":490,"y":500,"wires":[["89a70559.86e1d","36e7ab4a.ef4a5c","9c9e8d8a.4013f"]]},{"id":"c026f52c.85c6b8","type":"smooth","z":"88aeaed4.d841c","name":"Lux: Standard Deviation","property":"payload.lux","action":"sd","count":"3","round":"","mult":"multi","x":510,"y":560,"wires":[["668ae5c9.608924","c4720701.e84c2","839d32b8.216c08"]]},{"id":"668ae5c9.608924","type":"debug","z":"88aeaed4.d841c","name":"Standard Deviation","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.lux","x":770,"y":560,"wires":[]},{"id":"abb569ad.4aeed8","type":"function","z":"88aeaed4.d841c","name":"Z-Score","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task1\";\nmsg.payload=msg.ID.zscore\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":720,"wires":[["13e8f49e.9bbae3","248aaed2.c6ac52"]]},{"id":"13e8f49e.9bbae3","type":"debug","z":"88aeaed4.d841c","name":"Z-Score Out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":540,"wires":[]},{"id":"36e7ab4a.ef4a5c","type":"function","z":"88aeaed4.d841c","name":"Moving Average","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task2\";\nmsg.payload=msg.ID.lux\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":760,"wires":[["efcb35bb.e9254","8968da59.28ec7"]]},{"id":"efcb35bb.e9254","type":"debug","z":"88aeaed4.d841c","name":"Mean Out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1020,"y":580,"wires":[]},{"id":"c4720701.e84c2","type":"function","z":"88aeaed4.d841c","name":"Standard Deviation","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task3\";\nmsg.payload=msg.ID.lux\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":800,"wires":[["786551cd.4758e","5bb7eec3.cb2ad8"]]},{"id":"786551cd.4758e","type":"debug","z":"88aeaed4.d841c","name":"Standard Deviation","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":620,"wires":[]},{"id":"248aaed2.c6ac52","type":"delay","z":"88aeaed4.d841c","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"0","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":720,"wires":[["6949e2ca.5ea13c","7fae218b.cbf078"]]},{"id":"8968da59.28ec7","type":"delay","z":"88aeaed4.d841c","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":760,"wires":[["6949e2ca.5ea13c"]]},{"id":"5bb7eec3.cb2ad8","type":"delay","z":"88aeaed4.d841c","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"6","randomUnits":"seconds","drop":false,"x":960,"y":800,"wires":[["6949e2ca.5ea13c"]]},{"id":"6949e2ca.5ea13c","type":"function","z":"88aeaed4.d841c","name":"Wait for all tasks to finish","func":"QueryID = msg.ID;\ncontext.data = context.data || {};\ncontext.data[QueryID] = context.data[QueryID] || {tstamp:(new Date()).getTime(), zscore : null, weighted_mean: null, standard_dev: null, piname: context.global.os.hostname()};\n\nswitch (msg.topic) {\n case \"task1\":\n context.data[QueryID].zscore = msg.payload;\n msg = null;\n break;\n case \"task2\":\n context.data[QueryID].weighted_mean = msg.payload;\n msg = null;\n break;\n case \"task3\":\n context.data[QueryID].standard_dev = msg.payload;\n msg = null;\n break;\n case \"task4\":\n context.data[QueryID].piname = msg.payload;\n msg = null;\n break;\n default:\n msg = null;\n \tbreak;\n\n}\n\nif(context.data[QueryID].zscore !== null && context.data[QueryID].weighted_mean !== null && context.data[QueryID].standard_dev !== null) {\n\tmsg2 = {};\n msg2 = context.data[QueryID];\n delete context.data[QueryID];\n\treturn msg2;\n} else return msg;","outputs":1,"noerr":0,"x":1230,"y":760,"wires":[["14e77a73.3db126","e57717b1.a78c1"]]},{"id":"7fae218b.cbf078","type":"debug","z":"88aeaed4.d841c","name":"Z with Delay","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1170,"y":680,"wires":[]},{"id":"14e77a73.3db126","type":"debug","z":"88aeaed4.d841c","name":"Combined","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1450,"y":700,"wires":[]},{"id":"e9090664.7a64b8","type":"function","z":"88aeaed4.d841c","name":"Z-Score to Guage","func":"var fields = {payload: msg.payload.zscore};\nreturn fields;","outputs":1,"noerr":0,"x":1030,"y":400,"wires":[["8b2e1796.e5512"]]},{"id":"1021e91b.aa109f","type":"ui_chart","z":"88aeaed4.d841c","name":"","group":"9963034.8cc27","order":0,"width":0,"height":0,"label":"Lux Mean Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1300,"y":440,"wires":[[],[]]},{"id":"9c9e8d8a.4013f","type":"function","z":"88aeaed4.d841c","name":"Lux Mean","func":"var fields = {payload: msg.payload.lux};\nreturn fields;","outputs":1,"noerr":0,"x":1000,"y":440,"wires":[["1021e91b.aa109f"]]},{"id":"839d32b8.216c08","type":"function","z":"88aeaed4.d841c","name":"Standard Deviation","func":"var fields = {payload: msg.payload.lux};\nreturn fields;","outputs":1,"noerr":0,"x":1030,"y":480,"wires":[["1f5759eb.bed8a6"]]},{"id":"1f5759eb.bed8a6","type":"ui_chart","z":"88aeaed4.d841c","name":"","group":"9963034.8cc27","order":0,"width":0,"height":0,"label":"Lux Standard Deviation Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1350,"y":480,"wires":[[],[]]},{"id":"8b2e1796.e5512","type":"ui_chart","z":"88aeaed4.d841c","name":"","group":"9963034.8cc27","order":0,"width":0,"height":0,"label":"Z-Score Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1300,"y":400,"wires":[[],[]]},{"id":"10ab31e9.4a6ab6","type":"mqtt-broker","z":"","name":"dietpi-1","broker":"192.168.51.20","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"4143b30d.84526c","type":"timeseries","z":"","hostname":"192.168.51.20","port":"27018","db":"iot","name":"Insert to Informax (Local)"},{"id":"f99df1a6.8cce48","type":"cloudant","z":"","host":"5017a47e-4beb-49a9-b221-56de06629f80-bluemix.cloudant.com","name":"devnetcreate2018-cloudantdb"},{"id":"9963034.8cc27","type":"ui_group","z":"","name":"Dashboard","tab":"fce9bb9a.afc248","order":1,"disp":true,"width":"6","collapse":false},{"id":"fce9bb9a.afc248","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}] \ No newline at end of file diff --git a/Louis Frolio/scripts/python/cc2650.py b/Louis Frolio/scripts/python/cc2650.py new file mode 100644 index 0000000..f936f08 --- /dev/null +++ b/Louis Frolio/scripts/python/cc2650.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# read CC2650 SensorTag by JP Mens +# follow https://smidgeonpigeon.wordpress.com/2015/07/21/raspberry-pi-2-ble-ti-sensor-tag/ +# to get started, but use Sensortag2650.py + +import time +import json +import struct +import sensortag2650 as sensortag +import paho.mqtt.publish as mqtt + +# don't even bother starting until you see your SensorTag +# $ hcitool -i hci1 lescan +# LE Scan ... +# B0:B4:48:BD:B8:05 CC2650 SensorTag + +my_sensor = '54:6C:0E:53:1E:46' +tag = sensortag.SensorTag(my_sensor) + +print "Connected to SensorTag", my_sensor + +sensorOn = struct.pack("B", 0x01) +sensorbarcal = struct.pack("B", 0x02) +sensorMagOn = struct.pack("H", 0x0007) +sensorGyrOn = struct.pack("H", 0x0007) +sensorAccOn = struct.pack("H", 0x0038) + +tag.IRtemperature.enable(sensorOn) +tag.humidity.enable(sensorOn) +tag.barometer.enable(sensorOn) +tag.accelerometer.enable(sensorAccOn) +# tag.magnetometer.enable(sensorMagOn) +# tag.gyroscope.enable(sensorGyrOn) +tag.luxometer.enable(sensorOn) + +base_topic = 'cc2650/temp/%s' % my_sensor.replace(':', '').lower() + +while True: + msgs = [] + + ambient_temp, target_temp = tag.IRtemperature.read() + x_accel, y_accel, z_accel = tag.accelerometer.read() + ambient_temp, rel_humidity = tag.humidity.read() + lux = tag.luxometer.read() + ambient_temp, pressure_millibars = tag.barometer.read() + + data = { + 'ambient_temp' : ambient_temp, + 'target_temp' : target_temp, + 'humidity' : rel_humidity, + 'lux' : lux, + 'millibars' : pressure_millibars, + 'tst' : int(time.time()), + } + + payload = json.dumps(data) + print payload + msgs.append((base_topic, payload, 0, False)) + for k in data: + msgs.append( ( "%s/%s" % (base_topic, k), data[k], 0, False ) ) + + mqtt.multiple(msgs, hostname='test.mosquitto.org') + + time.sleep(60) + +tag.disconnect() \ No newline at end of file diff --git a/Louis Frolio/scripts/python/trafficlight.py b/Louis Frolio/scripts/python/trafficlight.py new file mode 100644 index 0000000..a393808 --- /dev/null +++ b/Louis Frolio/scripts/python/trafficlight.py @@ -0,0 +1,37 @@ +# Writtn by Louis Frolio with inspiration from Google and the work of others. +# First developed for DevNet Create 2018. +# Workshop 3-WS9B - IOT & Edge Analytics Demystified. +# https://www.devnetcreate.io/2018/pages/agenda/agenda.html +# +# April 2018 +# You are welcome to use and modify this code at will. +# Contact me on Twitter: @froliol + +import RPi.GPIO as GPIO +import sys + +if sys.argv[1] in ['red','Red','RED','r','R']: + color = 9 +elif sys.argv[1] in ['yellow','Yellow','y','Y','YELLOW']: + color = 10 +elif sys.argv[1] in ['green','Green','g','G','GREEN']: + color = 11 + +# Reset all the pins to LOW +GPIO.setmode(GPIO.BCM) +GPIO.setup(9,GPIO.OUT) +GPIO.output(9, False) +GPIO.setup(10,GPIO.OUT) +GPIO.output(10,False) +GPIO.setup(11,GPIO.OUT) +GPIO.output(11,False) + +#Pin Setup +GPIO.setmode(GPIO.BCM) #Brodcom pin-numbering scheme. +GPIO.setup(color, GPIO.OUT) # Red LED pin set as output. +# Set Pin High + +if sys.argv[2] in ['True','true','t','T','TRUE','1']: + GPIO.output(color, True) +else: + GPIO.output(color, False)