Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is just a undersigned html page for flood system (will do html page features in the future)
- //This is for Deviance
- //Twitter: @ItsWizardly | Instagram: @imWizardly | Discord: wizard#7815
- <html>
- <head>
- <title> Flood detection [need bolt] </title>
- <script type="text/javascript" src="/serveFile?filename=bolt.js"> setDebug(true); </script>
- </head>
- <body onload="init();" bgcolor="#FFFFFF">
- <button onclick="myLoop(1);">START SENSOR</button>
- <script>
- var avg_curr = 0; //avg of current minute
- var avg_prev=0; //avg for previous minutes
- var ctr=0,ctr2=0;
- function myLoop (i) {
- setTimeout(function () {
- var input = new XMLHttpRequest();
- input.onreadystatechange = function() {
- if (input.readyState == 4 && input.status == 200) {
- //document.getElementById("output").innerHTML = input.responseText; //for debuging
- var flag = typeof input.responseText != 'object' ? JSON.parse(input.responseText) : input.responseText;
- alert(flag.value); //It will print the value of second field //for debuging
- if(flag.value != "failed")
- {
- var piezo = parseInt(flag.value);
- if(ctr == 4){
- var check = avg_curr - avg_prev;
- var alarm = new XMLHttpRequest();
- if (check >=25){
- /*sets the Digital pin 0 HIGH*/
- alarm.open("GET", "/digitalWrite?pin=0&state=HIGH",true);
- }
- else{
- alarm.open("GET", "/digitalWrite?pin=0&state=LOW",true);
- }
- alarm.send();
- ctr2++;
- avg_prev = (avg_prev+avg_curr)/ctr2;
- ctr =0;
- }
- else {
- ctr++;
- avg_curr = (avg_curr+piezo)/ctr;
- }
- }
- }
- };
- input.open("GET", "/analogRead?pin=A3",true);
- input.send();
- //console.log(10); //for debuging
- if (i) myLoop(i); // decrement i and call myLoop again if i > 0
- }, 1500)
- }
- /*initiator function to set the IF condition and THEN action for IFTTT */
- function init()
- {
- var ifttt = new XMLHttpRequest();
- iftttt.open("POST","/iftttSettings",true );
- ifttt.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
- ifttt.send('key=https://maker.ifttt.com/trigger/attention_people/with/key/daqNS-hP1rjC9iYeUPVCx2&pin=0&state=HIGH&enable=1');
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement