Updated README and fixed auto rtlsdr problem.

pull/70/head 0.9.23
weetmuts 2020-02-02 17:05:10 +01:00
rodzic 7f7fb464c2
commit ffeed3f798
7 zmienionych plików z 140 dodań i 68 usunięć

12
CHANGES
Wyświetl plik

@ -1,3 +1,15 @@
Version 0.9.23: 2020-02-02
Added the electricity meters:
ESysWM-20 (esyswm) from EasyMeter
eHZ Generation P (ehzp) from EMH Metering
Added the water meter:
Q400 (q400) from Axis Industries.
Fixed a bug in the auto-start from udev that
prevented rtlsdr/rtlwmbus to work properly.
Version 0.9.22: 2020-01-19
Bibo added docker support. Thanks Bibo!

Wyświetl plik

@ -370,8 +370,10 @@ If you do not want the daemon to start automatically, simply edit
`,TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters.service"` from each
line.
You can also start/stop the daemon with `sudo systemctl start wmbusmeters`
You can also start/stop the daemon with `sudo systemctl restart wmbusmeters@im871a_0`
and trigger the daemon to reload the config files with `sudo killall -HUP wmbusmetersd`
If you add more dongles, then more daemons gets started. Each daemon gets a unique name
like `wmbusmeters@im871a_0 wmbusmeters@im871a_1`.
# Source code

Wyświetl plik

@ -223,7 +223,7 @@ then
# Create service file
cat <<EOF > "$ROOT"/etc/systemd/system/wmbusmeters@.service
[Unit]
Description="wmbusmeters service on %i"
Description="wmbusmeters service on %I"
After=network.target
StopWhenUnneeded=true
@ -246,7 +246,7 @@ ExecStartPre=/bin/chown -R wmbusmeters:wmbusmeters /var/log/wmbusmeters
ExecStartPre=-/bin/mkdir -p /var/run/wmbusmeters
ExecStartPre=/bin/chown -R wmbusmeters:wmbusmeters /var/run/wmbusmeters
ExecStart=/usr/sbin/wmbusmetersd --device=/dev/%i /var/run/wmbusmeters/wmbusmeters-%i.pid
ExecStart=/usr/sbin/wmbusmetersd --device='%I' /var/run/wmbusmeters/wmbusmeters-%i.pid
ExecReload=/bin/kill -HUP `cat /var/run/wmbusmeters/wmbusmeters-%i.pid 2> /dev/null` 2> /dev/null || true
PIDFile=/var/run/wmbusmeters/wmbusmeters-%i.pid
@ -284,10 +284,10 @@ then
mkdir -p "$ROOT"/etc/udev/rules.d
# Create service file
cat <<EOF > "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",SYMLINK+="im871a",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",SYMLINK+="amb8465",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838",SYMLINK+="rtlsdr",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
SUBSYSTEM=="usb", ATTRS{idVendor}=="2047", ATTRS{idProduct}=="0863",SYMLINK+="rfmrx2",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",SYMLINK+="im871a_%n",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@/dev/im871a_%n.service"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",SYMLINK+="amb8465_%n",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@/dev/amb8465_%n.service"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838",SYMLINK+="rtlsdr_%n",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@/dev/rtlsdr_%n.service"
SUBSYSTEM=="usb", ATTRS{idVendor}=="2047", ATTRS{idProduct}=="0863",SYMLINK+="rfmrx2_%n",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@/dev/rfmrx2_%n.service"
EOF
echo udev: installed "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
else

Wyświetl plik

@ -1,5 +1,5 @@
/*
Copyright (C) 2019 Fredrik Öhrström
Copyright (C) 2019-2020 Fredrik Öhrström
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
@ -357,7 +357,9 @@ unique_ptr<Configuration> loadConfiguration(string root, string device_override,
c->json = true;
vector<char> global_conf;
bool ok = loadFile(root+"/etc/wmbusmeters.conf", &global_conf);
string conf_file = root+"/etc/wmbusmeters.conf";
debug("(config) loading %s\n", conf_file.c_str());
bool ok = loadFile(conf_file, &global_conf);
global_conf.push_back('\n');
if (!ok) exit(1);
@ -408,6 +410,11 @@ unique_ptr<Configuration> loadConfiguration(string root, string device_override,
if (device_override != "")
{
if (startsWith(device_override, "/dev/rtlsdr"))
{
debug("(config) use rtlwmbus instead of raw device %s\n", device_override.c_str());
device_override = "rtlwmbus";
}
debug("(config) overriding device with \"%s\"\n", device_override.c_str());
handleDevice(c, device_override);
}

Wyświetl plik

@ -54,7 +54,7 @@ int main(int argc, char **argv)
}
if (cmdline->license) {
const char * license = R"LICENSE(
Copyright (C) 2017-2019 Fredrik Öhrström
Copyright (C) 2017-2020 Fredrik Öhrström
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

Wyświetl plik

@ -497,84 +497,80 @@ bool detectRawTTY(string device, int baud, SerialCommunicationManager *handler);
bool detectRTLSDR(string device, SerialCommunicationManager *handler);
bool detectCUL(string device, SerialCommunicationManager *handler);
#define CHECK_SAME_GROUP \
if (ac == AccessCheck::NotSameGroup) \
{ \
/* The device exists and is not locked, but we cannot read it! */ \
error("You are not in the same group as the device %s\n", devicefile.c_str()); \
}
Detected detectAuto(string devicefile,
string suffix,
SerialCommunicationManager *handler)
{
assert(devicefile == "auto");
if (suffix != "")
{
error("You cannot have a suffix appended to auto.\n");
}
if (detectIM871A("/dev/im871a", handler))
{
return { DEVICE_IM871A, "/dev/im871a", 0, false };
}
else
{
AccessCheck ac = checkIfExistsAndSameGroup("/dev/im871a");
if (ac == AccessCheck::NotSameGroup)
{
// The device exists but we cannot read it!
error("You are not in the same group as the device /dev/im871a\n");
}
}
AccessCheck ac;
if (detectAMB8465("/dev/amb8465", handler))
{
return { DEVICE_AMB8465, "/dev/amb8465", false };
}
else
{
AccessCheck ac = checkIfExistsAndSameGroup("/dev/amb8465");
if (ac == AccessCheck::NotSameGroup)
{
// The device exists but we cannot read it!
error("You are not in the same group as the device /dev/amb8465\n");
}
}
ac = findAndDetect(handler, &devicefile,
[](string d, SerialCommunicationManager* m){ return detectIM871A(d, m);},
"im871a",
"/dev/im871a");
if (detectRawTTY("/dev/rfmrx2", 38400, handler))
if (ac == AccessCheck::OK)
{
return { DEVICE_RFMRX2, "/dev/rfmrx2", false };
}
else
{
AccessCheck ac = checkIfExistsAndSameGroup("/dev/rfmrx2");
if (ac == AccessCheck::NotSameGroup)
{
// The device exists but we cannot read it!
error("You are not in the same group as the device /dev/rfmrx2\n");
}
return { DEVICE_IM871A, devicefile, 0, false };
}
CHECK_SAME_GROUP
if (detectRTLSDR("/dev/rtlsdr", handler))
{
return { DEVICE_RTLWMBUS, "rtlwmbus" };
}
else
{
AccessCheck ac = checkIfExistsAndSameGroup("/dev/amb8465");
if (ac == AccessCheck::NotSameGroup)
{
// The device exists but we cannot read it!
error("You are not in the same group as the device /dev/amb8465\n");
}
}
ac = findAndDetect(handler, &devicefile,
[](string d, SerialCommunicationManager* m){ return detectAMB8465(d, m);},
"amb8465",
"/dev/amb8465");
if (detectCUL("/dev/ttyUSB0", handler))
if (ac == AccessCheck::OK)
{
return { DEVICE_AMB8465, devicefile, false };
}
CHECK_SAME_GROUP
ac = findAndDetect(handler, &devicefile,
[](string d, SerialCommunicationManager* m){ return detectRawTTY(d, 38400, m);},
"rfmrx2",
"/dev/rfmrx2");
if (ac == AccessCheck::OK)
{
return { DEVICE_RFMRX2, devicefile, false };
}
CHECK_SAME_GROUP
ac = findAndDetect(handler, &devicefile,
[](string d, SerialCommunicationManager* m){ return detectCUL(d, m);},
"cul",
"/dev/ttyUSB0");
if (ac == AccessCheck::OK)
{
return { DEVICE_CUL, "/dev/ttyUSB0" };
}
else
CHECK_SAME_GROUP
ac = findAndDetect(handler, &devicefile,
[](string d, SerialCommunicationManager* m){ return detectRTLSDR(d, m);},
"rtlsdr",
"/dev/rtlsdr");
if (ac == AccessCheck::OK)
{
AccessCheck ac = checkIfExistsAndSameGroup("/dev/ttyUSB0");
if (ac == AccessCheck::NotSameGroup)
{
// The device exists but we cannot read it!
error("You are not in the same group as the device CUL\n");
}
return { DEVICE_RTLWMBUS, "rtlwmbus" };
}
CHECK_SAME_GROUP
// We could not auto-detect any device.
return { DEVICE_UNKNOWN, "", false };
@ -3414,3 +3410,52 @@ LIST_OF_AFL_AUTH_TYPES
return AFLAuthenticationType::Reserved1;
}
AccessCheck findAndDetect(SerialCommunicationManager *manager, string *out_device,
function<bool(string,SerialCommunicationManager*)> check,
string dongle_name,
string device_root)
{
string dev = device_root;
debug("(%s) exists? %s\n", dongle_name.c_str(), dev.c_str());
AccessCheck ac = checkIfExistsAndSameGroup(dev);
*out_device = dev;
if (ac == AccessCheck::OK)
{
debug("(%s) checking %s\n", dongle_name.c_str(), dev.c_str());
if (detectIM871A(dev, manager)) return AccessCheck::OK;
return AccessCheck::NotThere;
}
if (ac == AccessCheck::NotSameGroup)
{
// Device exists, but you do not belong to its group!
// This will short circuit testing for other devices.
// But not being in the same group is such a problematic
// situation, that we can stop early.
return AccessCheck::NotSameGroup;
}
for (int n=0; n < 9; ++n)
{
dev = device_root+"_"+to_string(n);
debug("(%s) exists? %s\n", dongle_name.c_str(), dev.c_str());
AccessCheck ac = checkIfExistsAndSameGroup(dev);
*out_device = dev;
if (ac == AccessCheck::OK)
{
debug("(%s) checking %s\n", dongle_name.c_str(), dev.c_str());
if (detectIM871A(dev, manager)) return AccessCheck::OK;
// If we get here, the device /dev/im871a_0 could be locked
// try /dev/im871a_1 etc...
}
if (ac == AccessCheck::NotSameGroup)
{
// Device exists, but you do not belong to its group!
return AccessCheck::NotSameGroup;
}
}
*out_device = "";
// No device found!
return AccessCheck::NotThere;
}

Wyświetl plik

@ -460,4 +460,10 @@ MeasurementType difMeasurementType(int dif);
string linkModeName(LinkMode link_mode);
string measurementTypeName(MeasurementType mt);
AccessCheck findAndDetect(SerialCommunicationManager *manager,
string *out_device,
function<bool(string,SerialCommunicationManager*)> check,
string dongle_name,
string device_root);
#endif