[OH2] mPower 1.9.x Binding Problems

Hi Community,

On openHAB 2, Snapshot #693, I am using org.openhab.binding.mpower-1.9.0-SNAPSHOT.jar (copied over to /usr/share/openhab2/addons/) dated June 2016 as it was build by @chano (thanx by the way) and made available in this post:

It mainly works ok with my 4 units of Ubiquiti mfi mPower (EU) strips (2 units of 3 ports and 2 units of 6 ports).

In some first start cases (when I restart OH2 due to a snapshot upgrade or system reboot), the mPower Binding throws an exception (ConcurrentModificationException) and the binding gets shut down…

2017-01-04 20:13:24.273 [INFO ] [nternal.connector.MpowerSSHConnector] - connected to mP602 on host 172.16.13.2
2017-01-04 20:13:26.445 [INFO ] [nternal.connector.MpowerSSHConnector] - connected to mP304 on host 172.16.13.4
2017-01-04 20:13:28.824 [INFO ] [nternal.connector.MpowerSSHConnector] - connected to mP601 on host 172.16.13.1
2017-01-04 20:13:30.875 [INFO ] [nternal.connector.MpowerSSHConnector] - connected to mP303 on host 172.16.13.3
2017-01-04 20:13:30.876 [INFO ] [b.core.service.AbstractActiveService] - Ubiquiti mPower Binding has been started
2017-01-04 20:13:30.877 [INFO ] [nternal.connector.MpowerSSHConnector] - Session closed to 172.16.13.2
2017-01-04 20:13:30.880 [INFO ] [inding.mpower.internal.MpowerBinding] - Connector mP602 is down. Trying to restart
2017-01-04 20:13:30.881 [INFO ] [nternal.connector.MpowerSSHConnector] - Session closed to 172.16.13.4
2017-01-04 20:13:30.882 [INFO ] [nternal.connector.MpowerSSHConnector] - Session closed to 172.16.13.1
2017-01-04 20:13:30.882 [INFO ] [nternal.connector.MpowerSSHConnector] - Session closed to 172.16.13.3
2017-01-04 20:13:32.134 [INFO ] [nternal.connector.MpowerSSHConnector] - connected to mP602 on host 172.16.13.2
2017-01-04 20:13:32.135 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread Ubiquiti mPower Binding
java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437)[:1.8.0_111]
	at java.util.HashMap$ValueIterator.next(HashMap.java:1466)[:1.8.0_111]
	at org.openhab.binding.mpower.internal.MpowerBinding.execute(MpowerBinding.java:293)[9:org.openhab.binding.mpower:1.9.0.201606081237]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[176:org.openhab.core.compat1x:2.0.0.201701032212]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)[176:org.openhab.core.compat1x:2.0.0.201701032212]
2017-01-04 20:14:32.136 [INFO ] [b.core.service.AbstractActiveService] - Ubiquiti mPower Binding has been shut down

To solve this, I edit the config file (/etc/openhab2/services/mpower.cfg) and modify one of the refresh intervals, triggering a reconnection that usually succeeds and then the binding comes up and it works (and stays stable for days, reading the values from the devices).

Does anyone have any idea what could be the root cause of this (ConcurrentModificationException) problem?

My items config looks like (only 1 example is provided for 1 outlet of 1 mPower strip). There is a total of 72 items defined that use the mpower binding

Switch  mP6_01_01       "LAN Switch 24"                 (gmPower)               {mpower="mP601:1:switch"}
Number  mP6_01_01_V     "LAN Switch Voltage [%d V]"     (gmPower,gInflux)       {mpower="mP601:1:voltage"}
Number  mP6_01_01_E     "LAN Switch Energy [%d Wh]"     (gmPower,gInflux)       {mpower="mP601:1:energy"}
Number  mP6_01_01_P     "LAN Switch Power [%.1f W]"     (gmPower,gInflux)       {mpower="mP601:1:power"}

My /etc/openhab2/services/mpower.cfg is:

refresh=60000
mP601.host=172.16.13.1
mP601.user=<username>
mP601.password=<password>
mP601.refresh=900000
mP602.host=172.16.13.2
mP602.user=<username>
mP602.password=<password>
mP602.refresh=900000
mP303.host=172.16.13.3
mP303.user=<username>
mP303.password=<password>
mP303.refresh=900000
mP304.host=172.16.13.4
mP304.user=<username>
mP304.password=<password>
mP304.refresh=900000

BR,
Dim
Ps: Any chance that any developer will pickup the existing work and produce a 2.x mPower Binding for OH2? :slight_smile: :slight_smile: :wink:

Any chance that any developer will pickup the existing work and produce a 2.x mPower Binding for OH2?

Yes. I’m the developer of the 1.x binding. And I feel soon or later the time will come that I need to switch to OH2. :slight_smile: Latest by then I need to spend some time rewriting the binding for OH2.

Regarding the ConcurrentModificationException its probably just a stupid coding error. (Coding is actually not my core competency :grin:)

1 Like

:slight_smile: Great work by the way!

The binding works fine in OH2 (just this minor problem that I can work around)

If you do update this mpower binding for OH2, I will send you a new power strip :slight_smile:

@magcode Do you have any interest in contributing the binding code via a pull request to the openhab/openhab repo?

You might be able to workaround the ConcurrentModificationException by using a ConcurrentHashMap. The thread that runs your execute method is probably manipulating the HashMap while some other thread is trying to do so as well.

Thanks John. Yes sure. However

  • I did not really maintain my fork https://github.com/magcode/openhab
  • the version 1.9 of this binding has not been created by myself
  • I had trouble getting my “latest” 1.7.0-SNAPSHOT to work with OH2, some bundles dependencies were missing.
  • I guess someone compiled 1.9.0 with some changes I do not know about

What I want to say: maybe I better start from scratch with a OH2 version of this binding. Including the ConcurrentModificationException fix.

Excellent idea! It sounds like there will be users very excited to have it.

@Dim
I take you by your word! :grinning:
I made my first steps yesterday into OH2 development. I saw that OH2 provides some OOTB discovery features, which I would love to integrate into the OH2 version of the mPower binding.

Btw: I while ago I experimented with a pure MQTT based integration. https://github.com/magcode/mpower-mqtt
It actually works (mPower can run a “native” MQTT client). The only (and major) downside is that it is much too slow. It takes up to 2 seconds for switch commands. Not compareable to the SSH based solution.

1 Like

work has started!

:sunglasses:


2 Likes

Excellent! :slight_smile:

A new 6 port EU mPower strip is waiting for you :slight_smile: (when you publish the 2.x binding)

first data can be read… stay tuned

1 Like

a little update:

I have working

  • SSH connection
  • bridge/mpower discovery (inbox)
  • socket discovery (inbox)
  • reading
  • switching
  • sync switch state when mpower socket has been switched by native mpower app
  • as least as possible channel updates by comparing new and old values (from old binding) and rounding

missing:

  • connection watchdog
  • clean removal of things
  • power factor reading
  • documentation
  • more testing with multiple mpower strips
  • testing with versions other than P3E and P6E

Will most likely post a first beta on weekend.
Very smooth so far. It took a while to understand the new ESH ideas. But everything makes sense now.

2 Likes

here you go New OH2 Ubiquiti Networks mPower binding

1 Like