-
Notifications
You must be signed in to change notification settings - Fork 9
/
Temperature.cpp
87 lines (78 loc) · 2.12 KB
/
Temperature.cpp
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
//
// Temperature
// Retrieves the actual temperatue and calculates average and 'Graaddagen factor'
#include "Temperature.h"
Temperature::Temperature(char* ws, int sid, int f) : BaseSensor(1000,sid, f) // 1000 is a dummy value
{
weatherStation = ws;
Type = 5; // temperature graph of PvOutput
}
void Temperature::Begin(byte i)
{
BaseSensor::Begin(i); // to initialize other variables
todayCnt = 0;
needUpdate=true;
}
void Temperature::CalculateActuals()
{
// Actual is the temperature in 0.1 deg
Actual = actual * 10;
}
void Temperature::Loop(int m)
{
// limit the temperature reading to once every 10 minutes
if(m%10==0)
{
if(needUpdate)
{
GetTemperature();
needUpdate = false;
}
}
else needUpdate = true;
}
void Temperature::GetTemperature()
{
// Get temperature from buienradar
EthernetClient buienradarClient;
buienradarClient.setTimeout(2000);
if(buienradarClient.connect((char*)"xml.buienradar.nl",80))
{
buienradarClient << F("GET / HTTP/1.1") << endl;
buienradarClient << F("Host: xml.buienradar.nl") << endl << endl;
if(buienradarClient.find(weatherStation)) //6275 = Arnhem
{
if(buienradarClient.find((char*)"<temperatuurGC>"))
{
actual = buienradarClient.parseFloat();
// Calculate new average
average = (todayCnt * average) + actual;
todayCnt++;
average /= todayCnt;
}
}
buienradarClient.stop();
}
}
float Temperature::GetFactor(long Gas, int hr)
{
// Calculate 'graaddagen' = 18 - average temperature of today
float gd = 18 - average;
if (gd < 0 || hr == 0)
{
gd = 0;
gdFactor = 0;
}
else
{
// Factor is gas usage per 'graaddag' extrapolated to the end of the day (*24/Hr)
gdFactor = 2.4 * (Gas / gd) / hr ;
}
return gdFactor;
}
void Temperature::Status(Print& client)
{
BaseSensor::Status(client);
client << F("<td>avg=") << average;
client << F(" gdFactor=") << gdFactor;
}