Custom Bundle Works on Eclipse Environment BUT NOT on Distribution Runtime

Hi,

I have setup a scheduler to execute some commands, see below codes. updateDeviceBridgeState() is called as per the PARAMETER_REFRESH_INTERVAL on the Eclipse Debug Environment only. But, if I export the bundle (project -> export-> plug-in-development->Deployable plug-ins and fragments) into a single jar file and copy it to “\addons” folder of openHab2 runtime root folder on Raspberry Pi, the scheduler doesn’t seem to work and updateDeviceBridgeState() never get called at all though the bundle is loaded properly (at least no error message shown if i run start_debug.sh). Can someone enlighten me how to troubleshoot this? Could this be some dependencies plugins that exist on Eclipse environment which do not include in the runtime distribution package? Thanks,

some debug output from Eclipse:

2015-08-26 00:12:01 [DEBUG] [.c.thing.internal.ThingManager:82 ] - Thing handler for thing 'test:switchThing:myHome:myDevice2:mySwitch0' added.
2015-08-26 00:12:01 [INFO ] [ome.event.ThingStatusInfoEvent:43 ] - test:deviceBridge:myHome:myDevice2' updated: ONLINE
2015-08-26 00:12:01 [INFO ] [marthome.event.ThingAddedEvent:43 ] - Thing 'test:switchThing:myHome:myDevice2:mySwitch0' has been added.
2015-08-26 00:12:01 [DEBUG] [.c.thing.internal.ThingManager:236 ] - Assigning handler for thing 'test:switchThing:myHome:myDevice2:mySwitch0'.
2015-08-26 00:12:01 [INFO ] [ome.event.ThingStatusInfoEvent:43 ] - test:switchThing:myHome:myDevice2:mySwitch0' updated: INITIALIZING
2015-08-26 00:12:01 [INFO ] [ome.event.ThingStatusInfoEvent:43 ] - test:switchThing:myHome:myDevice2:mySwitch0' updated: ONLINE
2015-08-26 00:12:01 [INFO ] [.e.s.m.c.i.ModelRepositoryImpl:86 ] - Loading model 'default.rules'
2015-08-26 00:12:02 [INFO ] [.e.s.m.c.i.ModelRepositoryImpl:86 ] - Loading model 'test.items'
2015-08-26 00:12:03 [DEBUG] [.e.s.m.i.i.GenericItemProvider:151 ] - Processing binding configs for items from model 'test.items'
2015-08-26 00:12:03 [DEBUG] [.e.s.m.i.i.GenericItemProvider:130 ] - Read items from model 'test.items'
2015-08-26 00:12:03 [INFO ] [.e.s.m.c.i.ModelRepositoryImpl:86 ] - Loading model 'default.items'
2015-08-26 00:12:03 [DEBUG] [.e.s.m.i.i.GenericItemProvider:151 ] - Processing binding configs for items from model 'default.items'
2015-08-26 00:12:03 [DEBUG] [.e.s.m.i.i.GenericItemProvider:130 ] - Read items from model 'test.items'
2015-08-26 00:12:03 [DEBUG] [.e.s.m.i.i.GenericItemProvider:130 ] - Read items from model 'default.items'
2015-08-26 00:12:06 [INFO ] [smarthome.event.ItemStateEvent:43 ] - test_mainBridge_myHome_online updated to ON
.....
2015-08-26 00:28:33 [INFO ] [smarthome.event.ItemStateEvent:43 ] - MyMessage updated to Hello
2015-08-26 00:28:33 [INFO ] [smarthome.event.ItemStateEvent:43 ] - test_mainBridge_myHome_online updated to ON
2015-08-26 00:28:33 [INFO ] [smarthome.event.ItemStateEvent:43 ] - My_LastUpdate updated to 2015-08-25T16:28:34
2015-08-26 00:28:34 [INFO ] [smarthome.event.ItemStateEvent:43 ] - My_LastUpdate1 updated to 2015-08-25T16:28:33
2015-08-26 00:28:34 [INFO ] [smarthome.event.ItemStateEvent:43 ] - My_Link_Strength updated to 34
2015-08-26 00:28:34 [INFO ] [smarthome.event.ItemStateEvent:43 ] - My_Link_Quality1 updated to 109
2015-08-26 00:28:38 [DEBUG] [.s.u.c.i.servlet.WebAppServlet:111 ] - Servlet request received!

debug our from Raspberry Runtime:

2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:71 ] - Thing handler for thing 'test:switchThing:myHome:myDevice1:mySwitch1' added.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:191 ] - Assigning handler for thing 'test:switchThing:myHome:myDevice1:mySwitch1'.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:278 ] - Thing 'test:deviceBridge:myHome:myDevice2' is tracked by ThingManager.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:381 ] - Creating handler for thing 'test:deviceBridge:myHome:myDevice2'.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:140 ] - Status of test:deviceBridge:myHome:myDevice2 changed to ONLINE
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:71 ] - Thing handler for thing 'test:deviceBridge:myHome:myDevice2' added.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:191 ] - Assigning handler for thing 'test:deviceBridge:myHome:myDevice2'.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:278 ] - Thing 'test:switchThing:myHome:myDevice2:mySwitch0' is tracked by ThingManager.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:381 ] - Creating handler for thing 'test:switchThing:myHome:myDevice2:mySwitch0'.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:140 ] - Status of test:switchThing:myHome:myDevice2:mySwitch0 changed to ONLINE
2015-08-26 00:33:56 [DEBUG] [b.t.h.TalentSwitchThingHandler:52 ] - Thing Handler for mySwitch0 started
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:71 ] - Thing handler for thing 'test:switchThing:myHome:myDevice2:mySwitch0' added.
2015-08-26 00:33:56 [DEBUG] [.c.thing.internal.ThingManager:191 ] - Assigning handler for thing 'test:switchThing:myHome:myDevice2:mySwitch0'.
2015-08-26 00:33:56 [INFO ] [.e.s.m.c.i.ModelRepositoryImpl:86 ] - Loading model 'default.items'
2015-08-26 00:33:57 [DEBUG] [.e.s.m.i.i.GenericItemProvider:151 ] - Processing binding configs for items from model 'default.items'
2015-08-26 00:33:58 [DEBUG] [.e.s.m.i.i.GenericItemProvider:130 ] - Read items from model 'default.items'

handler code:

private void startAutomaticRefresh() {
Configuration config = this.getConfig();

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            try {
                updateDeviceBridgeState();
            } catch (Exception e) {
                updateStatus(ThingStatus.OFFLINE);
            }
        }
    };
    if (refreshJob != null) {
        if (!refreshJob.isDone()) {
            refreshJob.cancel(false);
        }
    }

    refreshJob = scheduler.scheduleAtFixedRate(runnable, 0,
            Integer.parseInt(config.get(PARAMETER_REFRESH_INTERVAL).toString()), TimeUnit.SECONDS);

Did you try to remotely debug if the refreshJob gets created and scheduled as expected?
You could try to compare the code with e.g. the Yahoo Weather binding as this is doing the same (afair). As this works as expected, this could give you a clue on what is different in your case.

Hi Kai,

I am trying to figure out how to get the remote debug work for OpenHabs :smile:

In the mean time, it seems that none of the things that associate to items work either. On Eclipse, when i switch on/off of an switch item from OpenHab client, the event is propagated to a specific channel on my custom bundle. But, it fails to work on distribution runtime, nothing is propagated after on/off.

Wild thought: could this be some Plugin Dependencies or libraries issue? On Eclipse i found this dependency which is not included in the distribution runtime’s “~/openhab/runtime/server/plugins”, as an example:

Dependency show on Eclipse:
~/openhab2-master/ws/.metadata/.plugins/org.eclipse.pde.core/.external_libraries/org.eclipse.smarthome.model.persistence_0.8.0.201507290807/lib/joda-time-2.3.jar

Hi Kai,

I got it to work. Apparently, it is due to Java version mismatched. Eclipse OS supports Java 8 and hence some libraries used in the bundle are meant for Java 8 whilst Raspberry Pi only supports up to Java 7.

I do not understand why the Java never complain this instead I have to use remote debug to trace it one by one.

Anyway, thanks for your advice of using remote debug as this is my 1st time use of eclipse. Cheers

Hi Felix,

I am glad you were able to solve it yourself, thanks for the info!

Cheers,
Kai

Hi All,

From the comments above, it looks like I have similar problem of version mismatch. But still I am unclear as to how close the versions have to be. (1) exactly same, (2) only major version numbers, (3) versions and ISA (i.e., 32-bit or 64-bit) , (4) JRE or JDK?

I compiled myProject (with my own components communicating through mqtt) on a Windows 7 64-bit machine with 64-bit JDK (with Eclipse), and then produced the three files (runtime, addon,myProject). I tried to run these on another Intel Windows 64-bit machine with (look like) 32-bit JRE installed. And it has the problem mentioned above (my added items don’t work).

What should I do to make it work?
Thanks,

John.

I executed start_debug.bat and see the following error occuring many many times.

2015-09-08 22:11:38 [INFO ] [.service.AbstractActiveService:169 ] - HTTP Refresh Service has been started
2015-09-08 22:11:38 [INFO ] [.service.AbstractActiveService:169 ] - HTTP Refresh Service has been started
2015-09-08 22:11:38 [WARN ] [java.util.prefs :-1 ] - Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(…) returned error code 5.
2015-09-08 22:11:38 [ERROR] [.service.AbstractActiveService:175 ] - Error while executing background thread HTTP Refresh Servicejava.lang.ClassCastException: org.openhab.binding.http.internal.HttpGenericBindingProvider cannot be cast to org.openhab.binding.http.HttpBindingProvider
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:135)
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156)
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)

In my original project, I moved around some folders from openhab2 to my workspace called ws3 because I wanted to test different projects by having each in its own workspace. Would this cause above problem?

Sorry that I am new to IoT.
Thanks,

John.

Ok, the above warning and errors were removed. I think that was due to version mismatch.

But I am still having problems of the bindings added are not working. for example, when starts, it reads my mqtt.cfg, and starts MQTT service. But after that it never actually binds mqtt. Iooks like it does not read(find) binding.mqtt at all.
Also openhab.binding.mqtt is not included in the distribution files.

Questions:
Is it because I moved around files between openhab2 and my workspace?

How can I make sure such bindings are included in the distribution maven outputs?
Thanks,

John.

Did you see MQTT and OH2 - not working - #5 by kgoderis? If you add all required bundles, it seems to work. Simply put stuff in the “addons” folder, there is no need trying to include them in the Maven build.

Thanks for reply; I will try more later, but in the mean time,
I realized that the mqtt binding has been accessed, but still not fully working.
When I execute on the development env, all of the following occur.

[.c.d.internal.ConfigDispatcher:222 ] - Processing config file ‘mqtt.cfg’
[.b.mqtt.internal.MqttActivator:34 ] - MQTT binding has been started.
[.io.transport.mqtt.MqttService:123 ] - Starting MQTT Service…
[m.internal.MqttEventBusBinding:61 ] - MQTT: Activating event bus binding.
[.io.transport.mqtt.MqttService:108 ] - MQTT Service initialization completed.
[o.i.t.m.i.MqttBrokerConnection:108 ] - No url defined for MQTT broker connection ‘mymosquitto’. Not starting.
[o.i.t.m.i.MqttBrokerConnection:114 ] - Starting MQTT broker connection ‘mqttbroker’
[o.i.t.m.i.MqttBrokerConnection:294 ] - Creating new client for ‘tcp://192.168.1.111:1883’ using id ‘.144**’ and file store ‘C:\Users****~1\AppData\Local\Temp/mqttbroker’

But when i run the distribution build on another machine, I only see the following with a different order.

[.b.mqtt.internal.MqttActivator:34 ] - MQTT binding has been started.
[.c.d.internal.ConfigDispatcher:222 ] - Processing config file ‘mqtt.cfg’
[.io.transport.mqtt.MqttService:118 ] - Starting MQTT Service…

Thanks for any help.

I finally gave up, until someone enlightens about it, as I don’t know Java and Eclipse at all.
Tried remote debugging, but no source, and dont know at which I should start, either.
To me, remote debugging is same as start_debug ^^
I did mess up folders for having different tests, but I dont think that is problem…

So, what I need now is how to port distribution build (with additional bindings) on another same type machine or another platform such as Raspberry or Edison.
Thanks,

Hi John,

Sorry, as I didn’t yet try MQTT myself on OH2, I cannot really help here - would need to analyze in depth how your setup looks like.

If you do not know Java and Eclipse at all, openHAB 2 is probably not the right thing for you to look at for the moment; better stick with openHAB 1, which is more stable and where there is more documentation and support available.

In theory, all it needs is copying the complete installation folder. If this doesn’t work, you probably have done some system specific configuration which you would need to find and fix.

Best regards,
Kai

Per your suggestion, I tried Openhab 1 thinking it should run as smooth as you sound, but it unfortunately did not work well, either. My openhab2 .cfg files were incompatible with openhab1. Also Designer was not properly displaying items, showing a frustrating message “Failed to create the part’s controls", which generated a hundred errors, which seems due to Java run-time incompatibility. Some suggested to use JRE 32-bit and others old version of JRE, but none worked for me, so I gave up openhab 1.

Thus, I decided to stick with openhab 2, and installed it on another machine, and made it almost identical (w.r.t. structure) to my first machine, and then share some folders for development (machine 1) and deployment (machine 2), which worked well for me.

I have MQTT and Ecobee binding working, along with Arduino, XBee, and nRF components. Thanks,

Speaking of MQTT, when is it going to be officially supported by OpenHab2
instead of using OH1 addon? If I want to develop a new addon by using MQTT
service and transport, can this be done on OH2 now? Thanks

@profjlee, Glad to hear that you were able to solve your problems yourself!

@lsafelix75, openHAB 2 already comes with the org.eclipse.smarthome.io.transport.mqtt bundle. If you want to develop addons, you can make use of that.