Sat, 04 May 2024 15:18:02 +0200
Log pid of each started thread so we can see which uses the most cpu time.
696
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2024 |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of mbsePi-apps |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * BrewCloud is distributed in the hope that it will be useful, but |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | $(document).ready(function() { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | var dataRecord = {}, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | source = { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | datatype: 'json', |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | cache: false, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | datafields: [ |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | { name: 'address', type: 'string' }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | { name: 'family', type: 'string' }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | { name: 'value', type: 'int' }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | { name: 'present', type: 'string' }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | { name: 'timestamp', type: 'int' } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | ], |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | id: 'address', |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | url: 'getonewire.php' |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | dataAdapter = new $.jqx.dataAdapter(source), |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | // initialize jqxGrid |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | $('#jqxgrid').jqxGrid({ |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | width: 1280, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | height: 630, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | source: dataAdapter, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | theme: theme, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | showstatusbar: true, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | renderstatusbar: function(statusbar) { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Total items: ' + rowCount + '</div>'); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | var container; |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | statusbar.append(container); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | columns: [ |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | { text: 'Address', datafield: 'address' }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | { text: 'Family', datafield: 'family', width: 100 }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | { text: 'Present', datafield: 'present', width: 120 }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | { text: 'Value', datafield: 'value', width: 100 }, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | { text: 'Last change', datafield: 'timestamp', width: 200, |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | ], |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | }); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | websocket.onmessage = function(evt) { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | var msg = evt.data; |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | var obj = JSON.parse(msg); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | if (obj.ping) { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | websocket.send('{"pong":' + obj.ping + '}'); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | if (obj.type == 'onewire') { |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | // Use the message to trigger update. |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | $('#jqxgrid').jqxGrid('updatebounddata'); |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | } |
fe042f9484ac
Added web page to display the one-wire bus live status.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | }); |