[Solved] NETATAMO Refresh token

Hi
I am trying to get netatmo binding to work, but I am unsure how the refresh token works, or what it is at all. My openhablog shows this error:

11:59:11.674 [DEBUG] [.o.b.n.internal.NetatmoBinding:99   ] - Querying Netatmo API
11:59:11.677 [DEBUG] [.o.b.n.internal.NetatmoBinding:606  ] - Refreshing access token.
11:59:11.681 [DEBUG] [.o.b.n.internal.NetatmoBinding:610  ] - Request: RefreshTokenRequest[clientId=568a9d9e67XXXXXXXXXXXX,clientSecret=f56zkY7Yx9dG4avMbXXXXXXX,refreshToken=5689941269f7405b8cf3b889|8372699d6457428a07c1c58221ced8ee]
11:59:12.249 [ERROR] [g.openhab.io.net.http.HttpUtil:233  ] - Fatal transport error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
11:59:12.373 [ERROR] [.service.AbstractActiveService:175  ] - Error while executing background thread Netatmo Refresh Service
org.openhab.binding.netatmo.internal.NetatmoException: Could not refresh access token!

Did the curl request fail and i need to get a new token or what is the problem?

Java must have been upgraded on your system. You need to re-add the StartCom security certificate see https://github.com/openhab/openhab/wiki/Netatmo-Binding#missing-certificate-authority.

tried:)

https://api.netatmo.net/ is down it seems like because I just get : {“error”:{“code”:404,“message”:“method not found”}} when i open it in chrome.

Can you confirm this?

Cheers

I just tried https://api.netatmo.net/oauth2/token with chrome and I got:

{"error":"invalid_request"}

Which would be expected since I didn’t pass in any arguments with the request. You might want to turn on debug logging by adding the following to logback.xml:

<appender name="NETATMOFILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>logs/netatmo.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logs/netatmo-%d{yyyy-ww}.log.zip</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{30}[:%line]- %msg%n%ex{5}</pattern> </encoder> </appender> <logger name="org.openhab.binding.netatmo" level="DEBUG" additivity="false"> <appender-ref ref="NETATMOFILE" />

It will show the calls that the binding is making to the Netatmo api’s.

I am trying to do this:

$ sudo keytool -import -keystore $JAVA_HOME/jre/lib/security/cacerts -alias StartCom-Root-CA -file api.netatmo.net.crt
Enter keystore password:
Re-enter new password:
keytool error: java.io.FileNotFoundException: api.netatmo.net.crt (No such file or directory)

Sorry, that I am newbie to linux :smile:

No problems, did you download the certificate before trying to import it? Try:

wget https://www.startssl.com/certs/ca.pem $JAVA_HOME/bin/keytool -import -keystore $JAVA_HOME/jre/lib/security/cacerts -alias StartCom-Root-CA -file ca.pem

Afterwards, you’ll need to restart openhab.

Seems that my internet is down now:

wget https://www.startssl.com/certs/ca.pem
--2016-01-10 13:31:52--  https://www.startssl.com/certs/ca.pem
Resolving www.startssl.com (www.startssl.com)... failed: Name or service not known.
wget: unable to resolve host address `www.startssl.com'

Will try again tonight.

I tried again but I get all these errors:
Here is what i got when i tried to install the certificate

Trust this certificate? [no]:  yes
Certificate was added to keystore
keytool error: java.io.FileNotFoundException: /jre/lib/security/cacerts (No such file or directory)

and this is what openhab says when rebooting:

22:44:31.522 [DEBUG] [.o.b.n.internal.NetatmoBinding:99   ] - Querying Netatmo API
22:44:31.523 [DEBUG] [.o.b.n.internal.NetatmoBinding:606  ] - Refreshing access token.
22:44:31.525 [DEBUG] [.o.b.n.internal.NetatmoBinding:610  ] - Request: RefreshTokenRequest[clientId=568a9d9e67e482c411f60107,clientSecret=f56zkY7Yx9dG4avMbdptdK2p53THInBqGL,refreshToken=5689941269f7405b8cf3b8898372699d6457428a07c1c58221ced8ee]
22:44:31.745 [ERROR] [g.openhab.io.net.http.HttpUtil:233  ] - Fatal transport error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
22:44:31.774 [ERROR] [.service.AbstractActiveService:175  ] - Error while executing background thread Netatmo Refresh Service
org.openhab.binding.netatmo.internal.NetatmoException: Could not refresh access token!
        at org.openhab.binding.netatmo.internal.messages.AbstractRequest.newException(AbstractRequest.java:50) ~[na:na]
        at org.openhab.binding.netatmo.internal.messages.RefreshTokenRequest.execute(RefreshTokenRequest.java:63) ~[na:na]
        at org.openhab.binding.netatmo.internal.NetatmoBinding$OAuthCredentials.refreshAccessToken(NetatmoBinding.java:612) ~[na:na]
        at org.openhab.binding.netatmo.internal.NetatmoBinding.execute(NetatmoBinding.java:105) ~[na:na]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) ~[na:na]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) ~[na:na]
Caused by: java.lang.NullPointerException: null
        at java.io.StringReader.<init>(StringReader.java:50) ~[na:1.8.0]
        at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:636) ~[na:na]
        at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1854) ~[na:na]
        at org.openhab.binding.netatmo.internal.messages.RefreshTokenRequest.execute(RefreshTokenRequest.java:58) ~[na:na]
        ... 4 common frames omitted

It appears you didn’t set the JAVA_HOME environment variable. Run the command:
update-alternatives --list java

This should output something similar to:
/usr/lib/jvm/java-8-oracle/jre/bin/java

Use everything before /jre/… to set the JAVA_HOME environment variable:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle

After you set the environment variable, try:

ls -l $JAVA_HOME/jre/lib/security/cacerts

If it’s set correctly then you should see something similar to:
-rw-r--r-- 1 root root 101992 Nov 4 10:54 /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts

Now try and rerun the keytool command. If you didn’t get errors, you should be good to go.

.[quote=“ranielsen, post:9, topic:5781”]
It appears you didn’t set the JAVA_HOME environment variable. Run the command:
[/quote]

Hi, I added your tips to the wiki, so now I have JAVA_HOME variable set. Im a newbie to linux thats why.

So what does the refresh token mean/do? Do I need to refresh it with the curl request? Because I still can not get the binding to work.

Thanks for the hint so far:)

Did you follow the instructions at https://github.com/openhab/openhab/wiki/Netatmo-Binding#pre-setup? You should only need to get the refresh token one time then add it to the configuration file. What kind of problems are you having now? Also if you haven’t already upgraded, can you upgrade to openhab 1.8?

Yes I did. I tried on two different rpi, hence two differnt curl call, and two different refresh tokens. But I will upgrade tonight:

sudo apt-get update
sudo apt-get upgrade

So after that i will request new refresh tokens and give it a new try. I am sure I will get it to work.
I just need to make sure that my flat mate is not home, due to rebooting and then the entire flat gets dark:)

Still can not get it to work:(

The MAC address in the https://my.netatmo.com/app/station shows : 70:ee:50:1a:fc:b6, but this does not show up in router dhcp list. I think this might be the problem.

From my router I find this in the sys log, what does that mean?
2 23974:DHCPS: 1:0x70ee501afcb6, 192.168.1.72, ACK in request

I tried giving it static ip but its still not working. Any idea why the MAC address does not show up in my router?

Works now! How can i set it solved? Thanks for the help

You can edit your header by clicking the little pencil icon on the right hand side of that header, than just add [Solved] to the beginning.

Thx, I thought there were more to it so u could track which is still open etc…

Nope … only on github :grinning: