Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIOD Support through alternative implementation of the HWIF interface #525

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

wrichter
Copy link

@wrichter wrichter commented Jun 4, 2022

I'm running vzlogger on Fedora/RPi4 which no longer supports the legacy GPIO interface and has a changed MMAP layout. Neither of the existing approaches worked for me. Therefore I've implemented support for libGPIOD (which works both on Debian as well as Fedora).

In order to retain backwards compatibility with the config file syntax / not to introduce additional config fields, a GPIO line > 1000 will trigger the GPIOD implementation, and GPIO lines <1000 will trigger the old GPIO (/sys fs-based) implementation.

Currently there is no way to specify which gpiochip to use, it always defaults to gpiochip0.

@wrichter
Copy link
Author

wrichter commented Jun 9, 2022

Am currently reworking this to prevent spurious readings - pls don't merge right now

@J-A-U
Copy link
Collaborator

J-A-U commented Jun 10, 2022

I won't merge anything as long as the checks fail.

@wrichter
Copy link
Author

sounds prudent :-) given that libgpiod is a new dependency, the test env needs to include it as well, otherwise it will continue to fail. How can this be done?

@r00t-
Copy link
Contributor

r00t- commented Jun 10, 2022

@wrichter
Copy link
Author

Thanks, am currently out and will do it when I'm back at home after next week.

@wrichter
Copy link
Author

Hi @r00t- , hi @J-A-U can you please rerun the workflows to see if the code is now in better shape?

@wrichter
Copy link
Author

the tests have additional #defines which interfere with the compilation… will work around

@wrichter
Copy link
Author

@r00t- @J-A-U could you please run the workflows again?

@wrichter
Copy link
Author

Thanks... so this is a bit annoying :-( the clang-format on my system creates a formatting incompatible with what the test requires:

wrichter@wrichter-mac vzlogger % uname -a
Darwin wrichter-mac 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64
wrichter@wrichter-mac vzlogger % clang-format --version
clang-format version 14.0.4 
wrichter@wrichter-mac vzlogger % find include src tests  -type f -name '*.h' -o -name '*.cpp' -o -name '*.hpp' | xargs -I{} -P1 clang-format -i -style=file {}
wrichter@wrichter-mac vzlogger % git status
On branch gpiod
Your branch is up to date with 'origin/gpiod'.

nothing to commit, working tree clean
wrichter@wrichter-mac vzlogger %

Same when I try it from within a debian:stable container on another machine:

root@4d889486e0c9:/workdir# uname -a
Linux 4d889486e0c9 5.17.12-300.fc36.aarch64 #1 SMP Mon May 30 16:39:03 UTC 2022 aarch64 GNU/Linux
root@4d889486e0c9:/workdir# clang-format --version
Debian clang-format version 11.0.1-2
root@4d889486e0c9:/workdir# find include src tests  -type f -name '*.h' -o -name '*.cpp' -o -name '*.hpp' | xargs -I{} -P1 clang-format -i -style=file {}
root@4d889486e0c9:/workdir# git status
On branch gpiod
Your branch is up to date with 'origin/gpiod'.

nothing to commit, working tree clean
root@4d889486e0c9:/workdir#

Question 1: Do you have any tipps how to massage things so that the formatting is acceptable?

Question 2: The test fails because it doesn't link the GPIOD libs. This is my first exposure to CMake and I'm lost where to add them for the tests. Could you please help me? (for the vzlogger itself I made the following changes):

wrichter@wrichter-mac vzlogger % git diff master gpiod -- CMakeLists.txt src/CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c053b62..d278612 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -171,6 +171,8 @@ endif(WIN32)

 find_library(LIBUUID uuid)
 find_library(LIBGCRYPT gcrypt)
+find_library(GPIOD_LIBRARY NAMES libgpiod.so)
+

 include_directories(${CMAKE_BINARY_DIR})
 include_directories(${CMAKE_SOURCE_DIR}/include)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cd76ec2..473b5d0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,7 +81,7 @@ if( TARGET )
     target_link_libraries(vzlogger dl)
   endif( ${TARGET} STREQUAL "ar71xx")
 endif( TARGET )
-target_link_libraries(vzlogger ${CURL_STATIC_LIBRARIES} ${CURL_LIBRARIES} unistring ${GNUTLS_LIBRARIES} ${OPENSSL_LIBRARIES} )
+target_link_libraries(vzlogger ${CURL_STATIC_LIBRARIES} ${CURL_LIBRARIES} unistring ${GNUTLS_LIBRARIES} ${OPENSSL_LIBRARIES} ${GPIOD_LIBRARY})

 # add programs to the install target
 INSTALL(PROGRAMS
wrichter@wrichter-mac vzlogger %

@wrichter wrichter mentioned this pull request Aug 25, 2022
@leoguiders
Copy link

Hi Wolfram,

found your gpiod branch while trying to get S0 working on a Raspberry Pi 3B. Thanks for your work, I'm currently testing the gpiod support with my S0-meter.

In order to retain backwards compatibility with the config file syntax / not to introduce additional config fields, a GPIO line > 1000 will trigger the GPIOD implementation, and GPIO lines <1000 will trigger the old GPIO (/sys fs-based) implementation.

This does feel hacky.

Currently there is no way to specify which gpiochip to use, it always defaults to gpiochip0.

The "device" configuration-string is currently unused when setting the gpio value. That would be a good place to set the gpiochip. Maybe not less hacky than the current solution, but what about switching to gpiod when gpio is set and device string starts with "/dev/gpiochip" (or gpiod_is_gpiochip_device(device) returns true for that matter) ?

@wrichter
Copy link
Author

Hi Wolfram,

found your gpiod branch while trying to get S0 working on a Raspberry Pi 3B. Thanks for your work, I'm currently testing the gpiod support with my S0-meter.

In order to retain backwards compatibility with the config file syntax / not to introduce additional config fields, a GPIO line > 1000 will trigger the GPIOD implementation, and GPIO lines <1000 will trigger the old GPIO (/sys fs-based) implementation.

This does feel hacky.

It sure is. Of course we could also introduce a new Boolean config parameter use_gpiod which defaults to false. Cleaner would be to just create a new config parameter hardware_interface_impl that has values like „uart“, „gpio_sysfs“, „gpio_mmap“, „gpiod“ and „legacy“ and defaults to „legacy“. Then existing users can continue to use the magic decisiontree to decide whether to use the uart/gpio/mmap implementations and new users have a single place to specify which implementation they want. This feels like a separate pull request though.

Currently there is no way to specify which gpiochip to use, it always defaults to gpiochip0.

The "device" configuration-string is currently unused when setting the gpio value. That would be a good place to set the gpiochip. Maybe not less hacky than the current solution, but what about switching to gpiod when gpio is set and device string starts with "/dev/gpiochip" (or gpiod_is_gpiochip_device(device) returns true for that matter) ?

again laziness on my side. I like the idea - would you want to send a pull request to https://github.com/wrichter/vzlogger/tree/gpiod ?

@leoguiders
Copy link

I'm still trying to get my head around what is required and what is the most user-friendly way to configure this.

The question here really is - do we need do support /sysfs and gpiod at the same time or can we just assume that gpiod is the better way to deal with gpios and use it if available and fallback to /sysfs if it isn't?

@wrichter
Copy link
Author

so I personally do think that GPIOD is the better solution, and I have been running the implementation successfully for the last ~4 months. But it hasn't seen much testing beyond my setup, is not yet merged with the main development branch, etc... I expect both versions will need to be supported in parallel until the GPIOD version has seen more testing. At the moment it can't even be merged since some tests fail - which I believe is currently caused by something else than my code, but also the tests don't yet know anything about GPIOD (which was the reason it failed earlier - see #525 (comment) ).

@trabant-asb
Copy link

May I ask why active_low ist set true in MeterS0.cpp when using libgpiod?

	if (_configureGPIO) {
		print(log_info, "configuring GPIO via GPIOD (active low)", "S0");
		flags = GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
	}

In the sysfs implementation it is set to 0:

 name.append("/sys/class/gpio/gpio");
                name.append(std::to_string(_gpiopin));
                name.append("/active_low");
                fd = ::open(name.c_str(), O_WRONLY);
                if (fd < 0)
                        throw vz::VZException("open active_low failed");
                res = ::write(fd, "0\n", 2);
                if (2 != res)
                        throw vz::VZException("set active_low failed");
                if (::close(fd) < 0)
                        throw vz::VZException("set active_low failed");

In my understanding vzlogger expects a pulled down gpio bin, which receives positive impulses from the S0 meter. setting active_low to true would kind of invert this logic.

@wrichter
Copy link
Author

May I ask why active_low ist set true in MeterS0.cpp when using libgpiod?

I did not look at the sysfs implementation since that was a non-starter on Fedora. When designing my system I took a look at chapter 8 in https://www.elektronik-kompendium.de/sites/raspberry-pi/2006051.htm (German) which basically says "it probably doesn't matter much, but a pull-up resistor and signalling by connecting the pin to ground is a bit more interference-resistant".

@trabant-asb
Copy link

trabant-asb commented Nov 23, 2022

May I ask why active_low ist set true in MeterS0.cpp when using libgpiod?

I did not look at the sysfs implementation since that was a non-starter on Fedora. When designing my system I took a look at chapter 8 in https://www.elektronik-kompendium.de/sites/raspberry-pi/2006051.htm (German) which basically says "it probably doesn't matter much, but a pull-up resistor and signalling by connecting the pin to ground is a bit more interference-resistant".

While I agree that it won't matter much from the technical perspective, I see a consistency issue here. vzlogger was originally written to work with certain hardware extensions like https://wiki.volkszaehler.org/hardware/controllers/raspberry_pi_erweiterung_mit_schaltausgaengen_rev.1, which to my best knowledge use the pull-down logic.

And people (like me) who started with the VZ at a time when the extensions were not available any longer, learned that a pull-down hard- or soft-resistor is the easiest way to make it work, because it works that way with the default configure_gpio setting in vzlogger.conf, without the need to configure the gpio pin manually or edit the vzlogger code.

So, if any person with a working S0 config changes from sysfs to gpiochip, he or she could likely see issues. For example, vzlogger will not count impulses any more, but the time between impulses - which indeed will generate some output, but it might be erroneous.

So from that perspective I think both sysfs as well as the gpiochip implementation (which is definitely the way to go!) should do the same default pin setup.

In my personal opinion some new configuration parameters could however make sense, like for your use case, or indeed, for setting the soft resistors with GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN or _UP, which is a new capability and could not be done with sysfs at all.

@wrichter
Copy link
Author

wrichter commented Nov 23, 2022

Legacy makes a compelling case :-) My hardware lives on a breadboard, so I can somewhat simply rewire towards a pulldown resistor. I believe that this should be configurable and default to whatever is similar to the implementations out there.

Properly making stuff configurable was the discussion earlier in this thread; see #525 (comment)

While we're pondering about the best way, you can get to an "active high" behavior by setting configureGPIO to false (it's the only thing that the GPIOD code configures, the other aspects like which level/edge to react to are haredcoded).

@trabant-asb
Copy link

trabant-asb commented Nov 24, 2022

Edited my last post - the part with the soft resistor flags did not make sense...
Regarding the configuration options, it might make sense to keep configureGPIO in vzlogger.conf, with true doing the same as with the sysfs configuration, but allow detailed options like active_low, bias_pull_down and so on.

@trabant-asb
Copy link

I expect both versions will need to be supported in parallel until the GPIOD version has seen more testing.

So far I have tested the gpiod based vzlogger for a few days in my environment (S0 cyble sensor attached to my gas meter) and didn't see any problems. I do like the states mechanism in general and especially the high_wait parameter, which I could tune to the pulse length from the spec of the electronic (cyble) sensor and thereby avoid some rare electrostatic interference to be counted... setting debounce_delay to 0 and high_wait to 60 did the trick.

The question here really is - do we need do support /sysfs and gpiod at the same time or can we just assume that gpiod is the better way to deal with gpios and use it if available and fallback to /sysfs if it isn't?

Imho, this makes sense for the time being... with the current linux kernels, both options can be enabled at compile time, however as I understand it the gpiochip solution will finally replace the sysfs way.

One more related configuration thing that was referenced in this thread...

The "device" configuration-string is currently unused when setting the gpio value. That would be a good place to set the gpiochip.

... defaulting to /dev/gpiochip0 when the device option is not set?

I'm not sure if I can be of any help in bringing this PR forward to be merged, having no idea why the github build fails; however I could try to implement the idea I had with that configureGPIO options....

Regarding the configuration options, it might make sense to keep configureGPIO in vzlogger.conf, with true doing the same as with the sysfs configuration, but allow detailed options like active_low, bias_pull_down and so on.

Not sure if any of my thoughts are helpful... let me know what you think.

@wrichter
Copy link
Author

@trabant-rgb Agree with your comments. I suppose I need to reach out to the developers mailing list to get help; the GitHub discussion does not create much interaction with the project maintainers. if I only had more free time…

@wrichter
Copy link
Author

Yeah I noodled over it a bit as well. I have coded up a quick solution which adds a counter that is incremented whenever the HIGH state is entered, and reset to 0 when the LOW state is entered. A pulse is only detected at a state transition to HIGH when the counter is exactly 1. This means only the first transition from LOW to HIGH will be considered, HIGH->DEBOUNCE->HIGH transitions will have a counter value greater than 1. I'm testing it tonight to see if this works.

@trabant-asb
Copy link

I'm testing it tonight to see if this works.

Any chance to get that new MeterS0.cpp to test it in my environment?

@wrichter
Copy link
Author

I just pushed the commit - if you use the latest version in my gpiod branch, it includes the counter a5551bc

@trabant-asb
Copy link

I just pushed the commit - if you use the latest version in my gpiod branch, it includes the counter a5551bc

That was fast... I've run the new code over the night and reviewed my log file this morning. Indeed on several occasions it has prevented wrong impulses to be counted.

@trabant-asb
Copy link

Just to give you some positive feedback... I did run your code with the electronic cyble sensor about half a year and am now using it with your latest code changes for about 2 months with a vendor supplied reed contact on another meter. I have a lot of electrostatical noise (which I see when turning on logging) and am running the sensor directly on a Raspberry GPIO line.

In spite of this non-optimal environment, I am not getting any irregular readings logged. Good job!

@belegdol
Copy link

belegdol commented Jan 9, 2024

I tried using your branch but I cannot get vzlogger to start:

[Jan 09 10:54:57][main] vzlogger v0.8.2 based on heads/gpiod-0-g1f5979dab2 from Sun, 18 Jun 2023 16:38:55 +0200 started.
[Jan 09 10:54:57]       New meter initialized (protocol=sml)
[Jan 09 10:54:57][chn0] New channel initialized (uuid=...166991 api=volkszaehler id=1-0:1.8.0*255)
[Jan 09 10:54:57][chn1] New channel initialized (uuid=...3440e5 api=volkszaehler id=1-0:16.7.0*255)
[Jan 09 10:54:57][s0]   GPIO Pin 1024 greater than 1000. Using GPIOD interface for gpio.
[Jan 09 10:54:57][S0]   Initialized with config gpiopin 24, configureGPIO false, debounce_delay 30, high_wait 250
[Jan 09 10:54:57]       New meter initialized (protocol=s0)
[Jan 09 10:54:57][chn2] New channel initialized (uuid=...89dc6a api=volkszaehler id=Impulse)
[Jan 09 10:54:57][main] log level is 5
[Jan 09 10:54:57]       Daemonize process...
[Jan 09 10:54:57][mtr0] Meter connection established
[Jan 09 10:54:57][]     Startup failed: line request input failed, errno 16

Here is my config:

         "protocol" : "s0",
         "enabled" : true,
         "gpio" : 1024, 
         "configureGPIO" : false,
         "debounce_delay" : 30,
         "high_wait" : 250,
         "channels": [{
                 "uuid" : "918f7ff0-ae33-11ee-9c97-b19e2a89dc6a",
                 "middleware" : "http://odroidxu4.local:8080",
                 "identifier" : "Impulse"

What am I missing?

@wrichter
Copy link
Author

wrichter commented Jan 9, 2024

Errno 16 is "device or resource is busy". Can you check with gpioinfo https://www.acmesystems.it/gpiod whether line 24 is indeed free to use?

@belegdol
Copy link

belegdol commented Jan 9, 2024

It seems to be used by sysfs:

gpiochip0 - 54 lines:
	line   0:       "SDA0"       unused   input  active-high 
	line   1:       "SCL0"       unused   input  active-high 
	line   2:       "SDA1"       unused   input  active-high 
	line   3:       "SCL1"       unused   input  active-high 
	line   4:  "GPIO_GCLK"      "sysfs"   input  active-high [used]
	line   5:  "CAM_GPIO1"       unused  output  active-high 
	line   6:    "LAN_RUN"       unused  output  active-high 
	line   7:  "SPI_CE1_N"       unused   input  active-high 
	line   8:  "SPI_CE0_N"       unused   input  active-high 
	line   9:   "SPI_MISO"       unused   input  active-high 
	line  10:   "SPI_MOSI"       unused   input  active-high 
	line  11:   "SPI_SCLK"       unused   input  active-high 
	line  12:         "NC"       unused   input  active-high 
	line  13:         "NC"       unused   input  active-high 
	line  14:       "TXD0"       unused   input  active-high 
	line  15:       "RXD0"       unused   input  active-high 
	line  16: "STATUS_LED_N" "ACT" output active-low [used]
	line  17:     "GPIO17"      "sysfs"   input  active-high [used]
	line  18:     "GPIO18"      "sysfs"   input  active-high [used]
	line  19:         "NC"       unused   input  active-high 
	line  20:         "NC"       unused   input  active-high 
	line  21:  "CAM_GPIO0" "cam1_regulator" output active-high [used]
	line  22:     "GPIO22"      "sysfs"   input  active-high [used]
	line  23:     "GPIO23"      "sysfs"   input  active-high [used]
	line  24:     "GPIO24"      "sysfs"   input  active-high [used]
	line  25:     "GPIO25"      "sysfs"  output  active-high [used]
	line  26:         "NC"       unused   input  active-high 
	line  27:     "GPIO27"      "sysfs"   input  active-high [used]
	line  28:     "GPIO28"       unused   input  active-high 
	line  29:     "GPIO29"       unused   input  active-high 
	line  30:     "GPIO30"       unused   input  active-high 
	line  31:     "GPIO31"       unused   input  active-high 
	line  32:         "NC"       unused   input  active-high 
	line  33:         "NC"       unused   input  active-high 
	line  34:         "NC"       unused   input  active-high 
	line  35:         "NC"       unused   input  active-high 
	line  36:         "NC"       unused   input  active-high 
	line  37:         "NC"       unused   input  active-high 
	line  38:         "NC"       unused   input  active-high 
	line  39:         "NC"       unused   input  active-high 
	line  40:   "PWM0_OUT"       unused   input  active-high 
	line  41:         "NC"       unused   input  active-high 
	line  42:         "NC"       unused   input  active-high 
	line  43:         "NC"       unused   input  active-high 
	line  44:         "NC"       unused   input  active-high 
	line  45:   "PWM1_OUT"       unused   input  active-high 
	line  46: "HDMI_HPD_P"        "hpd"   input  active-high [used]
	line  47: "SD_CARD_DET" unused input active-high 
	line  48:   "SD_CLK_R"       unused   input  active-high 
	line  49:   "SD_CMD_R"       unused   input  active-high 
	line  50: "SD_DATA0_R"       unused   input  active-high 
	line  51: "SD_DATA1_R"       unused   input  active-high 
	line  52: "SD_DATA2_R"       unused   input  active-high 
	line  53: "SD_DATA3_R"       unused   input  active-high 
gpiochip1 - 4 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high

Do I need to specifically disable sysfs somehow?

@belegdol
Copy link

belegdol commented Jan 9, 2024

Rebooting the PI did not help, now the line is used by sysfs and set as output.

@belegdol
Copy link

belegdol commented Jan 9, 2024

echo 24 > /sys/class/gpio/unexport has helped but the question remains why it was exported in the first place. Some default config of the volkszähler image?

@wrichter
Copy link
Author

wrichter commented Jan 9, 2024

good question, I don't know. I'm personally using a Fedora IoT image which doesn't provide SysFS.

@belegdol
Copy link

belegdol commented Jan 9, 2024

Now that I have the code running, looks like some tweaks to the config or the set-up are required. I can reliably trigger invalid events by turning on CCFL tube light with a magnetic ballast. This is a correct event:

[Jan 09 12:59:06][S0]   [6254.137137778] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 12:59:06][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801546.917702642
[Jan 09 12:59:06][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801547.167852788
[Jan 09 12:59:07][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 12:59:07][chn2] Adding reading to queue (value=1.00 ts=1704801547199)

This happens if I turn on the lamp:

[Jan 09 13:02:29][S0]   [6456.995721183] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.995816177] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.996147158] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.996379145] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.996417143] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.996443141] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:29][S0]   [6456.996455140] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.428170449] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.428242445] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.428298441] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.428328440] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.439239810] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.721586507] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801751.503153320
[Jan 09 13:02:31][S0]   [6458.721627504] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801751.726304138
[Jan 09 13:02:31][S0]   [6458.721637504] GPIO event 1 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6458.721647503] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721701500] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721712499] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721724499] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721760497] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721770496] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721795495] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721807494] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721831493] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721846492] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721881490] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721881490] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.721896489] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6458.722613447] GPIO event 2 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 1 to 2 with a timeout at 1704801751.558168143
[Jan 09 13:02:31][chn2] Adding reading to queue (value=1.00 ts=1704801751510)
[Jan 09 13:02:31][S0]   [6458.797275136] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6458.797400129] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.797431127] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.797466125] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.797550120] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.797601118] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831329170] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831416165] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801751.613905925
[Jan 09 13:02:31][S0]   [6458.831466162] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6458.831478161] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831488161] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831499160] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831508160] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831561157] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831573156] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831585155] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831622153] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831629153] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801751.634702724
[Jan 09 13:02:31][S0]   [6458.831637152] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6458.831647152] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831676150] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   [6458.831746146] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801751.644830139
[Jan 09 13:02:31][S0]   [6458.832118124] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6459.81601719] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801751.863483514
[Jan 09 13:02:31][S0]   [6459.81631717] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801752.86981312
[Jan 09 13:02:31][S0]   [6459.81643717] GPIO event 1 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6459.81652716] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81703713] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81736711] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81746711] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81790708] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81790708] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81803707] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81826706] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81877703] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81889702] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81901702] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81927700] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.81942699] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   [6459.82636659] GPIO event 2 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 1 to 2 with a timeout at 1704801751.926428879
[Jan 09 13:02:31][S0]   [6459.86363444] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:31][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:31][S0]   [6459.117449649] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.260809371] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801752.42055203
[Jan 09 13:02:32][S0]   [6459.260865368] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801752.264608055
[Jan 09 13:02:32][S0]   [6459.260877367] GPIO event 1 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 13:02:32][S0]   [6459.260923365] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.260948363] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.260987361] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261014360] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261026359] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261054357] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261068356] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261081356] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261098355] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261112354] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261144352] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261171350] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261185350] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.261482333] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.269650861] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.269678859] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.492392003] GPIO event 2 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 1 to 2 with a timeout at 1704801752.272698889
[Jan 09 13:02:32][S0]   [6459.492424001] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801752.495385734
[Jan 09 13:02:32][S0]   [6459.492433001] GPIO event 2 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 2 with a timeout at 1704801752.277949586
[Jan 09 13:02:32][S0]   [6459.492445000] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:32][S0]   [6459.492489997] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.492499997] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.492525995] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.668814819] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.668953811] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.669041806] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.669160799] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.669208796] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.669268793] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.670897699] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.670985693] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671009692] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671033691] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671060689] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671083688] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671110686] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671135685] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671165683] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671203681] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671225680] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.671499664] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.679815184] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.679935177] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.681431090] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.682111051] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.683471973] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.684382920] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.684407919] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.684417918] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.684546911] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.686235813] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.752827969] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   [6459.752891965] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][chn2] Adding reading to queue (value=2.00 ts=1704801752052)
[Jan 09 13:02:32][S0]   [6459.951823482] GPIO event 1 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 0 to 2 with a timeout at 1704801752.734168250
[Jan 09 13:02:32][S0]   [6459.951863479] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801752.956938090
[Jan 09 13:02:32][S0]   [6459.951870479] GPIO event 1 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 13:02:32][S0]   [6459.951880478] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951885478] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951891478] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951900477] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951904477] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951932475] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.951939475] GPIO event 2 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 1 to 2 with a timeout at 1704801752.783436406
[Jan 09 13:02:32][S0]   [6459.952475444] GPIO event 1 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 3 with a timeout at 1704801753.5705275
[Jan 09 13:02:32][S0]   [6459.952490443] GPIO event 1 (1=rising edge, 2=falling edge) in current state 3
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: state machine transition from 3 to 1 with a timeout at -1.-1
[Jan 09 13:02:32][S0]   MeterS0:HWIF_GPIOD: ignoring transition to HIGH state due to high state count 2
[Jan 09 13:02:32][S0]   [6459.952496443] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.952503442] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.952542440] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.952542440] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:32][S0]   [6459.952549440] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:33][S0]   [6460.613217307] GPIO event 1 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:33][S0]   [6460.613241306] GPIO event 2 (1=rising edge, 2=falling edge) in current state 1
[Jan 09 13:02:33][S0]   MeterS0:HWIF_GPIOD: state machine transition from 1 to 2 with a timeout at 1704801753.392800235
[Jan 09 13:02:33][S0]   [6460.613248305] GPIO event 2 (1=rising edge, 2=falling edge) in current state 2
[Jan 09 13:02:33][S0]   MeterS0:HWIF_GPIOD: state machine transition from 2 to 0 with a timeout at -1.-1
[Jan 09 13:02:33][S0]   [6460.613275304] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613292303] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613297303] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613332301] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613339300] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613361299] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613366299] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613372298] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613415296] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613423295] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613448294] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613448294] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][S0]   [6460.613456293] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 13:02:33][chn2] Adding reading to queue (value=1.00 ts=1704801752740)
[Jan 09 13:02:41][S0]   [6468.797932432] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0

3 events were added to the queue as a result. The question is whether I am better off trying to tweak the settings or maybe switching to an active_low approach would be a better choice. According to the specification of the IN-Z62, the impulse should be at least 0,25 s.

@belegdol
Copy link

belegdol commented Jan 9, 2024

I tried 1000 ms high wait and the lamp is still able to generate an impulse.

@J-A-U
Copy link
Collaborator

J-A-U commented Jan 9, 2024

echo 24 > /sys/class/gpio/unexport has helped but the question remains why it was exported in the first place. Some default config of the volkszähler image?

Yes! See point 14.c) IX.: https://wiki.volkszaehler.org/howto/building_raspberry_pi_image_for_vz

@wrichter
Copy link
Author

wrichter commented Jan 9, 2024

So am I understanding correctly that the CCFL tube generates noise for ~4 seconds (13:02:29 to 13:02:33)?. Not sure what kind of logic could reliably distinguish between that and a legit signal. Is it possible to shield the CCFL or the line somehow? In my home, I only need to work around a spurious spike by an ELTAKO relay.

@belegdol
Copy link

belegdol commented Jan 9, 2024

So am I understanding correctly that the CCFL tube generates noise for ~4 seconds (13:02:29 to 13:02:33)?. Not sure what kind of logic could reliably distinguish between that and a legit signal. Is it possible to shield the CCFL or the line somehow? In my home, I only need to work around a spurious spike by an ELTAKO relay.

Looks like the lamp is my final boss indeed. I could rewire it for LED removing the ballast, maybe it would reduce the noise. Other than that, I could also see if I can use a shielded Cat cable instead of an unshielded twisted wire [1]. But first I will see if using an active_low approach changes anything.

[1] https://www.berrybase.de/kupferschaltdraht-isoliert-oe2x0-5mm-rot-weiss-10m

@belegdol
Copy link

belegdol commented Jan 9, 2024

Turns out there is indeed value in shorting to ground as opposed to 3V3. I have moved to GPIO7 to benefit from the default pull-up state and the spurious signals from the lamp went away (turned on at 15:17:30 and off at 15:17:41), even with the high_wait reduced back to 250 ms:

         "protocol" : "s0",
         "enabled" : true,
         "gpio" : 1007, 
         "configureGPIO" : true,
         "debounce_delay" : 30,
         "high_wait" : 250,
         "channels": [{
                 "uuid" : "918f7ff0-ae33-11ee-9c97-b19e2a89dc6a",
                 "middleware" : "http://odroidxu4.local:8080",
                 "identifier" : "Impulse"
          }]
[Jan 09 15:17:30][S0]   [456.815289937] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.152245495] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.152282494] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.152291493] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522284895] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522326894] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522335893] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522348893] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522356893] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522410891] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522421891] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522456890] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522493889] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522503888] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522526888] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522540887] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522551887] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522576886] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522589886] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.522626885] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.523645856] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.609354401] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794155107] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794172106] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794177106] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794210105] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794236104] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794243104] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794268104] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794291103] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794306102] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794320102] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794332102] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794347101] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794360101] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794373101] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794390100] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794405100] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:32][S0]   [458.794525096] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922080453] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922102453] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922135452] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922156451] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922167451] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922177451] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922203450] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922218449] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922230449] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922248449] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922263448] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922279448] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922296447] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922312447] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922327446] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922343446] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [458.922604438] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.39626102] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.40787069] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.40930065] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.40951064] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.40982063] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.41012063] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.41041062] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.41072061] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.41107060] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.50286798] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.50293798] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.50323797] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.50368796] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.202175468] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.202205467] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.202240466] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.202247466] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.202260465] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.232962590] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.232985589] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233020588] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233037588] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233045588] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233053587] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233072587] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233081587] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233096586] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233105586] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233125585] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233136585] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233145585] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233158584] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233167584] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233193583] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.233484575] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472156770] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472182770] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472190769] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472224768] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472232768] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472249768] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472258767] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472275767] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472284767] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472299766] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472308766] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472335765] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472345765] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472368764] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472379764] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472390764] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.472801752] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513113603] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513148602] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513157601] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513164601] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513215600] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513222600] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513246599] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513256599] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513278598] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513296597] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513309597] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513338596] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513373595] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513401595] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513416594] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513431594] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.513885581] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:33][S0]   [459.520310398] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:34][S0]   [460.353573709] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:34][S0]   [460.353607708] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:34][S0]   [460.353677706] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:34][S0]   [460.353677706] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:41][S0]   [466.950339290] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0
[Jan 09 15:17:41][S0]   [466.971302714] GPIO event 2 (1=rising edge, 2=falling edge) in current state 0

@belegdol
Copy link

With the new approach, the counter seems really stable:
gas
The only strange thing are the dips around 10:30 and 12:45, but there is nothing suspicious in the log around these times. Other than that, there is not a single spurious peak. Thanks a lot for your PR!

@r00t-
Copy link
Contributor

r00t- commented Jan 10, 2024

this discussion is full of noise,
i would suggest to avoid mixing user-suport with code discussions.

OR is there any indication that the stray impulses issues are related to the code?
due to the newly intoduced software-debounce code?
https://github.com/volkszaehler/vzlogger/pull/525/files#diff-69dc855d09e6cdb27122deab555b11abc165758089cd8dc8b7fe1da3fbd6ccf7R883

@belegdol: can you compare the performance to the old implementation?

@belegdol
Copy link

@r00t- fair enough, apologies.
With the vzlogger default implementation and sensor between GPIO24 and 3V3 i was getting spurious peaks, which is why I tried the code from this PR (and also following recommendation from @trabant-asb).
The performance of the new implementation is definitely better with the sensor between GPIO7 and GND. Between GPIO24 and 3V3 it was the same or worse:

  • default is from start till the gap on 9th January
  • GPIOD 3V3 is from the gap till ~15:30 on 9th January
  • GPIOD GND is from the drop ~15:30 on 9th January until now
    gas_all

@wrichter
Copy link
Author

To me it sound like the main improvement was due to the change in shielding (GPIO7 and grounding) and not due to the performance of the code. That being said, the code wasn't intended to be better performing than the SysFS interface, its main claim to merit is that SysFS GPIO is obsolete while GPIOD is the more future-proof interface. It just happens to implement some of the suggestions to filter out noise that have been raised in the past (like a HIGH_WAIT state) that do seem to work for some people (e.g. @trabant-asb ).

@belegdol
Copy link

belegdol commented Jan 10, 2024

Just to clarify, there is no shielding. The only changes are a different GPIO pin (because I have a twin connector so I need 3V3 or GND in the second GPIO row) and moving from pull-down/3V3 to pull-up/GND logic. The circuit is as simple as it gets otherwise: crimp connector on the Pi, the referenced unshielded twisted wire towards the sensor. No capacitors or shielding are present.

@belegdol
Copy link

Almost two weeks later I am happy to report that there are still no weird spikes from the lamp and the gas consumption is being monitored properly.

@belegdol
Copy link

belegdol commented Mar 1, 2024

Still no issues despite direct connection to GPIO and close proximity to an ancient CCFL tube.

@belegdol
Copy link

belegdol commented May 5, 2024

Still not an impulse too few or too many. Rock solid.

@r00t-
Copy link
Contributor

r00t- commented May 8, 2024

thanks for the reminder.
i'm somewhat hesitant to just merge this, as it's a complex change that affects a very large part of our userbase.
i'll instal this on my personal instance asap for some more confirmation.

@wrichter
Copy link
Author

wrichter commented May 8, 2024

hey @r00t- I agree that this is not ready for mass inclusion at this stage. There were some comments in this thread regarding the code, e.g.:

gpiochip is hardcoded to 0 and the appraoch to use gpioline > 1000 to configure the plugin is hacky

default active high/low configuration is the inverse from the sysfs GPIO approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants