1
1
#include " stdafx.h"
2
2
#include " CurrentCostMeterBase.h"
3
3
4
- CurrentCostMeterBase::CurrentCostMeterBase (void )
4
+ CurrentCostMeterBase::CurrentCostMeterBase (void ) :
5
+ m_tempuratureCounter(0 )
5
6
{
6
7
Init ();
7
8
}
@@ -55,17 +56,18 @@ void CurrentCostMeterBase::ExtractReadings()
55
56
}
56
57
57
58
float temp;
58
- float sensor;
59
+ float sensor ( 0.0 ) ;
59
60
float type;
60
61
float reading;
61
62
62
- // if we have the sensor tag then only do the whle house one
63
+ // if we have the sensor tag then read it
63
64
// earlier versions don't have this
64
65
if (m_buffer.find (" <sensor>" ) != std::string::npos)
65
66
{
66
- if (!ExtractNumberBetweenStrings (" <sensor>" , " </sensor>" , &sensor) || sensor != 0 .0 )
67
+ if (!ExtractNumberBetweenStrings (" <sensor>" , " </sensor>" , &sensor) || sensor > 9 .0 )
67
68
{
68
- // not the whole house sensor, ignore
69
+ // no sensor end tag found or too high a sensor number
70
+ // indicating data must be corrupt
69
71
return ;
70
72
}
71
73
}
@@ -76,9 +78,14 @@ void CurrentCostMeterBase::ExtractReadings()
76
78
return ;
77
79
}
78
80
79
- if (ExtractNumberBetweenStrings (" <tmpr>" , " </tmpr>" , &temp))
81
+ // get the temp and only process if it is from the whole house sensor
82
+ if (ExtractNumberBetweenStrings (" <tmpr>" , " </tmpr>" , &temp) && sensor == 0.0 )
80
83
{
81
- SendTempSensor (1 , 255 , temp, " Temp" );
84
+ // only send the temp once a minute to avoid filling up the db
85
+ if ((m_tempuratureCounter++ % 10 ) == 0 )
86
+ {
87
+ SendTempSensor (1 , 255 , temp, " Temp" );
88
+ }
82
89
}
83
90
84
91
float totalPower (0.0 );
@@ -94,7 +101,20 @@ void CurrentCostMeterBase::ExtractReadings()
94
101
{
95
102
totalPower += reading;
96
103
}
97
- SendWattMeter (2 , 1 , 255 , totalPower, " CC Power" );
104
+ if (sensor == 0.0 )
105
+ {
106
+ SendWattMeter (2 , 1 , 255 , totalPower, " CC Whole House Power" );
107
+ }
108
+ else
109
+ {
110
+ // create a suitable default name
111
+ // there can only be 8 sensors so this
112
+ // method is OK and should be faster
113
+ char sensorInt (static_cast <char >(sensor));
114
+ std::string sensorName (" CC Sensor 0 Power" );
115
+ sensorName[10 ] += sensorInt;
116
+ SendWattMeter (2 + sensorInt, 1 , 255 , totalPower, sensorName);
117
+ }
98
118
}
99
119
100
120
bool CurrentCostMeterBase::ExtractNumberBetweenStrings (const char *startString, const char *endString, float *pResult)
0 commit comments