Database - Assignment 6

Node Red - Flow

I've written a simple node to send an email if the humidity increases which happens when I breathe down the humidity sensor.

image

image
image
image

My Node-Red flow

[{"id":"2e3aed9b.629962","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4f434552.b3580c","type":"mqtt in","z":"2e3aed9b.629962","name":"Device 12","topic":"itp/device_12/humidity","qos":"2","datatype":"auto","broker":"c168da8b.f1eb28","x":150,"y":380,"wires":[["4ed4bfdd.b75e2"]]},{"id":"4ed4bfdd.b75e2","type":"function","z":"2e3aed9b.629962","name":"Send Email","func":"\nconst DOMAIN = '[sandboxeb23dce4a0a3474b851d5a9a296c6845.mailgun.org](http://sandboxeb23dce4a0a3474b851d5a9a296c6845.mailgun.org/)';\nconst api_key = 'key-205d30lojk4u9mvk9ee9fk0y-66pli02'\n\nvar mailgun = context.global.get('mailgun');\n\nconsole.log(msg)\n\n\nif (parseFloat(msg.payload) > 53.0) {\n const mg = mailgun({apiKey: api_key, domain: DOMAIN});\n const data = {\n \tfrom: 'Excited User [me@samples.mailgun.org](mailto:me@samples.mailgun.org)',\n \tto: 'wasif.hyder@gmail.com, DEVICE_12@YO_HOUSE',\n \tsubject: 'Help!',\n \ttext: 'Psttt. I think someone is breathing on me!'\n };\n \n console.log(\"Met requirement to send email\")\n \n mg.messages().send(data, function (error, body) {\n \tconsole.log(body);\n }); \n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":500,"wires":[[]]},{"id":"c168da8b.f1eb28","type":"mqtt-broker","name":"Dev2Db","broker":"[dev2db.com](http://dev2db.com/)","port":"8883","tls":"","clientid":"","usetls":true,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]