Skip to content

Commit 4b953ff

Browse files
committed
- Fixed: MySensors, corrected sending localtime
1 parent 916bb6d commit 4b953ff

File tree

7 files changed

+30
-117
lines changed

7 files changed

+30
-117
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Version 2.xxx (xxxx 2015)
9494
- Fixed: Weather tab, nofications
9595
- Changed: EnOcean rocker inclusion (thanks to zorgluf!)
9696
- Implemented: Icons for RFXMeter Gas/Water
97+
- Fixed: MySensors, corrected sending localtime
9798

9899
Version 2.2563 (June 14th 2015)
99100
- Implemented: WebServer, native SSL and keep-alive, big thanks to chimit!!!!

hardware/MySensorsBase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <algorithm>
1212
#include <iostream>
1313
#include <boost/bind.hpp>
14+
#include <boost/date_time/posix_time/posix_time.hpp>
1415

1516
#include <ctime>
1617

@@ -1130,10 +1131,9 @@ void MySensorsBase::ParseLine()
11301131
case I_TIME:
11311132
//send time in seconds from 1970 with timezone offset
11321133
{
1133-
time_t atime = mytime(NULL);
1134-
struct tm ltime;
1135-
localtime_r(&atime, &ltime);
1136-
sstr << mktime(&ltime);
1134+
boost::posix_time::ptime tlocal(boost::posix_time::second_clock::local_time());
1135+
time_t fltime = boost::posix_time::to_time_t(tlocal);
1136+
sstr << fltime;
11371137
SendCommand(node_id, child_sensor_id, message_type, I_TIME, sstr.str());
11381138
}
11391139
break;

main/SQLHelper.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5449,12 +5449,12 @@ unsigned long long CSQLHelper::UpdateValueLighting2GroupCmd(const int HardwareID
54495449
// it will be updated too. The reason we choose the UpdateValue is the propagation of the change to all units involved, including LogUpdate.
54505450

54515451
unsigned long long devRowIndex = -1;
5452-
typedef std::vector<std::vector<std::string> > VectorVectorString;
5452+
typedef std::vector<std::vector<std::string> > VectorVectorString;
54535453

54545454
VectorVectorString result = safe_query("SELECT Unit FROM DeviceStatus WHERE ((DeviceID=='%q') AND (Type==%d) AND (SubType==%d) AND (nValue!=%d))",
54555455
ID,
5456-
pTypeLighting2,
5457-
subType,
5456+
pTypeLighting2,
5457+
subType,
54585458
nValue);
54595459

54605460
for (VectorVectorString::const_iterator itt = result.begin(); itt != result.end(); ++itt)
@@ -5466,21 +5466,21 @@ unsigned long long CSQLHelper::UpdateValueLighting2GroupCmd(const int HardwareID
54665466
}
54675467

54685468

5469-
void CSQLHelper::Lighting2GroupCmd(const std::string &ID, const unsigned char subType, const unsigned char GroupCmd)
5470-
{
5471-
time_t now = mytime(NULL);
5472-
struct tm ltime;
5473-
localtime_r(&now, &ltime);
5474-
5475-
safe_query("UPDATE DeviceStatus SET nValue='%d', sValue='%s', LastUpdate='%04d-%02d-%02d %02d:%02d:%02d' WHERE (DeviceID=='%q') And (Type==%d) And (SubType==%d) And (nValue!=%d)",
5476-
GroupCmd,
5477-
"OFF",
5478-
ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec,
5479-
ID.c_str(),
5480-
pTypeLighting2,
5481-
subType,
5482-
GroupCmd);
5483-
}
5469+
void CSQLHelper::Lighting2GroupCmd(const std::string &ID, const unsigned char subType, const unsigned char GroupCmd)
5470+
{
5471+
time_t now = mytime(NULL);
5472+
struct tm ltime;
5473+
localtime_r(&now, &ltime);
5474+
5475+
safe_query("UPDATE DeviceStatus SET nValue='%d', sValue='%s', LastUpdate='%04d-%02d-%02d %02d:%02d:%02d' WHERE (DeviceID=='%q') And (Type==%d) And (SubType==%d) And (nValue!=%d)",
5476+
GroupCmd,
5477+
"OFF",
5478+
ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec,
5479+
ID.c_str(),
5480+
pTypeLighting2,
5481+
subType,
5482+
GroupCmd);
5483+
}
54845484

54855485
void CSQLHelper::GeneralSwitchGroupCmd(const std::string &ID, const unsigned char subType, const unsigned char GroupCmd)
54865486
{

main/WebServer.cpp

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -6986,6 +6986,10 @@ namespace http {
69866986
root["result"][ii]["XOffset"] = sd[24].c_str();
69876987
root["result"][ii]["YOffset"] = sd[25].c_str();
69886988
root["result"][ii]["PlanID"] = sd[26].c_str();
6989+
root["result"][ii]["AddjValue"] = AddjValue;
6990+
root["result"][ii]["AddjMulti"] = AddjMulti;
6991+
root["result"][ii]["AddjValue2"] = AddjValue2;
6992+
root["result"][ii]["AddjMulti2"] = AddjMulti2;
69896993
sprintf(szData, "%d, %s", nValue, sValue.c_str());
69906994
root["result"][ii]["Data"] = szData;
69916995

@@ -7097,14 +7101,7 @@ namespace http {
70977101

70987102
root["result"][ii]["IsSubDevice"] = bIsSubDevice;
70997103

7100-
if (switchtype == STYPE_OnOff)
7101-
{
7102-
root["result"][ii]["AddjValue"] = AddjValue;
7103-
root["result"][ii]["AddjMulti"] = AddjMulti;
7104-
root["result"][ii]["AddjValue2"] = AddjValue2;
7105-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7106-
}
7107-
else if (switchtype == STYPE_Doorbell)
7104+
if (switchtype == STYPE_Doorbell)
71087105
{
71097106
root["result"][ii]["TypeImg"] = "doorbell";
71107107
root["result"][ii]["Status"] = "";//"Pressed";
@@ -7121,20 +7118,12 @@ namespace http {
71217118
lstatus = "Closed";
71227119
}
71237120
root["result"][ii]["Status"] = lstatus;
7124-
root["result"][ii]["AddjValue"] = AddjValue;
7125-
root["result"][ii]["AddjMulti"] = AddjMulti;
7126-
root["result"][ii]["AddjValue2"] = AddjValue2;
7127-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
71287121
}
71297122
else if (switchtype == STYPE_PushOn)
71307123
{
71317124
root["result"][ii]["TypeImg"] = "push";
71327125
root["result"][ii]["Status"] = "";
71337126
root["result"][ii]["InternalState"] = (IsLightSwitchOn(lstatus) == true) ? "On" : "Off";
7134-
root["result"][ii]["AddjValue"] = AddjValue;
7135-
root["result"][ii]["AddjMulti"] = AddjMulti;
7136-
root["result"][ii]["AddjValue2"] = AddjValue2;
7137-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
71387127
}
71397128
else if (switchtype == STYPE_PushOff)
71407129
{
@@ -7148,10 +7137,6 @@ namespace http {
71487137
root["result"][ii]["TypeImg"] = "smoke";
71497138
root["result"][ii]["SwitchTypeVal"] = STYPE_SMOKEDETECTOR;
71507139
root["result"][ii]["SwitchType"] = Switch_Type_Desc(STYPE_SMOKEDETECTOR);
7151-
root["result"][ii]["AddjValue"] = AddjValue;
7152-
root["result"][ii]["AddjMulti"] = AddjMulti;
7153-
root["result"][ii]["AddjValue2"] = AddjValue2;
7154-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
71557140
}
71567141
else if (switchtype == STYPE_Contact)
71577142
{
@@ -7164,10 +7149,6 @@ namespace http {
71647149
lstatus = "Closed";
71657150
}
71667151
root["result"][ii]["Status"] = lstatus;
7167-
root["result"][ii]["AddjValue"] = AddjValue;
7168-
root["result"][ii]["AddjMulti"] = AddjMulti;
7169-
root["result"][ii]["AddjValue2"] = AddjValue2;
7170-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
71717152
}
71727153
else if (switchtype == STYPE_Media)
71737154
{
@@ -7222,18 +7203,10 @@ namespace http {
72227203
else if (switchtype == STYPE_Dimmer)
72237204
{
72247205
root["result"][ii]["TypeImg"] = "dimmer";
7225-
root["result"][ii]["AddjValue"] = AddjValue;
7226-
root["result"][ii]["AddjMulti"] = AddjMulti;
7227-
root["result"][ii]["AddjValue2"] = AddjValue2;
7228-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
72297206
}
72307207
else if (switchtype == STYPE_Motion)
72317208
{
72327209
root["result"][ii]["TypeImg"] = "motion";
7233-
root["result"][ii]["AddjValue"] = AddjValue;
7234-
root["result"][ii]["AddjMulti"] = AddjMulti;
7235-
root["result"][ii]["AddjValue2"] = AddjValue2;
7236-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
72377210
}
72387211
if (llevel != 0)
72397212
sprintf(szData, "%s, Level: %d %%", lstatus.c_str(), llevel);
@@ -7267,19 +7240,7 @@ namespace http {
72677240
root["result"][ii]["SwitchTypeVal"] = STYPE_SMOKEDETECTOR;
72687241
root["result"][ii]["TypeImg"] = "smoke";
72697242
root["result"][ii]["SwitchType"] = Switch_Type_Desc(STYPE_SMOKEDETECTOR);
7270-
root["result"][ii]["AddjValue"] = AddjValue;
7271-
root["result"][ii]["AddjMulti"] = AddjMulti;
7272-
root["result"][ii]["AddjValue2"] = AddjValue2;
7273-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7274-
}
7275-
if (switchtype == STYPE_Motion)
7276-
{
7277-
root["result"][ii]["AddjValue"] = AddjValue;
7278-
root["result"][ii]["AddjMulti"] = AddjMulti;
7279-
root["result"][ii]["AddjValue2"] = AddjValue2;
7280-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
72817243
}
7282-
72837244
sprintf(szData, "%s", lstatus.c_str());
72847245
root["result"][ii]["Data"] = szData;
72857246
root["result"][ii]["HaveTimeout"] = false;
@@ -7355,11 +7316,6 @@ namespace http {
73557316
if (strarray.size()>=3)
73567317
{
73577318
int i=0;
7358-
root["result"][ii]["AddjValue"]=AddjValue;
7359-
root["result"][ii]["AddjMulti"]=AddjMulti;
7360-
root["result"][ii]["AddjValue2"]=AddjValue2;
7361-
root["result"][ii]["AddjMulti2"]=AddjMulti2;
7362-
73637319
double tempCelcius=atof(strarray[i++].c_str());
73647320
double temp=ConvertTemperature(tempCelcius,tempsign);
73657321
double tempSetPoint;
@@ -7398,8 +7354,6 @@ namespace http {
73987354
}
73997355
else if ((dType == pTypeTEMP) || (dType == pTypeRego6XXTemp))
74007356
{
7401-
root["result"][ii]["AddjValue"] = AddjValue;
7402-
root["result"][ii]["AddjMulti"] = AddjMulti;
74037357
double tvalue = ConvertTemperature(atof(sValue.c_str()), tempsign);
74047358
root["result"][ii]["Temp"] = tvalue;
74057359
sprintf(szData, "%.1f %c", tvalue, tempsign);
@@ -7421,10 +7375,6 @@ namespace http {
74217375
}
74227376
else if ((dType == pTypeRFXSensor) && (dSubType == sTypeRFXSensorTemp))
74237377
{
7424-
root["result"][ii]["AddjValue"] = AddjValue;
7425-
root["result"][ii]["AddjMulti"] = AddjMulti;
7426-
root["result"][ii]["AddjValue2"] = AddjValue2;
7427-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
74287378
double tvalue = ConvertTemperature(atof(sValue.c_str()), tempsign);
74297379
root["result"][ii]["Temp"] = tvalue;
74307380
sprintf(szData, "%.1f %c", tvalue, tempsign);
@@ -7446,11 +7396,6 @@ namespace http {
74467396
StringSplit(sValue, ";", strarray);
74477397
if (strarray.size() == 3)
74487398
{
7449-
root["result"][ii]["AddjValue"] = AddjValue;
7450-
root["result"][ii]["AddjMulti"] = AddjMulti;
7451-
root["result"][ii]["AddjValue2"] = AddjValue2;
7452-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7453-
74547399
double tempCelcius = atof(strarray[0].c_str());
74557400
double temp = ConvertTemperature(tempCelcius, tempsign);
74567401
int humidity = atoi(strarray[1].c_str());
@@ -7474,11 +7419,6 @@ namespace http {
74747419
StringSplit(sValue, ";", strarray);
74757420
if (strarray.size() == 5)
74767421
{
7477-
root["result"][ii]["AddjValue"] = AddjValue;
7478-
root["result"][ii]["AddjMulti"] = AddjMulti;
7479-
root["result"][ii]["AddjValue2"] = AddjValue2;
7480-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7481-
74827422
double tempCelcius = atof(strarray[0].c_str());
74837423
double temp = ConvertTemperature(tempCelcius, tempsign);
74847424
int humidity = atoi(strarray[1].c_str());
@@ -7529,11 +7469,6 @@ namespace http {
75297469
StringSplit(sValue, ";", strarray);
75307470
if (strarray.size() >= 3)
75317471
{
7532-
root["result"][ii]["AddjValue"] = AddjValue;
7533-
root["result"][ii]["AddjMulti"] = AddjMulti;
7534-
root["result"][ii]["AddjValue2"] = AddjValue2;
7535-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7536-
75377472
double tvalue = ConvertTemperature(atof(strarray[0].c_str()), tempsign);
75387473
root["result"][ii]["Temp"] = tvalue;
75397474
int forecast = atoi(strarray[2].c_str());
@@ -7560,11 +7495,6 @@ namespace http {
75607495
root["result"][ii]["UVI"] = strarray[0];
75617496
if (dSubType == sTypeUV3)
75627497
{
7563-
root["result"][ii]["AddjValue"] = AddjValue;
7564-
root["result"][ii]["AddjMulti"] = AddjMulti;
7565-
root["result"][ii]["AddjValue2"] = AddjValue2;
7566-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7567-
75687498
double tvalue = ConvertTemperature(atof(strarray[1].c_str()), tempsign);
75697499

75707500
root["result"][ii]["Temp"] = tvalue;
@@ -7602,10 +7532,6 @@ namespace http {
76027532
}
76037533
if ((dSubType == sTypeWIND4) || (dSubType == sTypeWINDNoTemp))
76047534
{
7605-
root["result"][ii]["AddjValue"] = AddjValue;
7606-
root["result"][ii]["AddjMulti"] = AddjMulti;
7607-
root["result"][ii]["AddjValue2"] = AddjValue2;
7608-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
76097535
if (dSubType == sTypeWIND4)
76107536
{
76117537
double tvalue = ConvertTemperature(atof(strarray[4].c_str()), tempsign);
@@ -7657,11 +7583,6 @@ namespace http {
76577583
}
76587584
if (result2.size() > 0)
76597585
{
7660-
root["result"][ii]["AddjValue"] = AddjValue;
7661-
root["result"][ii]["AddjMulti"] = AddjMulti;
7662-
root["result"][ii]["AddjValue2"] = AddjValue2;
7663-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
7664-
76657586
double total_real = 0;
76667587
float rate = 0;
76677588
std::vector<std::string> sd2 = result2[0];
@@ -8465,8 +8386,6 @@ namespace http {
84658386
}
84668387
else if (dSubType == sTypeSystemTemp)
84678388
{
8468-
root["result"][ii]["AddjValue"] = AddjValue;
8469-
root["result"][ii]["AddjMulti"] = AddjMulti;
84708389
double tvalue = ConvertTemperature(atof(sValue.c_str()), tempsign);
84718390
root["result"][ii]["Temp"] = tvalue;
84728391
sprintf(szData, "%.1f %c", tvalue, tempsign);
@@ -8541,11 +8460,6 @@ namespace http {
85418460
}
85428461
else if (dSubType == sTypeBaro)
85438462
{
8544-
root["result"][ii]["AddjValue"] = AddjValue;
8545-
root["result"][ii]["AddjMulti"] = AddjMulti;
8546-
root["result"][ii]["AddjValue2"] = AddjValue2;
8547-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
8548-
85498463
sprintf(szData, "%.1f hPa", atof(sValue.c_str()));
85508464
root["result"][ii]["Data"] = szData;
85518465
root["result"][ii]["TypeImg"] = "gauge";
@@ -8739,10 +8653,6 @@ namespace http {
87398653

87408654
root["result"][ii]["Level"] = 0;
87418655
root["result"][ii]["LevelInt"] = atoi(sValue.c_str());
8742-
root["result"][ii]["AddjValue"] = AddjValue;
8743-
root["result"][ii]["AddjMulti"] = AddjMulti;
8744-
root["result"][ii]["AddjValue2"] = AddjValue2;
8745-
root["result"][ii]["AddjMulti2"] = AddjMulti2;
87468656
}
87478657
break;
87488658
case sTypeRego6XXCounter:

main/mainworker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extern std::string szAppVersion;
113113

114114
extern http::server::CWebServerHelper m_webservers;
115115

116+
116117
namespace tcp {
117118
namespace server {
118119
class CTCPClient;

www/html5.appcache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ images/pushoff.png
248248
images/pushoff48.png
249249
images/pushon.png
250250
images/pushon48.png
251+
images/PV48.png
251252
images/radiation.png
252253
images/radiation48.png
253254
images/rain.png

www/images/PV48.png

2.97 KB
Loading

0 commit comments

Comments
 (0)