Skip to content

Commit c297812

Browse files
committed
Merge pull request #403 from JohnAdders/currentcost
Add support for multiple meters and throttle temp updates
2 parents d14894a + e3a1ca0 commit c297812

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

hardware/CurrentCostMeterBase.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "stdafx.h"
22
#include "CurrentCostMeterBase.h"
33

4-
CurrentCostMeterBase::CurrentCostMeterBase(void)
4+
CurrentCostMeterBase::CurrentCostMeterBase(void) :
5+
m_tempuratureCounter(0)
56
{
67
Init();
78
}
@@ -55,17 +56,18 @@ void CurrentCostMeterBase::ExtractReadings()
5556
}
5657

5758
float temp;
58-
float sensor;
59+
float sensor(0.0);
5960
float type;
6061
float reading;
6162

62-
// if we have the sensor tag then only do the whle house one
63+
// if we have the sensor tag then read it
6364
// earlier versions don't have this
6465
if(m_buffer.find("<sensor>") != std::string::npos)
6566
{
66-
if(!ExtractNumberBetweenStrings("<sensor>", "</sensor>", &sensor) || sensor != 0.0)
67+
if(!ExtractNumberBetweenStrings("<sensor>", "</sensor>", &sensor) || sensor > 9.0)
6768
{
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
6971
return;
7072
}
7173
}
@@ -76,9 +78,14 @@ void CurrentCostMeterBase::ExtractReadings()
7678
return;
7779
}
7880

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)
8083
{
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+
}
8289
}
8390

8491
float totalPower(0.0);
@@ -94,7 +101,20 @@ void CurrentCostMeterBase::ExtractReadings()
94101
{
95102
totalPower += reading;
96103
}
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+
}
98118
}
99119

100120
bool CurrentCostMeterBase::ExtractNumberBetweenStrings(const char *startString, const char *endString, float *pResult)

hardware/CurrentCostMeterBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ class CurrentCostMeterBase : public CDomoticzHardwareBase
1717
void ExtractReadings();
1818
bool ExtractNumberBetweenStrings(const char *startString, const char *endString, float *pResult);
1919
std::string m_buffer;
20+
unsigned int m_tempuratureCounter;
2021
};
2122

webserver/proxyclient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "request.hpp"
55
#include "reply.hpp"
66
#include "request_parser.hpp"
7+
#include "../main/Helper.h"
78
#include "../main/SQLHelper.h"
89
#include "../webserver/Base64.h"
910
#include "../tcpserver/TCPServer.h"
@@ -91,7 +92,7 @@ namespace http {
9192
}
9293
if (b_Connected) {
9394
_socket.lowest_layer().close();
94-
boost::this_thread::sleep_for(boost::chrono::seconds(10));
95+
sleep_seconds(10);
9596
}
9697
b_Connected = false;
9798
boost::asio::ip::tcp::resolver resolver(_io_service);

0 commit comments

Comments
 (0)