Modernized MCP23017 Binding for OpenHAB 4.3 - Request for Feedback and Issue Assistance

Hi everyone,

I’ve been working on modernizing the MCP23017 binding for OpenHAB 4.3 to resolve compatibility issues I encountered on a Raspberry Pi 5. Despite my efforts, I couldn’t get the existing implementation to work, even after patching the Pi4J library.

To address this, I’ve rewritten the binding to replace the Pi4J dependency, which is no longer maintained, with a new implementation that directly communicates with I2C via Libc. This change should make the binding functional across all Linux environments. The updated code is available on GitHub:
GitHub Repository - MCP23017 Binding for OpenHAB 4.3

Key Changes

  1. Removal of Pi4J Dependency
  • Pi4J has been replaced with a direct Libc-based I2C communication implementation.
  1. Configuration Compatibility
  • The binding remains configuration-compatible. The technical implementation has been updated, but OpenHAB configurations, items, things, and rules should not require changes.
  1. Behavioral Improvements
  • If the I2C communication is interrupted, the thing status changes to OFFLINE and returns to ONLINE once communication is restored.
  • Registers of the MCP23017 are checked regularly (every ~5 seconds). Any deviations from the desired values are automatically corrected.

Open Issues

  1. Logging
  • Currently, everything is logged at the ERROR level. This will be adjusted in the final version.
  1. Startup Issue
  • When starting OpenHAB, items do not automatically bind to the channels of the MCP23017 thing. I need to manually remove and re-add the items to establish the connection.
  • If anyone has insights or suggestions on what might cause this issue, I’d appreciate your guidance!

Next Steps

Once the open points are resolved, I’d be happy to submit a pull request to contribute these changes back to the OpenHAB project.

I’d greatly appreciate any feedback on the implementation, as well as any suggestions for addressing the startup issue. Thanks in advance for your help!

Best regards,
Igor

If this is ready for general testing, you can create a post in the marketplace and then end users can install the add-on from the Add-on Store in MainUI instead of needing to download the jar file and dropping it into the addons folder.

Note that OH 5 is under development so be sure to look out for changes needed there as well.

I’d say the current state is “working for me”! :blush: That said, broader testing would definitely be a good idea. Can I publish it to the marketplace as well, even though it’s essentially a replacement for an existing add-on? Or would it be better to rename it for testing purposes?

I guess if it depends on whether this is intended to be a parallel implementation or if it’s intended to replace the existing add-on. If it’s intended to be parallel, the marketplace isn’t the right place for it. We do not want the marketplace to compete with the core add-ons nor do we want to add confusion. If it’s intended to be a replacement for the existing one, then posting it to the marketplace for testing is one of the reasons the marketplace was created.

Like this? MCP23017 - Without Pi4j

that looks like it could work. Did you test that it installs?

Yes, checked in a fresh installation. Works :slight_smile: