-
-
Save utkarsh-b690/5d1d81db506d35dcca427ca314f69b35 to your computer and use it in GitHub Desktop.
Codes for sublime text. To be saved in the folder "Admin"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Auto update lift code</title> | |
</head> | |
<body> | |
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script> | |
<script type="text/javascript"> | |
var sl_no, code, text = document.getElementById("text"), text2 = document.getElementById("text2"); | |
updateRecord(); | |
setInterval(updateRecord, 30000); | |
function updateRecord() { | |
code = Math.floor(Math.random() * 1000000); | |
var xmlhttp1 = new XMLHttpRequest(); | |
xmlhttp1.onreadystatechange = function() { | |
if(this.readyState == 4 && this.status == 200) { | |
sl_no = JSON.parse(this.responseText); | |
if(sl_no != "undefined" && sl_no != "null"){ | |
var i=0, total = sl_no.length; | |
for(i; i <= total-1; i++) { | |
var device; | |
lift_code = code + i; | |
if(lift_code > 999999) { | |
lift_code -= 1000000; | |
} | |
console.log(sl_no[i].sl_no , "," , lift_code); | |
var xmlhttp2 = new XMLHttpRequest(); | |
xmlhttp2.onreadystatechange = function() { | |
if(this.readyState == 4 && this.status == 200) { | |
device = JSON.parse(this.responseText); | |
serialWrite(device.api_key, device.device_name, "P," + device.lift_code); | |
} | |
}; | |
xmlhttp2.open("post", "update_record.php?slNo=" + sl_no[i].sl_no + "&liftCode=" + lift_code, 1); | |
xmlhttp2.send(); | |
} | |
} | |
else { | |
console.log("undefined"); | |
} | |
} | |
}; | |
xmlhttp1.open("post", "fetch_sl_no.php", 1); | |
xmlhttp1.send(); | |
} | |
function serialWrite(api_key,d_name,serialdata) { | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
var obj = JSON.parse(xmlhttp.responseText); | |
if(obj.success=="1"){ | |
console.log("Command sent successfully"); | |
} | |
else{ | |
console.log("Command failed"); | |
} | |
console.log(serialdata); | |
} | |
}; | |
xmlhttp.open("GET",base_url+api_key+"/serialWrite?data="+serialdata+"&deviceName=BOLT"+d_name,true); | |
xmlhttp.send(); | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "root"; | |
$password = ""; | |
$database = "verticel"; | |
$conn = new mysqli($servername, $username, $password, $database); | |
if($conn->connect_error) { | |
die("Could not connect"); | |
} | |
$stmt1 = "SELECT sl_no FROM elevator_config;"; | |
$result = $conn-> query($stmt1); | |
$sl_no = $result-> fetch_all(MYSQLI_ASSOC); | |
echo json_encode($sl_no); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "root"; | |
$password = ""; | |
$database = "verticel"; | |
$conn = new mysqli($servername, $username, $password, $database); | |
if($conn-> connect_error) { | |
die("Could not connect"); | |
} | |
$sl_no = $_GET['slNo']; | |
$lift_code = $_GET['liftCode']; | |
$stmt1 = "UPDATE elevator_config SET lift_code = '".$lift_code."' WHERE sl_no = '".$sl_no."';"; | |
$conn-> query($stmt1); | |
$stmt2 = "SELECT api_key, device_name, lift_code FROM elevator_config WHERE sl_no = '".$sl_no."';"; | |
$result = $conn-> query($stmt2); | |
$response = $result-> fetch_assoc(); | |
echo json_encode($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment