udevadm master github/master
authorChristian Weiske <cweiske@cweiske.de>
Wed, 29 Nov 2023 21:24:20 +0000 (22:24 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 29 Nov 2023 21:24:20 +0000 (22:24 +0100)
Makefile
README.rst
htmlreport/config.php.dist
munin/usb-wde1-log-last.sh
munin/usb-wde1_
systemd/usb-wde1-log.service [new file with mode: 0644]

index 4cba1540e1da138bef2c6b175f1627a7a6f19090..b07409acb1d07081a833590ac3e04ec67298adec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,16 +3,19 @@ PLUGINS = /etc/munin/plugins
 install: lninstall
 
 lninstall:
-       ln -sf $(abspath init.d/usb-wde-log) /etc/init.d
-       insserv usb-wde-log
+       ln -sf $(abspath systemd/usb-wde1-log.service) /etc/systemd/system/
+       systemctl daemon-reload
+       systemctl start usb-wde1-log
+       systemctl enable usb-wde1-log
 
        ln -sf $(abspath munin/usb-wde1_) $(PLUGINS)/usb-wde1_temperature
        ln -sf $(abspath munin/usb-wde1_) $(PLUGINS)/usb-wde1_humidity
 
 uninstall:
-       service usb-wde-log stop
-       insserv -r usb-wde-log
-       rm -f /etc/init.d/usb-wde-log
+       systemctl stop usb-wde1-log
+       systemctl disable usb-wde1-log
+       rm /etc/systemd/system/usb-wde1-log.service
+       systemctl daemon-reload
 
        rm -f $(PLUGINS)/usb-wde1_temperature
        rm -f $(PLUGINS)/usb-wde1_humidity
index 87a7d4b46f6898a20f8b69a74e896340c9b18ca3..9467f8e92abba7a3cddb19ddd190201c4e40f8c9 100644 (file)
@@ -28,20 +28,29 @@ Setup
 
      $ cd munin && nohup ./usb-wde1-log-last.sh &
 
-   once. It backgrounds the logging process and logs into /tmp/usb-wde1-last.
+   once. It backgrounds the logging process and logs into ``/var/spool/usb-wde1/usb-wde1-last``.
    This process needs to be started whenever the machine is rebooted.
 
+   The ``systemd/`` directory contains a ``usb-wde1-log.service`` file you can copy to
+   ``/etc/systemd/system/``. After copying it, run::
+
+     $ systemctl daemon-reload
+     $ systemctl start usb-wde1-log
+     $ systemctl status usb-wde1-log
+     $ systemctl enable usb-wde1-log
+
 2. Link the munin plugin::
 
    $ cd /etc/munin/plugins
    $ ln -s /usr/local/src/usb-wde1-tools/munin/usb-wde1_ usb-wde1_temperature
    $ ln -s /usr/local/src/usb-wde1-tools/munin/usb-wde1_ usb-wde1_humidity
 
-3. Configure the plugins
-   Edit /etc/munin/plugin-conf.d/munin-node and add the following lines::
+3. Configure the plugins:
+
+   Edit ``/etc/munin/plugin-conf.d/munin-node`` and add the following lines::
 
      [usb-wde1_*]
-     env.logfile /tmp/usb-wde1-last
+     env.logfile /var/spool/usb-wde1/usb-wde1-last
      env.host_name House
      env.sensors 0 1 7
      env.sensor0 Living room
@@ -119,3 +128,32 @@ Install PHP and the PHP rrd extension (``pear install pecl/rrd``) to make it
 work.
 
 Run ``gen-html.php`` every 5 minutes.
+
+
+Static USB device name
+======================
+When you have multiple serial USB devices attached to the computer,
+rebooting may lead to switched ttyUSB* numbers.
+
+A solution is to define a udev rule in ``/etc/udev/rules.d/99-usb-wde1.rules``::
+
+  SUBSYSTEM=="tty", ATTRS{serial}=="XQJ2EJEMADDFYBD3", SYMLINK+="usbwde1"
+
+You can find the serial number in ``dmesg`` output::
+
+  usb 1-3: new full-speed USB device number 2 using xhci_hcd
+  usb 1-3: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 1.00
+  usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
+  usb 1-3: Product: ELV USB-WDE1 Wetterdatenempfänger
+  usb 1-3: Manufacturer: Silicon Labs
+  usb 1-3: SerialNumber: XQJ2EJEMADDFYBD3
+
+After creating the file, activate it::
+
+  $ udevadm control --reload
+  $ udevadm trigger
+
+Now a file ``/dev/usbwde1`` exists.
+
+Modify ``munin/usb-wde1-log-last.sh`` to use the new device file instead
+of ``ttyUSB0``.
index 0720e331088f37b655331b4d59b3f96065327013..92b379300a1cae272c353144120205bf4d2b86eb 100644 (file)
@@ -3,6 +3,8 @@
  * path to the .rrd files.
  * {item} will be replaced with humidity/temperature,
  * {id} with the sensor number
+ *
+ * May be an array with the same keys as in $names.
  */
 $filetemplate = '/var/lib/munin/home.cweiske.de/haus-usb_wde1_{item}-sensor{id}-g.rrd';
 $outdir = '/tmp/';
index 9603dce5e893822860a86f03bd8eb0e1cbc933f3..620dd0cca8414063f1ed138478fabe1270bd024c 100755 (executable)
 #
 # FIXME: send RESET or INIT and M2
 
+device=/dev/ttyUSB0
+
+if [ ! -d /var/spool/usb-wde1 ]; then
+    mkdir /var/spool/usb-wde1
+fi
+
 curdir="$(dirname "$0")"
 if [ "$1" = "--dummy-data" ]; then
     $curdir/../dummy-data-generator.php\
-     | $curdir/log-single-line.sh /tmp/usb-wde1-last
+     | $curdir/log-single-line.sh /var/spool/usb-wde1/usb-wde1-last
 else
-    if [ ! -r /dev/ttyUSB0 ]; then
-        echo "Device /dev/ttyUSB0 is not readable"
+    if [ ! -r $device ]; then
+        echo "Device $device is not readable"
         exit 1
     fi
 
     #socat breaks something that leads to
     # WRONG VAL, WRONG CMD and FullBuff->Reset
     # errors
-    socat /dev/ttyUSB0,b9600,min=1,time=1,brkint=0,icrnl=0,ixoff=1,imaxbel=0,opost=0,isig=0,icanon=0,iexten=0,echo=0,echoe=0,echok=0 STDOUT\
-     | $curdir/log-single-line.sh /tmp/usb-wde1-last
+    socat $device,b9600,min=1,time=1,brkint=0,icrnl=0,ixoff=1,imaxbel=0,opost=0,isig=0,icanon=0,iexten=0,echo=0,echoe=0,echok=0 STDOUT\
+     | $curdir/log-single-line.sh /var/spool/usb-wde1/usb-wde1-last
 fi
index 6bae030f690701732e97909288d1cfdce993ee91..3c75c72d43378cdca9baf144cbd76620cc7c6088 100755 (executable)
@@ -15,7 +15,7 @@ usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
 =head2 EXAMPLE CONFIGURATION
 
  [usb-wde1_*]
-  env.logfile /tmp/usb-wde1-last
+  env.logfile /var/spool/usb-wde1/usb-wde1-last
   env.host_name House
   env.sensors 0 1 7
   env.sensor0 Living room
diff --git a/systemd/usb-wde1-log.service b/systemd/usb-wde1-log.service
new file mode 100644 (file)
index 0000000..b069fdb
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=USB-WDE1-Wetterdatenlogger
+After=systemd-udev-settle.service
+
+[Service]
+Type=simple
+User=root
+Group=root
+WorkingDirectory=/usr/local/src/usb-wde1-tools/munin/
+ExecStart=/usr/local/src/usb-wde1-tools/munin/usb-wde1-log-last.sh
+Restart=always
+RestartSec=30
+
+[Install]
+WantedBy=multi-user.target