-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
117 lines (96 loc) · 4.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Find My Maslow</title>
<style>
body {
margin: 0;
}
</style>
<link rel="stylesheet" href="maslowCreate.css" type="text/css">
<link rel="stylesheet" href="login.css" type="text/css">
<link rel="stylesheet" href="menuIcons.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.12.0/bootstrap-social.min.css">
<link rel="icon" href="https://www.maslowcnc.com/favicon.ico">
</head>
<body id= "mainBody">
<div class = "login-popup " id = "projects-popup">
<div class="login-page">
<div class="form animate fadeInUp one">
<div id="gitSide" class="logindiv">
<img class="logo" src='https://maslowcnc.github.io/Find-My-Maslow/maslow-logo.png' alt="logo">
<div id="welcome"><img src='https://maslowcnc.github.io/Find-My-Maslow/maslowcreate.svg' alt="logo" style="width: 300px;padding: 10px; margin-bottom: 0;"></div>
<p style= "padding: 0 20px">Find and connect to your Maslow.</p>
<form class="login-form">
<!--Credit to https://codepen.io/colorlib/pen/rxddKy -->
<button type="button" onclick="startScan()" id = "loginButton" style ="height: 40px;">Find My Maslow</button>
<p class="message">This will scan your network and find connected Maslow machines.</p>
</form>
</div>
<!-- <div id="nonGitSide" class="logindiv curiousBrowse"> -->
<!-- <p style="justify-content:flex-start; display: inline; width: 80%; ">Check out what others have designed in Maslow Create</p> -->
<!-- <form class="login-form"> -->
<!-- <button type="button" class= "browseButton" id = "browseNonGit" style ="padding: 0 30px;">Browse all projects</button> -->
<!-- </form> -->
<!-- </div> -->
</div>
</div>
<div class="browse"></div>
</div>
<script>
var numberScanned = 0;
var totalToScan = 0;
var numberFound = 0;
function reqListener (ipAddress, e) {
console.log("IP address: " + ipAddress);
updatePercent();
if(e.explicitOriginalTarget.response.includes("ESP")){
console.log("ESP32 FOUND AT: " + ipAddress);
numberFound = numberFound + 1;
var scanList = document.getElementById('scan_list')
scanList.innerHTML = scanList.innerHTML + '<h1>Maslow found at <a href="' + ipAddress + '"> ' + ipAddress + '</a></h1>'
}
}
function updatePercent() {
numberScanned = numberScanned + 1;
console.log("Percent complete: " + 100*(numberScanned/totalToScan) + "%");
var scanList = document.getElementById('scan_list')
const percentComplete = Math.round(100*(numberScanned/totalToScan));
scanList.innerHTML = scanList.innerHTML.replace(/\((.*?)\)/, '('+percentComplete+'%)')
if(percentComplete >= 100 && numberFound == 0){
var scanList = document.getElementById('scan_list')
scanList.innerHTML = scanList.innerHTML + '<h1>No machines found</h1>'
}
}
function startScan() {
var popup = document.getElementById('projects-popup')
//Remove everything in the popup now
while (popup.firstChild) {
popup.removeChild(popup.firstChild)
}
var welcome = document.createElement("div")
welcome.setAttribute("style", "margin: 10px; text-align: center;")
welcome.setAttribute("id", "scan_list");
const ipPrefix = "http://192.168.1.";
welcome.innerHTML = '<p>Scanning ' + ipPrefix + '.0 to '+ ipPrefix +'.255 (0%)</p><hr>'
popup.appendChild(welcome)
var ipIteration = 0;
const maxIteration = 255;
totalToScan = maxIteration - ipIteration;
while(ipIteration < maxIteration){
const ipAddress = ipPrefix + ipIteration;
console.log("Scanning: " + ipAddress);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", (e)=> {reqListener(ipAddress, e)});
xhr.open("GET", ipAddress, true);
xhr.addEventListener('error', updatePercent);
xhr.send(null);
ipIteration = ipIteration + 1;
}
console.log("End");
}
</script>
</body>
</html>