-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.htm
124 lines (100 loc) · 3.05 KB
/
settings.htm
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
118
119
120
121
122
123
124
<!DOCTYPE HTML><html>
<head>
<! define meta data >
<meta name="viewport" content="width=device-width, initial-scale=1">
<! define the style CSS of your page >
<style>
html {font-family: Arial; display: inline-block; text-align: center;}
h1 {font-size: 2.9rem;}
h2 {font-size: 2.1rem;}
p {font-size: 1.9rem;}
body {max-width: 400px; margin:0px auto; padding-bottom: 30px;}
</style>
</head>
<body>
<! Edit the pages your heading 2 >
<h2>ESP32 Multi Slider Settings</h2>
<input type='file' name='upload' id='upload' value=''><span id="percent"></span>
<script>
'use strict';
var gateway = `ws://${window.location.hostname}/ws`;
var websocket;
var state = {};
var json = {};
window.addEventListener('load', onLoad);
function initWebSocket() {
console.log('Trying to open a WebSocket connection...');
websocket = new WebSocket(gateway);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage;
}
function onOpen(event) {
console.log('Connection opened');
}
function onClose(event) {
console.log('Connection closed');
setTimeout(initWebSocket, 2000);
}
function onMessage(event) {
json = JSON.parse(event.data);
console.log(json);
if(json.reload) location.reload();
}
// on page load
function onLoad(event) {
initWebSocket();
document.getElementById("upload").addEventListener("change", (e) => processFile(e));
}
function processFile(e) {
const reader = new FileReader();
reader.readAsText(e.path[0].files[0]);
var myfilename = e.path[0].files[0].name;
reader.onload = (e) => {
var myfile = e.target.result;
var myarray = myfile.split('');
var mylength = myfile.length;
i = 0;
k = 1;
var sendArray = [];
sendArray[0] = ("upld:" + myfilename);
function getChunk() {
var sendstring = '';
for (var j = 0; j < 512; j++) {
if (i < mylength) {
sendstring += myarray[i];
}
i++
}
return sendstring;
}
function loopThroughSplittedText(splittedText) {
splittedText.forEach(function (text, i) {
setTimeout(function () {
sendMessage(text, i);
}, i * 500)
})
}
while (i < mylength) {
sendArray[k] = ("file:" + getChunk());
k++;
}
sendArray[k] = ("comp");
sendstring = '';
loopThroughSplittedText(sendArray);
};
}
function sendMessage(data, index) {
if (index) var percent = index / k * 100;
if (data.substring(0, 4) == 'file') document.getElementById('percent').innerHTML = percent + ' %';
if (data.substring(0, 4) == 'comp') {
document.getElementById('percent').innerHTML = "completed";
setTimeout(() => {
sendMessage("reload");
}, 2000);
}
websocket.send(data);
}
</script>
</body>
</html>