-
Notifications
You must be signed in to change notification settings - Fork 1
/
multimeter.html
228 lines (204 loc) · 8.23 KB
/
multimeter.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Owon B41T+ with web bluetooth example</title>
<script src="./dist/bt-owon-bt.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"
type="module"></script>
</head>
<body onload="setInterval(refreshStatus, 450)">
<style>
.output {
background-color: #f0f0f0;
border-radius: 0.75em;
display: block;
margin: 0.5em;
padding: 0.5em;
}
.status {
background-color: #b0b0b0;
border-radius: 0.75em;
display: block;
margin: 0.5em;
padding: 0.5em;
}
#status {
margin: .5em 0;
font-style: italic;
}
#log {
margin: .5em 0;
white-space: pre-wrap;
}
#status:empty,
#log:empty,
#content:empty {
display: none;
}
.highlight {
border-radius: 0.75em;
border: 1px solid #f0f0f0;
display: block;
margin: 0.5em;
overflow-x: auto;
padding: 0.5em;
}
code {
font-family: Inconsolata, Consolas, monospace;
}
</style>
<h1>Owon B41T+ Multimeter<br /></h1>
<div class="container">
<div class="row">
<div class="col">
<p>
This webpage uses Bluetooth to get the current reading from Owon multimeter using Bluetooth. A
Bluetooth 4.0+ chip is required.
<ul>
<li>Enable bluetooth on multimeter first.
<li>Then click Connect and select "BDM" or "LILLIPUT" device.
<li>The measure shall be shown below
</ul>
</p>
<br />
Status:<div id="status" class="status">?</div><br />
<button id="btnStart" class="btn btn-primary">START</button>
<button id="btnStop" class="btn btn-primary">STOP</button>
<button id="btnDebugLog" class="btn btn-info">LOG (Debug)</button>
<br /><br />
<strong>Latest data:</strong>
<div id="measure" class="output"></div>
<!-- LCD Display Container -->
<div id="lcd-container" class="lcd-container"></div>
<!-- Plugin Script -->
<script src="./dist/lcd.js"></script>
</div>
<div class="col">
<img src="dmm.png" />
</div>
<div class="col">
<strong>Statistics:</strong>
<div id="stats" class="output"></div>
Logs (see Developer Tools console):
<ul>
<li>To adjust: OwonBT.SetLogLevel(value 0..5) where 0=TRACE, 5=SILENT</li>
<li>To enable packet logging into application local storage : OwonBT.SetPacketLog(true)</li>
</ul>
<br />
With auto-range function active, the meter may send invalid data (wrong scale) if the measure is taken
in
the middle of the range update. To have consistent results, disable the auto range.
</div>
</div>
</div>
<div class="container">
<strong>Realtime chart:</strong><br />
<canvas id="myChart"></canvas>
</div>
<script>
var myChart = null;
var lcd = new LCD({
elem: document.getElementById("lcd-container"),
rows: 1, // number of character rows on the LCD screen
columns: 10, // number of character columns on the LCD screen
pixelSize: 4, // size of each pixel
pixelColor: "#000", // color of the pixel
});
async function updateGraph(chartData) {
if (chartData.length <= 0)
return;
const data = {
labels: chartData.map(function (data) { return data["Timestamp"] }),
datasets: [{
label: chartData[0]["Function"],
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: chartData.map(function (data) { return data["Value"] }),
cubicInterpolationMode: 'monotone'
}]
};
const config = {
type: 'line',
data: data,
options: {
scales: {
x: {
type: 'time',
stepSize: 1000,
}
}
}
};
if (myChart == null) {
myChart = new Chart(
document.getElementById('myChart'),
config
);
} else {
myChart.data.labels = data.labels;
myChart.data.datasets[0].data = data.datasets[0].data;
myChart.data.datasets[0].label = data.datasets[0].label;
myChart.options = config.options;
myChart.update('none');
}
}
</script>
<script language="javascript">
chartData = [];
lastData = null;
previousData = null;
/* HELPERS */
function time(text) {
log('[' + new Date().toJSON().substr(11, 8) + '] ' + text);
}
var init = 0;
async function refreshStatus() {
var new_sample = false;
document.getElementById("status").innerHTML = OwonBT.btState.state;
document.getElementById("stats").innerHTML = JSON.stringify(OwonBT.btState.stats).replaceAll(',', '<br/>');
if (OwonBT.btState.formattedResponse != '') {
document.getElementById("measure").innerHTML = OwonBT.btState.formattedResponse + "<br/><small>(" + OwonBT.btState.parsedResponse.DateTime + ")</small>";
if (OwonBT.btState.parsedResponse != null) {
lcd.clearScreen();
if (OwonBT.btState.parsedResponse.Overload) {
lcd.writeString({ string: "OL", offset: 0 });
}
else {
lcd.writeString({ string: OwonBT.btState.parsedResponse["Measurement"].toFixed(4).toString().padStart(12, " "), offset: 0 });
}
}
lastData = OwonBT.btState.parsedResponse;
if (previousData == null || lastData["Timestamp"] != previousData["Timestamp"]) {
if (previousData == null || previousData["Function"] != lastData["Function"]) {
chartData = []; // Reset the chart on function change
}
previousData = lastData;
new_sample = true;
}
} else {
document.getElementById("measure").innerHTML = "No data available";
lastData = null;
}
if (lastData != null && previousData != null && new_sample) {
chartData.push({
"Value": lastData["Overload"] ? NaN : lastData["Value"],
"Timestamp": lastData["Timestamp"].getTime(),
"Function": lastData["Function description"]
});
if (chartData.length > 75) {
chartData.shift();
}
await updateGraph(chartData);
}
}
document.getElementById("btnStart").onclick = async () => { await OwonBT.Start() };
document.getElementById("btnStop").onclick = async () => { await OwonBT.Stop() };
document.getElementById("btnDebugLog").onclick = async () => { await OwonBT.SetLogLevel(1) };
</script>
</body>
</html>