-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
141 lines (132 loc) · 6.03 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<title>ThingSpeak Logger</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript">
function saveThingspeakSettings() {
localStorage.setItem('server', $('#serverinput').val());
localStorage.setItem('channel', $('#channelinput').val());
localStorage.setItem('writekey', $('#writekeyinput').val());
getThingspeakSettings();
}
function getThingspeakSettings() {
var server = localStorage.getItem('server');
var channel = localStorage.getItem('channel');
var writekey = localStorage.getItem('writekey');
if (server == null || channel == null || writekey == null) {
return 0;
}
$('#serverinput').val(server);
$('#channelinput').val(channel);
$('#writekeyinput').val(writekey);
//$('#thingspeakform').attr('action', server + '/update');
$('#writekey').val(writekey);
return 1;
}
function clearThingspeakSettings() {
console.warn("localStorage cleared");
localStorage.clear();
}
function onSuccess(data, status) {
data = $.trim(data);
$("#notification").text("Data saved successfully!");
$("#notification").popup("open", setTimeout(function() {
$('#notification').popup("close");
}, 2000));
}
function onError(data, status) {
$("#notification").text("There has been an error: " + status );
$("#notification").popup("open");
}
$(document).ready(function() {
$("#submittothingspeak").click(function(e,data){
var formData = $("#thingspeakform").serialize();
$.ajax({
type: "POST",
url: localStorage.getItem('server') + '/update',
cache: false,
data: formData,
complete: onSuccess(),
timeout: 2000
});
return false;
});
});
$('#home').live('pageinit', function(e,data){
var isset = getThingspeakSettings();
if (isset) {
console.warn("all set!");
} else {
$.mobile.changePage('#settings','slidedown');
console.warn("not set");
}
});
$('#settings').live('pageinit', function(e,data) {
$('#savesettings').click(function(e) {
saveThingspeakSettings();
e.preventDefault();
$.mobile.changePage('#home');
});
$('#clearsettings').click(function(e) {
clearThingspeakSettings();
e.preventDefault();
$.mobile.changePage('#home');
});
});
</script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h2>ThingSpeak</h2>
<a href="#settings" data-icon="gear" data-iconpos="notext" data-rel="dialog" data-transition="slidedown">Settings</a>
</div>
<div data-role="content">
<div id="notification" class="ui-content" data-history="false" data-role="popup" data-position-to="window" data-theme="e"></div>
<form id="thingspeakform">
<input id="writekey" type="hidden" name="key"/>
<div data-role="collapsible">
<h3>Status</h3>
<div data-role="fieldcontain"><label for="status">Status:</label><input id="status" type="text" name="status" data-mini="true"/></div>
</div>
<div data-role="collapsible" data-collapsed="false">
<h3>Fields</h3>
<div data-role="fieldcontain"><label for="field1">Field 1:</label><input id="field1" type="range" min="0" max="10" value="5" name="field1" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field2">Field 2:</label><input id="field2" type="range" min="0" max="10" value="5" name="field2" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field3">Field 3:</label><input id="field3" type="range" min="0" max="10" value="5" name="field3" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field4">Field 4:</label><input id="field4" type="range" min="0" max="10" value="5" name="field4" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field5">Field 5:</label><input id="field5" type="range" min="0" max="10" value="5" name="field5" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field6">Field 6:</label><input id="field6" type="range" min="0" max="10" value="5" name="field6" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field7">Field 7:</label><input id="field7" type="range" min="0" max="10" value="5" name="field7" data-mini="true" data-highlight="true"></div>
<div data-role="fieldcontain"><label for="field8">Field 8:</label><input id="field8" type="range" min="0" max="10" value="5" name="field8" data-mini="true" data-highlight="true"></div>
</div>
<div data-role="collapsible">
<h3>Geolocation</h3>
<div data-role="fieldcontain"><label for="lat">Latitude:</label><input id="lat" type="text" name="lat"></div>
<div data-role="fieldcontain"><label for="long">Longitude:</label><input id="long" type="text" name="long"></div>
<div data-role="fieldcontain"><label for="elevation">Elevation:</label><input id="elevation" type="text" name="elevation"></div>
</div>
<div><button id="submittothingspeak"/>Submit!</button></div>
</form>
</div>
</div>
<div data-role="dialog" id="settings">
<div data-role="header">
<h2>Settings</h2>
</div>
<div data-role="content">
<form id="settingsform">
<div data-role="fieldcontain"><label for="server">Server URL:</label><input id="serverinput" name="server" type="text"/></div>
<div data-role="fieldcontain"><label for="channel">Channel:</label><input id="channelinput" name="channel" type="text"/></div>
<div data-role="fieldcontain"><label for="writekey">Write Key:</label><input id="writekeyinput" name="writekey" type="text"/></div>
<button id="savesettings">Store Locally</button>
<button id="clearsettings">Wipe Settings</button>
</form>
</div>
</div>
</body>
</html>