Skip to content

Commit 7bc84e7

Browse files
authored
Merge branch 'development' into jswebsockets
2 parents a16cb97 + 08c4722 commit 7bc84e7

24 files changed

+1678
-1564
lines changed

History.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Version 4.xxxxx (xxx 2019)
22
- Implemented: DarkSky CloudCover sensor
33
- Implemented: EventSystem, option in Settings to enable/disable URL call logging containing full URL path
4+
- Implemented: Floorplan, add support for SVG
45
- Implemented: GUI, OpenZWave added Refresh Node Information button, styling
56
- Implemented: RTL433, added Power (Watt) type
67
- Implemented: RTL433, added rainfall_mm type
78
- Implemented: OZW, JSON call to retrieve current battery levels for all nodes
89
- Implemented: BuienRadar
10+
- Implemented: Sun/Rain icons
911
- Fixed: Gui, Choosing Icon for ARC type switches
1012
- Fixed: GUI, Dashboard icon incremental counter (energy generated) not correct (#3231)
1113
- Fixed: GUI, device table initial order column

hardware/Buienradar.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
#include <sstream>
1414
#include <iomanip>
1515

16-
#define round(a) ( int ) ( a + .5 )
17-
1816
#define BUIENRADAR_URL "https://data.buienradar.nl/2.0/feed/json"
1917
#define BUIENRADAR_ACTUAL_URL "https://observations.buienradar.nl/1.0/actual/weatherstation/" //station_id
2018
#define BUIENRADAR_GRAFIEK_URL "https://www.buienradar.nl/nederland/weerbericht/weergrafieken/" //station_id
2119
//#define BUIENRARA_GRAFIEK_HISTORY_URL "https://graphdata.buienradar.nl/1.0/actualarchive/weatherstation/6370?startDate=2019-09-15"
2220

2321
#define BUIENRADAR_RAIN "https://gadgets.buienradar.nl/data/raintext/?lat=" // + m_szMyLatitude + "&lon=" + m_szMyLongitude;
24-
#define RAIN_ALARM_DURATION 15
25-
#define RAIN_SWITCH_THRESHOLD 70
26-
2722

2823
#ifdef _DEBUG
2924
// #define DEBUG_BUIENRADARR
@@ -83,9 +78,11 @@ double distanceEarth(double lat1d, double lon1d, double lat2d, double lon2d) {
8378
return 2.0 * earthRadiusKm * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
8479
}
8580

86-
CBuienRadar::CBuienRadar(const int ID)
81+
CBuienRadar::CBuienRadar(const int ID, const int iForecast, const int iThreshold)
8782
{
8883
m_HwdID = ID;
84+
m_iForecast = (iForecast >= 5) ? iForecast : 15;
85+
m_iThreshold = (iThreshold > 0) ? iThreshold : 25;
8986
Init();
9087
}
9188

@@ -378,13 +375,13 @@ void CBuienRadar::GetMeterDetails()
378375

379376
if (!root["groundtemperature"].empty())
380377
{
381-
float temp = root["groundtemperature"].asFloat();
382-
SendTempSensor(2, 255, temp, "Ground Temperature (10 cm)");
378+
float tempGround = root["groundtemperature"].asFloat();
379+
SendTempSensor(2, 255, tempGround, "Ground Temperature (10 cm)");
383380
}
384381
if (!root["feeltemperature"].empty())
385382
{
386-
float temp = root["feeltemperature"].asFloat();
387-
SendTempSensor(3, 255, temp, "Feel Temperature");
383+
float tempFeel = root["feeltemperature"].asFloat();
384+
SendTempSensor(3, 255, tempFeel, "Feel Temperature");
388385
}
389386

390387

@@ -469,7 +466,7 @@ void CBuienRadar::GetRainPrediction()
469466
#ifdef DEBUG_BUIENRADARR
470467
startTime = (13 * 60) + 30;
471468
#endif
472-
int endTime = startTime + RAIN_ALARM_DURATION;
469+
int endTime = startTime + m_iForecast;
473470
int endTimeHour = startTime + 60;
474471

475472
std::istringstream iStream(sResult);
@@ -523,7 +520,7 @@ void CBuienRadar::GetRainPrediction()
523520
//double rain_mm_hour = pow(10, ((rain_avg - 109) / 32));
524521
double rain_perc = (rain_avg == 0) ? 0 : (rain_avg * 0.392156862745098);
525522
SendPercentageSensor(1, 1, 255, static_cast<float>(rain_perc), "Rain Intensity");
526-
SendSwitch(1, 1, 255, (rain_avg >= RAIN_SWITCH_THRESHOLD), 255, "Is it Raining");
523+
SendSwitch(1, 1, 255, (rain_perc >= m_iThreshold), 0, "Is it Raining");
527524
}
528525
if (total_rain_values_next_hour)
529526
{

hardware/Buienradar.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class CBuienRadar : public CDomoticzHardwareBase
66
{
77
public:
8-
CBuienRadar(const int ID);
8+
CBuienRadar(const int ID, const int iForecast, const int iThreshold);
99
~CBuienRadar(void);
1010
bool WriteToHardware(const char *pdata, const unsigned char length) override;
1111
std::string GetForecastURL();
@@ -22,5 +22,7 @@ class CBuienRadar : public CDomoticzHardwareBase
2222
std::string m_szMyLatitude;
2323
std::string m_szMyLongitude;
2424
std::shared_ptr<std::thread> m_thread;
25+
int m_iForecast = 15;
26+
int m_iThreshold = 25;
2527
};
2628

hardware/OpenWebNetTCP.cpp

Lines changed: 67 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,28 @@ void COpenWebNetTCP::UpdateCenPlus(const int who, const int where, const int Com
835835
SendSwitch(NodeID, iInterface, BatteryLevel, (bool)Command, 0, devname);
836836
}
837837

838+
/**
839+
Insert/Update sound diffusion device
840+
**/
841+
void COpenWebNetTCP::UpdateSoundDiffusion(const int who, const int where, const int what, const int iInterface, const int BatteryLevel, const char* devname)
842+
{
843+
//NOTE: interface id (bus identifier) go in 'Unit' field
844+
//make device ID
845+
int NodeID = (((int)who << 16) & 0xFFFF0000) | (((int)where) & 0x0000FFFF);
846+
847+
/* insert switch type */
848+
char szIdx[10];
849+
sprintf(szIdx, "%07X", NodeID);
850+
std::vector<std::vector<std::string> > result;
851+
result = m_sql.safe_query("SELECT ID,SwitchType FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s') AND (Unit==%d)", m_HwdID, szIdx, iInterface);
852+
if (result.empty())
853+
{
854+
//m_sql.InsertDevice(m_HwdID, szIdx, iInterface, pTypeLighting2, sTypeAC, STYPE_Media, 0, "Unavailable", "OpenWebNet Media", 12, 255, 1);
855+
}
856+
857+
//TODO: manage SoundDiffusion device like dimmer (on, off and set volume) or like media device (check how to do it)
858+
}
859+
838860
/**
839861
Insert/Update switch device
840862
**/
@@ -1267,6 +1289,15 @@ void COpenWebNetTCP::UpdateDeviceValue(std::vector<bt_openwebnet>::iterator iter
12671289
break;
12681290
}
12691291
break;
1292+
1293+
case WHO_SOUND_DIFFUSION: // 22
1294+
//iAppValue = atoi(what.c_str());
1295+
//iWhere = atoi(where.c_str());
1296+
//devname = OPENWEBNET_SOUND_DIFFUSION;
1297+
//devname += " " + where;
1298+
//UpdateSoundDiffusion(WHO_SOUND_DIFFUSION, iWhere, iAppValue, atoi(sInterface.c_str()), 255, devname.c_str());
1299+
//break;
1300+
12701301
case WHO_SCENARIO: // 0
12711302
case WHO_LOAD_CONTROL: // 3
12721303
case WHO_DOOR_ENTRY_SYSTEM: // 6
@@ -1276,7 +1307,6 @@ void COpenWebNetTCP::UpdateDeviceValue(std::vector<bt_openwebnet>::iterator iter
12761307
case WHO_SCENARIO_SCHEDULER_SWITCH: // 15
12771308
case WHO_AUDIO: // 16
12781309
case WHO_SCENARIO_PROGRAMMING: // 17
1279-
case WHO_SOUND_DIFFUSION: // 22
12801310
case WHO_LIHGTING_MANAGEMENT: // 24
12811311
case WHO_ZIGBEE_DIAGNOSTIC: // 1000
12821312
case WHO_AUTOMATIC_DIAGNOSTIC: // 1001
@@ -1327,7 +1357,6 @@ bool COpenWebNetTCP::WriteToHardware(const char *pdata, const unsigned char leng
13271357
case WHO_AUTOMATION:
13281358
//Blinds/Window command
13291359
sprintf(szIdx, "%07X", ((who << 16) & 0xffff0000) | (where & 0x0000ffff));
1330-
13311360
result = m_sql.safe_query("SELECT nValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s') AND (SwitchType==%d)", //*******is there a better method for get
13321361
m_HwdID, szIdx, STYPE_BlindsPercentageInverted); //*******SUBtype (STYPE_BlindsPercentageInverted) ??
13331362

@@ -1401,16 +1430,27 @@ bool COpenWebNetTCP::WriteToHardware(const char *pdata, const unsigned char leng
14011430
what = AUXILIARY_WHAT_ON;
14021431
}
14031432
break;
1433+
1434+
case 0xF00: // Custom command, fake who..
1435+
sprintf(szIdx, "%07X", ((who << 16) & 0xffff0000) | (where & 0x0000ffff));
1436+
result = m_sql.safe_query("SELECT StrParam1 FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%s')", m_HwdID, szIdx);
1437+
if (!result.empty())
1438+
{
1439+
// Custom command fount, send it!
1440+
_log.Log(LOG_STATUS, "COpenWebNetTCP: send custom command: '%s'", result[0][0].c_str());
1441+
std::vector<bt_openwebnet> responses;
1442+
bt_openwebnet request(result[0][0]);
1443+
if (sendCommand(request, responses))
1444+
{
1445+
//if (responses.size() > 0) return responses.at(0).IsOKFrame();
1446+
return true; // if send ok, return always ok without check the response..
1447+
}
1448+
}
1449+
_log.Log(LOG_ERROR, "COpenWebNetTCP: custom command error: '%s'", result[0][0].c_str());
1450+
return false; // error
14041451
default:
14051452
break;
14061453
}
1407-
1408-
//int used = 1;
1409-
if (!FindDevice(who, where, iInterface, NULL)) {
1410-
_log.Log(LOG_ERROR, "COpenWebNetTCP: command received for unknown device : %d/%d", who, where);
1411-
return false;
1412-
}
1413-
14141454
break;
14151455
default:
14161456
_log.Log(LOG_STATUS, "COpenWebNetTCP unknown command: packettype=%d subtype=%d", packettype, subtype);
@@ -1611,6 +1651,21 @@ void COpenWebNetTCP::scan_automation_lighting(const int cen_area)
16111651
sendCommand(request, responses, 0, false);
16121652
}
16131653

1654+
/**
1655+
automatic scan of sound diffusion device
1656+
**/
1657+
void COpenWebNetTCP::scan_sound_diffusion()
1658+
{
1659+
bt_openwebnet request;
1660+
std::vector<bt_openwebnet> responses;
1661+
std::stringstream whoStr;
1662+
std::stringstream whereStr;
1663+
whoStr << WHO_SOUND_DIFFUSION;
1664+
whereStr << 0;
1665+
request.CreateStateMsgOpen(whoStr.str(), whereStr.str());
1666+
sendCommand(request, responses, 0, false);
1667+
}
1668+
16141669
/**
16151670
automatic scan of temperature control device
16161671
**/
@@ -1761,6 +1816,9 @@ void COpenWebNetTCP::scan_device()
17611816
//_log.Log(LOG_STATUS, "COpenWebNetTCP: scanning temperature control...");
17621817
//scan_temperature_control();
17631818

1819+
// Scan of sound diffusion device
1820+
//scan_sound_diffusion();
1821+
17641822
_log.Log(LOG_STATUS, "COpenWebNetTCP: scan device complete, wait all the update data..");
17651823

17661824
/* Update complete scan time*/
@@ -1831,72 +1889,3 @@ void COpenWebNetTCP::Do_Work()
18311889
}
18321890
_log.Log(LOG_STATUS, "COpenWebNetTCP: Heartbeat worker stopped...");
18331891
}
1834-
1835-
/**
1836-
Find OpenWebNetDevice in DB
1837-
**/
1838-
bool COpenWebNetTCP::FindDevice(const int who, const int where, const int iInterface, int* used)
1839-
{
1840-
std::vector<std::vector<std::string> > result;
1841-
int devType = -1;
1842-
1843-
//make device ID
1844-
int NodeID = (((int)who << 16) & 0xFFFF0000) | (((int)where) & 0x0000FFFF);
1845-
1846-
switch (who) {
1847-
case WHO_LIGHTING: // 1
1848-
case WHO_AUTOMATION: // 2
1849-
case WHO_AUXILIARY: // 9
1850-
case WHO_CEN_PLUS_DRY_CONTACT_IR_DETECTION: // 25
1851-
//devType = pTypeGeneralSwitch;
1852-
devType = pTypeLighting2;
1853-
break;
1854-
case WHO_TEMPERATURE_CONTROL: // 4
1855-
return true; // device always present
1856-
case WHO_SCENARIO: // 0
1857-
case WHO_LOAD_CONTROL: // 3
1858-
case WHO_BURGLAR_ALARM: // 5
1859-
case WHO_DOOR_ENTRY_SYSTEM: // 6
1860-
case WHO_MULTIMEDIA: // 7
1861-
case WHO_GATEWAY_INTERFACES_MANAGEMENT: // 13
1862-
case WHO_LIGHT_SHUTTER_ACTUATOR_LOCK: // 14
1863-
case WHO_SCENARIO_SCHEDULER_SWITCH: // 15
1864-
case WHO_AUDIO: // 16
1865-
case WHO_SCENARIO_PROGRAMMING: // 17
1866-
case WHO_ENERGY_MANAGEMENT: // 18
1867-
case WHO_LIHGTING_MANAGEMENT: // 24
1868-
case WHO_ZIGBEE_DIAGNOSTIC: // 1000
1869-
case WHO_AUTOMATIC_DIAGNOSTIC: // 1001
1870-
case WHO_THERMOREGULATION_DIAGNOSTIC_FAILURES: // 1004
1871-
case WHO_DEVICE_DIAGNOSTIC: // 1013
1872-
default:
1873-
return false;
1874-
}
1875-
1876-
if (devType >= 0)
1877-
{
1878-
char szIdx[10];
1879-
sprintf(szIdx, "%07X", NodeID);
1880-
1881-
if (used != NULL)
1882-
{
1883-
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d) AND Used == %d",
1884-
m_HwdID, szIdx, iInterface, devType, *used);
1885-
}
1886-
else
1887-
{
1888-
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d)",
1889-
m_HwdID, szIdx, iInterface, devType);
1890-
}
1891-
}
1892-
else
1893-
return false;
1894-
1895-
1896-
if (!result.empty())
1897-
{
1898-
return true;
1899-
}
1900-
1901-
return false;
1902-
}

hardware/OpenWebNetTCP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class COpenWebNetTCP : public CDomoticzHardwareBase
6666
int ownRead(csocket* connectionSocket, char* pdata, size_t size);
6767
bool sendCommand(bt_openwebnet& command, std::vector<bt_openwebnet>& response, int waitForResponse = 0, bool silent = false);
6868
bool ParseData(char* data, int length, std::vector<bt_openwebnet>& messages);
69-
bool FindDevice(const int who, const int where, const int iInterface, int *used);
7069
void UpdateSwitch(const int who, const int where, const int Level, const int iInterface, const int BatteryLevel, const char *devname);
7170
void UpdateBlinds(const int who, const int where, const int Command, const int iInterface, const int iLevel, const int BatteryLevel, const char *devname);
7271
void UpdateAlarm(const int who, const int where, const int Command, const char *sCommand, const int iInterface, const int BatteryLevel, const char *devname);
@@ -75,9 +74,11 @@ class COpenWebNetTCP : public CDomoticzHardwareBase
7574
void UpdateSetPoint(const int who, const int where, float fval, const int iInterface, const char *devname);
7675
void UpdatePower(const int who, const int where, double fval, const int iInterface, const int BatteryLevel, const char *devname);
7776
void UpdateEnergy(const int who, const int where, double fval, const int iInterface, const int BatteryLevel, const char *devname);
77+
void UpdateSoundDiffusion(const int who, const int where, const int what, const int iInterface, const int BatteryLevel, const char* devname);
7878
bool GetValueMeter(const int NodeID, const int ChildID, double *usage, double *energy);
7979
void UpdateDeviceValue(std::vector<bt_openwebnet>::iterator iter);
8080
void scan_automation_lighting(const int cen_area);
81+
void scan_sound_diffusion();
8182
void scan_temperature_control();
8283
void scan_device();
8384
void requestTime();

hardware/OpenZWave.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,9 +4965,25 @@ void COpenZWave::UpdateDeviceBatteryStatus(const int nodeID, const int value)
49654965
bool COpenZWave::GetBatteryLevels(Json::Value& root)
49664966
{
49674967
int ii = 0;
4968+
4969+
std::vector<std::vector<std::string> > result;
4970+
result = m_sql.safe_query("SELECT NodeID,Name FROM ZWaveNodes WHERE (HardwareID==%d)", m_HwdID);
4971+
4972+
std::map<uint16_t, std::string> _NodeNames;
4973+
for (const auto itt : result)
4974+
{
4975+
uint16_t nodeID = (uint16_t)atoi(itt[0].c_str());
4976+
_NodeNames[nodeID] = itt[1];
4977+
}
4978+
4979+
49684980
for (std::list<NodeInfo>::iterator it = m_nodes.begin(); it != m_nodes.end(); ++it)
49694981
{
49704982
root["result"][ii]["nodeID"] = it->nodeId;
4983+
std::string nodeName;
4984+
if (_NodeNames.find(it->nodeId) != _NodeNames.end())
4985+
nodeName = _NodeNames[it->nodeId];
4986+
root["result"][ii]["nodeName"] = nodeName;
49714987
root["result"][ii]["battery"] = it->batValue;
49724988
ii++;
49734989
}

0 commit comments

Comments
 (0)