hardillb / TRADFRI2MQTT

MQTT Bridge for IKEA TRÅDFRI Light Gateway
https://www.hardill.me.uk/wordpress/2017/04/06/fist-pass-tradfri-mqtt-bridge/
Apache License 2.0
81 stars 12 forks source link

Null Pointer response in discover() #4

Closed r41d closed 7 years ago

r41d commented 7 years ago

This line occurs twice in the discover() method:

CoapResponse response = client.get();

The first one (for the devices) always gives me Null Pointers on my Raspberry Pi 2. It always works on my Laptop, where I have my IDE for debugging... Communication with the gateway from the Pi also works (tested with coap-client from libcoap). Documentation says that get() "... blocks until the response is available". I don't get why this error only occurs only on my Pi 2, will also test on my Pi 3 now...

r41d commented 7 years ago

OK, on my Pi 3, this problem does not occur, very strange. On a side note I like to point out that installation of maven in Raspbian causes a JDK7 to get installed and prioritized higher than your out-of-the-box JDK8, then you will get errors because the TRADFRI2MQTT pom.xml wants a Java 1.8 target. Fix it with:

sudo update-alternatives --config java

found here: http://www.savagehomeautomation.com/projects/raspberry-pi-change-default-java-virtual-machine-jvm.html

hardillb commented 7 years ago

I'm seeing this as well on a pi, both Oracle and OpenJDK 8. I'll tweak the build to generate 7.0 compatible bytecode so it can run on both

hardillb commented 7 years ago

It's running fine on OpenJDK 7 on my Pi 2. I'll check in the pom.xml changes (plus the test for colour temp as my bulb [TRADFRI bulb E27 opal 1000lm] isn't reporting that value)

r41d commented 7 years ago

This commit didn't change the line that gives me Null Pointers. I only have full white spectrum bulbs, I guess your commit was to fix issues with the bulbs that only have one temperature. Currently, it is in line 182 in Main.java, this is where I get a NullPointerException, because CoapResponse response = client.get(); is null. Changing the Java version didn't change this issue.

hardillb commented 7 years ago

Did you rebuild with the Java 7.0 bytecode and run it with OpenJDK 7?

My best guess is that this is a JIT issue on ARM so you could try running with the -Xint command line arg.

It will be REALLY slow but it will confirm if it's the JIT

hardillb commented 7 years ago

Actually it's running for me with Oracle Java 7.0 it's working with, but I've just tried the 8.0 and -Xint and it's still throwing a NPE

hardillb commented 7 years ago

OK, fixed it with Java 8 as well. The doc is not great, but client.get() can return null when a response times out. The timeout defaults to 2 seconds, you can increase it by editing the Californium.properties file.

Edit the ACK_TIMEOUT value. 4000 seams to work for me

ACK_TIMEOUT=4000
r41d commented 7 years ago

That helps indeed, thanks a lot