-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
77 lines (60 loc) · 1.73 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
<html>
<title>Accessing REST API on localhost</title>
<head>
<script>
var baseUrl = 'http://localhost:5000/'
function httpGet( url, callback )
{
httpReq( "GET", url, callback, null )
}
function httpPut( url, data )
{
json_data = JSON.stringify( data )
httpReq( "PUT", url, null, json_data )
}
function httpReq( method, url, callback, data )
{
var xhr = new XMLHttpRequest();
var timeoutTime = 1000;
xhr.ontimeout = function () {
console.error("The request for " + url + " timed out.");
};
xhr.onload = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
if( callback != null ) {
callback( JSON.parse( xhr.responseText ) );
}
}
updateLastMessage( xhr.status + " " + xhr.statusText + "<br />" + xhr.responseText );
}
};
xhr.open( method, url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.timeout = timeoutTime;
xhr.send(data);
}
function updateA0Value( data )
{
document.getElementById('A0current').innerHTML = data['value'];
document.getElementById('A0set').value = data['value'];
}
function updateLastMessage( text )
{
document.getElementById('lastMessage').innerHTML = text;
}
</script>
</head>
<body>
<button type="button" onclick="httpGet( baseUrl + 'gpio/A0', updateA0Value )">Click to fetch latest value of A0</button>
Current values from device: <br />
<ul>
<li>A0: <label id="A0current">- X -</label> -
set: <input name='A0set' id="A0set"></input>
<button type="button" onclick="httpPut( baseUrl + 'gpio/A0', { 'value': document.getElementById('A0set').value } )">set</button>
</li>
</ul>
<br />
last message: <label id="lastMessage">- X -</label>
</body>
</html>