kopia lustrzana https://github.com/weetmuts/wmbusmeters
Rename jsons to extra_constant_fields.
rodzic
e4d3ec1e7e
commit
6009382d4f
16
README.md
16
README.md
|
@ -214,7 +214,9 @@ As <options> you can use:
|
|||
--nodeviceexit if no wmbus devices are found, then exit immediately
|
||||
--oneshot wait for an update from each meter, then quit
|
||||
--resetafter=<time> reset the wmbus dongle regularly, default is 23h
|
||||
--selectfields=id,timestamp,total_m3 select fields to be printed
|
||||
--addfields=timestamp_ut add the timestamp_ut field to be printed (--listfields=<meter> to list available fields)
|
||||
--selectfields=id,timestamp,total_m3 select only these fields to be printed (--listfields=<meter> to list available fields)
|
||||
addfields and selectfields are mutually exclusive.
|
||||
--separator=<c> change field separator to c
|
||||
--shell=<cmdline> invokes cmdline with env variables containing the latest reading
|
||||
--silent do not print informational messages nor warnings
|
||||
|
@ -461,6 +463,18 @@ wmbusmeters --format=fields --selectfields=id,total_m3 /dev/ttyUSB0:im871a Green
|
|||
33333333;9999.099
|
||||
```
|
||||
|
||||
Instead of selecting a subset you can add fields, such as: timestamp_ut, timestamp_utc, timestamp_lt
|
||||
and extra constant fields added using --field_xxx=yyy.
|
||||
|
||||
```shell
|
||||
wmbusmeters --format=fields --field_city=Stockholm --addfields=timestamp_ut,city /dev/ttyUSB0:im871a GreenhouseWater multical21:c1 33333333 NOKEY
|
||||
```
|
||||
|
||||
```
|
||||
GreenhouseTapWater;33333333;9999.099;77.712;0.000;11;31;;2018-03-05 12:10.24;1627855621,Stockholm
|
||||
```
|
||||
|
||||
|
||||
You can list all available fields for a meter: `wmbusmeters --listfields=multical21`
|
||||
|
||||
You can list all meters: `wmbusmeters --listmeters`
|
||||
|
|
|
@ -277,6 +277,17 @@ shared_ptr<Configuration> parseCommandLine(int argc, char **argv) {
|
|||
i++;
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(argv[i], "--addfields=", 12)) {
|
||||
if (strlen(argv[i]) > 12)
|
||||
{
|
||||
string s = string(argv[i]+12);
|
||||
handleAddedFields(c, s);
|
||||
} else {
|
||||
error("You must supply fields to be added.\n");
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp(argv[i], "--separator=", 12)) {
|
||||
if (!c->fields) {
|
||||
|
|
|
@ -554,6 +554,11 @@ void handleLogTimestamps(Configuration *c, string ts)
|
|||
|
||||
void handleSelectedFields(Configuration *c, string s)
|
||||
{
|
||||
if (c->added_fields.size() > 0)
|
||||
{
|
||||
warning("(warning) addfields already used! Ignoring addfields %s", s);
|
||||
return;
|
||||
}
|
||||
char buf[s.length()+1];
|
||||
strcpy(buf, s.c_str());
|
||||
char *saveptr {};
|
||||
|
@ -567,6 +572,11 @@ void handleSelectedFields(Configuration *c, string s)
|
|||
|
||||
void handleAddedFields(Configuration *c, string s)
|
||||
{
|
||||
if (c->selected_fields.size() > 0)
|
||||
{
|
||||
warning("(warning) selectfields already used! Ignoring selectfields %s", s);
|
||||
return;
|
||||
}
|
||||
char buf[s.length()+1];
|
||||
strcpy(buf, s.c_str());
|
||||
char *saveptr {};
|
||||
|
|
|
@ -276,8 +276,8 @@ MeterCommonImplementation::MeterCommonImplementation(MeterInfo &mi,
|
|||
for (auto s : mi.shells) {
|
||||
addShell(s);
|
||||
}
|
||||
for (auto j : mi.jsons) {
|
||||
addJson(j);
|
||||
for (auto j : mi.extra_constant_fields) {
|
||||
addExtraConstantField(j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,9 +294,9 @@ void MeterCommonImplementation::addShell(string cmdline)
|
|||
shell_cmdlines_.push_back(cmdline);
|
||||
}
|
||||
|
||||
void MeterCommonImplementation::addJson(string json)
|
||||
void MeterCommonImplementation::addExtraConstantField(string ecf)
|
||||
{
|
||||
jsons_.push_back(json);
|
||||
extra_constant_fields_.push_back(ecf);
|
||||
}
|
||||
|
||||
vector<string> &MeterCommonImplementation::shellCmdlines()
|
||||
|
@ -304,9 +304,9 @@ vector<string> &MeterCommonImplementation::shellCmdlines()
|
|||
return shell_cmdlines_;
|
||||
}
|
||||
|
||||
vector<string> &MeterCommonImplementation::additionalJsons()
|
||||
vector<string> &MeterCommonImplementation::meterExtraConstantFields()
|
||||
{
|
||||
return jsons_;
|
||||
return extra_constant_fields_;
|
||||
}
|
||||
|
||||
MeterDriver MeterCommonImplementation::driver()
|
||||
|
@ -584,7 +584,7 @@ void MeterCommonImplementation::triggerUpdate(Telegram *t)
|
|||
t->handled = true;
|
||||
}
|
||||
|
||||
string concatAllFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vector<Unit> &cs, bool hr)
|
||||
string concatAllFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vector<Unit> &cs, bool hr, vector<string> *added_fields)
|
||||
{
|
||||
string s;
|
||||
s = "";
|
||||
|
@ -624,11 +624,11 @@ string concatAllFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vec
|
|||
}
|
||||
|
||||
string concatFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vector<Unit> &cs, bool hr,
|
||||
vector<string> *selected_fields)
|
||||
vector<string> *selected_fields, vector<string> *added_fields)
|
||||
{
|
||||
if (selected_fields == NULL || selected_fields->size() == 0)
|
||||
{
|
||||
return concatAllFields(m, t, c, prints, cs, hr);
|
||||
return concatAllFields(m, t, c, prints, cs, hr, added_fields);
|
||||
}
|
||||
string s;
|
||||
s = "";
|
||||
|
@ -776,12 +776,12 @@ void MeterCommonImplementation::printMeter(Telegram *t,
|
|||
string *fields, char separator,
|
||||
string *json,
|
||||
vector<string> *envs,
|
||||
vector<string> *more_json,
|
||||
vector<string> *extra_constant_fields,
|
||||
vector<string> *selected_fields,
|
||||
vector<string> *added_fields)
|
||||
{
|
||||
*human_readable = concatFields(this, t, '\t', prints_, conversions_, true, selected_fields);
|
||||
*fields = concatFields(this, t, separator, prints_, conversions_, false, selected_fields);
|
||||
*human_readable = concatFields(this, t, '\t', prints_, conversions_, true, selected_fields, added_fields);
|
||||
*fields = concatFields(this, t, separator, prints_, conversions_, false, selected_fields, added_fields);
|
||||
|
||||
string media;
|
||||
if (t->tpl_id_found)
|
||||
|
@ -838,15 +838,15 @@ void MeterCommonImplementation::printMeter(Telegram *t,
|
|||
s += "\"device\":\""+t->about.device+"\",";
|
||||
s += "\"rssi_dbm\":"+to_string(t->about.rssi_dbm);
|
||||
}
|
||||
for (string add_json : additionalJsons())
|
||||
for (string extra_field : meterExtraConstantFields())
|
||||
{
|
||||
s += ",";
|
||||
s += makeQuotedJson(add_json);
|
||||
s += makeQuotedJson(extra_field);
|
||||
}
|
||||
for (string add_json : *more_json)
|
||||
for (string extra_field : *extra_constant_fields)
|
||||
{
|
||||
s += ",";
|
||||
s += makeQuotedJson(add_json);
|
||||
s += makeQuotedJson(extra_field);
|
||||
}
|
||||
s += "}";
|
||||
*json = s;
|
||||
|
@ -901,13 +901,13 @@ void MeterCommonImplementation::printMeter(Telegram *t,
|
|||
|
||||
// If the configuration has supplied json_address=Roodroad 123
|
||||
// then the env variable METER_address will available and have the content "Roodroad 123"
|
||||
for (string add_json : additionalJsons())
|
||||
for (string add_json : meterExtraConstantFields())
|
||||
{
|
||||
envs->push_back(string("METER_")+add_json);
|
||||
}
|
||||
for (string add_json : *more_json)
|
||||
for (string extra_field : *extra_constant_fields)
|
||||
{
|
||||
envs->push_back(string("METER_")+add_json);
|
||||
envs->push_back(string("METER_")+extra_field);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ struct MeterInfo
|
|||
LinkModeSet link_modes;
|
||||
int bps {}; // For mbus communication you need to know the baud rate.
|
||||
vector<string> shells;
|
||||
vector<string> jsons; // Additional static jsons that are added to each message.
|
||||
vector<string> extra_constant_fields; // Additional static fields that are added to each message.
|
||||
vector<Unit> conversions; // Additional units desired in json.
|
||||
|
||||
// If this is a meter that needs to be polled.
|
||||
|
@ -161,7 +161,7 @@ struct MeterInfo
|
|||
idsc = toIdsCommaSeparated(ids);
|
||||
key = k;
|
||||
shells = s;
|
||||
jsons = j;
|
||||
extra_constant_fields = j;
|
||||
link_modes = lms;
|
||||
bps = baud;
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ struct MeterInfo
|
|||
idsc = "";
|
||||
key = "";
|
||||
shells.clear();
|
||||
jsons.clear();
|
||||
extra_constant_fields.clear();
|
||||
link_modes.clear();
|
||||
bps = 0;
|
||||
}
|
||||
|
|
|
@ -66,9 +66,9 @@ protected:
|
|||
void setExpectedTPLSecurityMode(TPLSecurityMode tsm);
|
||||
void addConversions(std::vector<Unit> cs);
|
||||
void addShell(std::string cmdline);
|
||||
void addJson(std::string json);
|
||||
void addExtraConstantField(std::string ecf);
|
||||
std::vector<std::string> &shellCmdlines();
|
||||
std::vector<std::string> &additionalJsons();
|
||||
std::vector<std::string> &meterExtraConstantFields();
|
||||
void addLinkMode(LinkMode lm);
|
||||
// Print with the default unit for this quantity.
|
||||
void addPrint(string vname, Quantity vquantity,
|
||||
|
@ -110,7 +110,7 @@ private:
|
|||
time_t datetime_of_update_ {};
|
||||
LinkModeSet link_modes_ {};
|
||||
vector<string> shell_cmdlines_;
|
||||
vector<string> jsons_;
|
||||
vector<string> extra_constant_fields_;
|
||||
|
||||
protected:
|
||||
std::map<std::string,std::pair<int,std::string>> values_;
|
||||
|
|
|
@ -43,7 +43,7 @@ mqtt_publish) sent to a REST API (eg curl) or store it in a database
|
|||
|
||||
\fB\--ignoreduplicates\fR=<bool> ignore duplicate telegrams, remember the last 10 telegrams. Default is true.
|
||||
|
||||
\fB\--json_xxx=yyy\fR always add "xxx"="yyy" to the json output and add shell env METER_xxx=yyy
|
||||
\fB\--field_xxx=yyy\fR always add "xxx"="yyy" to the json output and add shell env METER_xxx=yyy The field xxx can also be selected or added using selectfields= and addfields=. Equivalent command is --json_xxx=yyy.
|
||||
|
||||
\fB\--license\fR print GPLv3+ license
|
||||
|
||||
|
@ -79,7 +79,9 @@ mqtt_publish) sent to a REST API (eg curl) or store it in a database
|
|||
|
||||
\fB\--resetafter=\fR<time> reset the wmbus dongle regularly, default is 23h
|
||||
|
||||
\fB\--selectfields=\fRid,timestamp,total_m3 select fields to be printed (--listfields=<meter> to list available fields)
|
||||
\fB\--addfields=\fRtimestamp_ut add the timestamp_ut field to be printed (--listfields=<meter> to list available fields)
|
||||
|
||||
\fB\--selectfields=\fRid,timestamp,total_m3 select only these fields to be printed (--listfields=<meter> to list available fields)
|
||||
|
||||
\fB\--separator=\fR<c> change field separator to c
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue