Skip to content

Commit

Permalink
Linux: add ThermHygroMeterParsed for temperature+humidity channel. See
Browse files Browse the repository at this point in the history
README.md file for example usage
  • Loading branch information
klew committed Dec 12, 2022
1 parent 01cc9cc commit 039ef14
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
28 changes: 28 additions & 0 deletions extras/examples/linux/README.md
Expand Up @@ -224,6 +224,7 @@ Supported channel types:
* `VirtualRelay` - related class `Supla::Control::VirtualRelay`
* `Fronius` - related class `Supla::PV::Fronius`
* `ThermometerParsed` - related class `Supla::Sensor::ThermometerParsed`
* `ThermHygroMeterParsed` - related class `Supla::Sensor::ThermHygroMeterParsed`
* `ImpulseCounterParsed` - related class `Supla::Sensor::ImpulseCounterParsed`
* `ElectricityMeterParsed` - related class `Supla::Sensor::ElectricityMeterParsed`
* `BinaryParsed` - related class `Supla::Sensor::BinaryParsed`
Expand Down Expand Up @@ -315,6 +316,22 @@ Example channels configuration (details are exaplained later):
parser:
use: parser_1

- type: ThermHygroMeterParsed
name: th1
source:
type: File
# use file "temp_humi.txt" from current folder
file: "temp_humi.txt"
parser:
type: Simple
refresh_time_ms: 200
# temperature is read from first line of txt file
temperature: 0
# humidity is read from second line of txt file
humidity: 1
multiplier_temp: 1
multiplier_humi: 1

There are some new classes (compared to standard non-Linux supla-device) which
names end with "Parsed" word. In general, those channels use `parser` and
`source` functions to get some data from your computer and put it to that
Expand Down Expand Up @@ -395,6 +412,17 @@ from `parser`.
Optional parameter: `multiplier` - defines multiplier for fetched value
(you can put any floating point number).

### `ThermHygroMeterParsed`

Add channel with "thermometer + hygrometer" type.

Mandatory parameters: `temperature` - defines key/index by which data is fetched
from `parser` for temperature value, `humidity` - defines key/index by which
data is fetched from `parser` for humidity value;
Optional parameter: `multiplier_temp` - defines multiplier for temperatur value
(you can put any floating point number), `multiplier_humi` - defines multiplier
for humidity value.

### `ImpulseCounterParsed`

Add channel with "impulse counter" type. You can define in Supla Cloud what
Expand Down
1 change: 1 addition & 0 deletions extras/porting/linux/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ set(SUPLA_DEVICE_LINUX_SRCS
supla/sensor/pressure_parsed.cpp
supla/sensor/rain_parsed.cpp
supla/sensor/wind_parsed.cpp
supla/sensor/therm_hygro_meter_parsed.cpp

../../../src/supla/pv/fronius.cpp
../../../src/supla/pv/afore.cpp
Expand Down
68 changes: 68 additions & 0 deletions extras/porting/linux/linux_yaml_config.cpp
Expand Up @@ -46,9 +46,12 @@
#include <string>

#include "linux_yaml_config.h"
#include "supla/sensor/therm_hygro_meter_parsed.h"

namespace Supla {
const char Multiplier[] = "multiplier";
const char MultiplierTemp[] = "multiplier_temp";
const char MultiplierHumi[] = "multiplier_humi";

const char GuidAuthFileName[] = "/guid_auth.yaml";
const char GuidKey[] = "guid";
Expand Down Expand Up @@ -433,6 +436,12 @@ bool Supla::LinuxYamlConfig::parseChannel(const YAML::Node& ch,
return false;
}
return addRainParsed(ch, channelNumber, parser);
} else if (type == "ThermHygroMeterParsed") {
if (!parser) {
SUPLA_LOG_ERROR("Channel[%d] config: missing parser", channelNumber);
return false;
}
return addThermHygroMeterParsed(ch, channelNumber, parser);
} else {
SUPLA_LOG_ERROR(
"Channel[%d] config: unknown type \"%s\"",
Expand Down Expand Up @@ -519,6 +528,10 @@ bool Supla::LinuxYamlConfig::addThermometerParsed(
paramCount++;
double multiplier = ch[Supla::Multiplier].as<double>();
therm->setMultiplier(Supla::Parser::Temperature, multiplier);
} else if (ch[Supla::MultiplierTemp]) {
paramCount++;
double multiplier = ch[Supla::MultiplierTemp].as<double>();
therm->setMultiplier(Supla::Parser::Temperature, multiplier);
}

return true;
Expand Down Expand Up @@ -834,6 +847,61 @@ bool Supla::LinuxYamlConfig::isConfigModeSupported() {
return false;
}

bool Supla::LinuxYamlConfig::addThermHygroMeterParsed(const YAML::Node& ch,
int channelNumber,
Supla::Parser::Parser* parser) {
SUPLA_LOG_INFO("Channel[%d] config: adding ThermHygroMeterParsed",
channelNumber);
auto thermHumi = new Supla::Sensor::ThermHygroMeterParsed(parser);
if (ch[Supla::Parser::Humidity]) {
paramCount++;
if (parser->isBasedOnIndex()) {
int index = ch[Supla::Parser::Humidity].as<int>();
thermHumi->setMapping(Supla::Parser::Humidity, index);
} else {
std::string key = ch[Supla::Parser::Humidity].as<std::string>();
thermHumi->setMapping(Supla::Parser::Humidity, key);
}
} else {
SUPLA_LOG_ERROR(
"Channel[%d] config: missing \"%s\" parameter",
channelNumber,
Supla::Parser::Humidity);
return false;
}

if (ch[Supla::MultiplierHumi]) {
paramCount++;
double multiplier = ch[Supla::MultiplierHumi].as<double>();
thermHumi->setMultiplier(Supla::Parser::Humidity, multiplier);
}

if (ch[Supla::Parser::Temperature]) {
paramCount++;
if (parser->isBasedOnIndex()) {
int index = ch[Supla::Parser::Temperature].as<int>();
thermHumi->setMapping(Supla::Parser::Temperature, index);
} else {
std::string key = ch[Supla::Parser::Temperature].as<std::string>();
thermHumi->setMapping(Supla::Parser::Temperature, key);
}
} else {
SUPLA_LOG_ERROR(
"Channel[%d] config: missing \"%s\" parameter",
channelNumber,
Supla::Parser::Temperature);
return false;
}

if (ch[Supla::MultiplierTemp]) {
paramCount++;
double multiplier = ch[Supla::MultiplierTemp].as<double>();
thermHumi->setMultiplier(Supla::Parser::Temperature, multiplier);
}

return true;
}

bool Supla::LinuxYamlConfig::addHumidityParsed(
const YAML::Node& ch, int channelNumber, Supla::Parser::Parser* parser) {
SUPLA_LOG_INFO("Channel[%d] config: adding HumidityParsed", channelNumber);
Expand Down
3 changes: 3 additions & 0 deletions extras/porting/linux/linux_yaml_config.h
Expand Up @@ -150,6 +150,9 @@ class LinuxYamlConfig : public Config {
bool addBinaryParsed(const YAML::Node& ch,
int channelNumber,
Supla::Parser::Parser* parser);
bool addThermHygroMeterParsed(const YAML::Node& ch,
int channelNumber,
Supla::Parser::Parser* parser);
bool addHumidityParsed(const YAML::Node& ch,
int channelNumber,
Supla::Parser::Parser* parser);
Expand Down
66 changes: 66 additions & 0 deletions extras/porting/linux/supla/sensor/therm_hygro_meter_parsed.cpp
@@ -0,0 +1,66 @@
/*
* Copyright (C) AC SOFTWARE SP. Z O.O
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <supla/log_wrapper.h>

#include "humidity_parsed.h"
#include "therm_hygro_meter_parsed.h"

Supla::Sensor::ThermHygroMeterParsed::ThermHygroMeterParsed(
Supla::Parser::Parser *parser)
: SensorParsed(parser) {
}

double Supla::Sensor::ThermHygroMeterParsed::getTemp() {
double value = TEMPERATURE_NOT_AVAILABLE;

if (isParameterConfigured(Supla::Parser::Temperature)) {
if (refreshParserSource()) {
value = getParameterValue(Supla::Parser::Temperature);
}
if (!parser->isValid()) {
if (!isDataErrorLogged) {
isDataErrorLogged = true;
SUPLA_LOG_WARNING("ThermHygroMeterParsed: source data error");
}
return TEMPERATURE_NOT_AVAILABLE;
}
isDataErrorLogged = false;
}
return value;
}

double Supla::Sensor::ThermHygroMeterParsed::getHumi() {
double value = HUMIDITY_NOT_AVAILABLE;

if (isParameterConfigured(Supla::Parser::Humidity)) {
if (refreshParserSource()) {
value = getParameterValue(Supla::Parser::Humidity);
}
if (!parser->isValid()) {
if (!isDataErrorLogged) {
isDataErrorLogged = true;
SUPLA_LOG_WARNING("ThermHygroMeterParsed: source data error");
}
return HUMIDITY_NOT_AVAILABLE;
}
isDataErrorLogged = false;
}
return value;
}

47 changes: 47 additions & 0 deletions extras/porting/linux/supla/sensor/therm_hygro_meter_parsed.h
@@ -0,0 +1,47 @@
/*
* Copyright (C) AC SOFTWARE SP. Z O.O
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERM_HYGRO_METER_PARSED_H_
#define EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERM_HYGRO_METER_PARSED_H_

#include <supla/parser/parser.h>
#include <supla/sensor/therm_hygro_meter.h>

#include <string>

#include "sensor_parsed.h"
#include "thermometer_parsed.h"
#include "humidity_parsed.h"

namespace Supla {
namespace Sensor {

class ThermHygroMeterParsed : public ThermHygroMeter, public SensorParsed {
public:
explicit ThermHygroMeterParsed(Supla::Parser::Parser *);
double getTemp() override;
double getHumi() override;

protected:
bool isDataErrorLogged = false;
};
}; // namespace Sensor
}; // namespace Supla


#endif // EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERM_HYGRO_METER_PARSED_H_

0 comments on commit 039ef14

Please sign in to comment.