-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemperatureloggerApp.qml
More file actions
209 lines (167 loc) · 6.42 KB
/
TemperatureloggerApp.qml
File metadata and controls
209 lines (167 loc) · 6.42 KB
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
import QtQuick 2.1
import qb.components 1.0
import qb.base 1.0
import "temperatureLogger.js" as TemperatureLoggerJS
App {
id: temperatureloggerApp
// These are the URL's for the QML resources from which our widgets will be instantiated.
// By making them a URL type property they will automatically be converted to full paths,
// preventing problems when passing them around to code that comes from a different path.
property url thumbnailIcon: "qrc:/tsc/buienradar.png"
property TemperatureloggerScreen temperatureloggerScreen
property url trayUrl2 : "TemperatureloggerTray.qml";
property string timeStr
property variant arycurrentTemp : []
property variant arycurrentSetpoint : []
property variant arycurrentBuienradar : []
property int nowlinexcoordinate : 20
property string nowleftlabel : "--"
property string nowrightlabel : "--"
property real temperatuurGC
property int temperatuurGCIndex
property int tempOffset : -8
QtObject {
id: p
property url temperatureloggerScreenUrl : "TemperatureloggerScreen.qml"
}
function init() {
registry.registerWidget("screen", p.temperatureloggerScreenUrl, this, "temperatureloggerScreen");
registry.registerWidget("systrayIcon", trayUrl2, this, "temperatureloggerTray");
}
function readBuienradarTemp() {
// read Buienradar tmp reading
var doc2 = new XMLHttpRequest();
doc2.onreadystatechange = function() {
if (doc2.readyState == XMLHttpRequest.DONE) {
if (doc2.responseText.length > 2) {
var i = doc2.responseText.indexOf(":");
temperatuurGC = tempOffset + parseFloat(doc2.responseText.substring(0, i));
//calculate index in array 27.5:08/03/2017 21:00:00
var hour = parseInt(doc2.responseText.substring(i+12, i+14));
var min = parseInt(doc2.responseText.substring(i+15, i+17));
temperatuurGCIndex = (hour * 6) + Math.round(-0.5 + (min /10));
}
}
}
doc2.open("GET", "file:///var/volatile/tmp/actualBuienradarTemp.txt", true);
doc2.send();
}
function updateActualAndProgramTemp() {
var xmlhttpt = new XMLHttpRequest();
xmlhttpt.onreadystatechange = function() {
nowleftlabel = xmlhttpt.readyState;
if ( xmlhttpt.readyState == 4 ) {
nowrightlabel = xmlhttpt.status;
if ( xmlhttpt.status == 200 ) {
nowleftlabel = xmlhttpt.readyState;
nowrightlabel = xmlhttpt.status;
//calculate index in array
var datum = new Date();
var hour = datum.getHours();
var min = datum.getMinutes();
var index = (hour * 6) + Math.round(-0.5 + (min / 10));
//read temp readings
var txtStat = xmlhttpt.responseText;
var idxcurrentSetpoint = txtStat.indexOf("currentSetpoint");
var idxcurrentTemp = txtStat.indexOf("currentTemp");
var currentSetpoint = tempOffset + (parseInt(txtStat.substring(18 + idxcurrentSetpoint, 22 + idxcurrentSetpoint)) / 100);
var currentTemp = tempOffset + (parseInt(txtStat.substring(14 + idxcurrentTemp , 18 + idxcurrentTemp)) / 100);
//store values in arrays
arycurrentTemp = TemperatureLoggerJS.addReading(arycurrentTemp , index, currentTemp);
arycurrentSetpoint = TemperatureLoggerJS.addReading(arycurrentSetpoint , index, currentSetpoint);
arycurrentBuienradar = TemperatureLoggerJS.addReading(arycurrentBuienradar , index, temperatuurGC);
//update positioning line and labels on screen
if (isNxt) {
nowlinexcoordinate = (697 * index * 1.25 / 144) + 32;
} else {
nowlinexcoordinate = (697 * index / 144) + 25;
}
var dag = datum.getDate();
var maand = datum.getMonth();
nowleftlabel = dag + "-" + (maand+1);
datum.setDate(datum.getDate() - 1);
dag = datum.getDate();
maand = datum.getMonth();
nowrightlabel = dag + "-" + (maand+1);
}
}
}
xmlhttpt.open("GET", "http://127.0.0.1/happ_thermstat?action=getThermostatInfo", true );
xmlhttpt.send();
}
function shiftArrays(delta) {
arycurrentTemp = TemperatureLoggerJS.shiftArray(arycurrentTemp , delta);
arycurrentSetpoint = TemperatureLoggerJS.shiftArray(arycurrentSetpoint , delta);
arycurrentBuienradar = TemperatureLoggerJS.shiftArray(arycurrentBuienradar , delta);
saveTemperatures();
}
function readSavedFiles() {
var doc2 = new XMLHttpRequest();
doc2.onreadystatechange = function() {
if (doc2.readyState == XMLHttpRequest.DONE) {
arycurrentTemp = doc2.responseText.split(",");
}
}
doc2.open("GET", "file:///HCBv2/var/actualTempReading24H.txt", true);
doc2.send();
var doc5 = new XMLHttpRequest();
doc5.onreadystatechange = function() {
if (doc5.readyState == XMLHttpRequest.DONE) {
arycurrentSetpoint = doc5.responseText.split(",");
}
}
doc5.open("GET", "file:///HCBv2/var/actualTempSetpoint24H.txt", true);
doc5.send();
var doc4 = new XMLHttpRequest();
doc4.onreadystatechange = function() {
if (doc4.readyState == XMLHttpRequest.DONE) {
arycurrentBuienradar = doc4.responseText.split(",");
}
}
doc4.open("GET", "file:///HCBv2/var/actualTempBuienradar24H.txt", true);
doc4.send();
var doc3 = new XMLHttpRequest();
doc3.onreadystatechange = function() {
if (doc3.readyState == XMLHttpRequest.DONE) {
tempOffset = parseInt(doc3.responseText);
}
}
doc3.open("GET", "file:///HCBv2/var/actualTempOffset.txt", true);
doc3.send();
}
function saveTemperatures() {
var doc3 = new XMLHttpRequest();
doc3.open("PUT", "file:///HCBv2/var/actualTempReading24H.txt");
doc3.send(arycurrentTemp);
var doc4 = new XMLHttpRequest();
doc4.open("PUT", "file:///HCBv2/var/actualTempSetpoint24H.txt");
doc4.send(arycurrentSetpoint);
var doc5 = new XMLHttpRequest();
doc5.open("PUT", "file:///HCBv2/var/actualTempBuienradar24H.txt");
doc5.send(arycurrentBuienradar);
var doc6 = new XMLHttpRequest();
doc6.open("PUT", "file:///HCBv2/var/actualTempOffset.txt");
doc6.send(tempOffset);
}
Component.onCompleted: {
//read default location
arycurrentTemp = TemperatureLoggerJS.initArray(arycurrentTemp);
arycurrentSetpoint = TemperatureLoggerJS.initArray(arycurrentSetpoint);
arycurrentBuienradar = TemperatureLoggerJS.initArray(arycurrentBuienradar);
readSavedFiles();
readBuienradarTemp();
updateActualAndProgramTemp();
}
Timer {
id: datetimeTimertl
interval: 600000
triggeredOnStart: false
running: true
repeat: true
onTriggered: {
readBuienradarTemp();
updateActualAndProgramTemp();
saveTemperatures();
}
}
}