openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.69k forks source link

[netatmo] Results of HTTP calls are shown on the console #4919

Closed hakan42 closed 7 years ago

hakan42 commented 7 years ago

Expected Behavior

Debug traces should go to either to the designated log or be suppressed

Current Behavior

The HTTP requests and responses are dumped on the system console:

Dec 21 15:58:42 pitaya start-service.sh[12940]: Access-Control-Allow-Origin: *
Dec 21 15:58:42 pitaya start-service.sh[12940]: OkHttp-Selected-Protocol: http/1.1
Dec 21 15:58:42 pitaya start-service.sh[12940]: OkHttp-Sent-Millis: 1482335922633
Dec 21 15:58:42 pitaya start-service.sh[12940]: OkHttp-Received-Millis: 1482335922834
Dec 21 15:58:42 pitaya start-service.sh[12940]: {"body":{"devices":[{"_id":"70:ee:50:17:e0:9c","cipher_id":...

Possible Solution

Suppress the aforementioned if not explicitly enabled 😈

Steps to Reproduce (for bugs)

  1. Set up a clean OH2 installation
  2. Add a netatmo bridge
  3. See HTTP dumps on console

Context

Your Environment

9037568 commented 7 years ago

That does not appear to be output from Netatmo or OH.

hakan42 commented 7 years ago

Actually, they are. I forgot to paste the URLs:

Dec 22 12:20:11 pitaya start-service.sh[729]: {"body":{"devices":[{"_id":"XX:XX:XX:XX:XX:XX","cipher_id":"enc:16:XXXXX
Dec 22 12:20:11 pitaya start-service.sh[729]: ,"battery_vp":5210,"battery_percent":61,"rf_status":55,"firmware":17},{"_id":"XX:XX:XX:XX:XX:XX","type":"NAModul
Dec 22 12:20:11 pitaya start-service.sh[729]: 797132,"wifi_status":42}],"user":{"mail":"hakan@tandogan.com","administrative":{"country":"DE","reg_locale":"en-
Dec 22 12:20:11 pitaya start-service.sh[729]: <--- END HTTP (4357-byte body)
Dec 22 12:20:11 pitaya start-service.sh[729]: ---> HTTP GET https://api.netatmo.net/api/getstationsdata?device_id=XXXXXXXXXXX
Dec 22 12:20:11 pitaya start-service.sh[729]: ---> END HTTP (no body)
Dec 22 12:20:12 pitaya start-service.sh[729]: <--- HTTP 200 https://api.netatmo.net/api/getstationsdata?device_id=XXXXXXX (154ms)

You can see from the requested URLs as well from the content (which I modified slightly to suppress my own credentials) that the request go to api.netatmo.net.

If an exception is thrown, the stack trace starts with

Dec 13 13:12:51 pitaya start-service.sh[4347]: at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:175)
....
Dec 13 13:12:52 pitaya start-service.sh[4347]: at org.openhab.binding.netatmo.handler.NetatmoBridgeHandler.getStationsDataBody(NetatmoBridgeHandler.java:138)
Dec 13 13:12:52 pitaya start-service.sh[4347]: at org.openhab.binding.netatmo.handler.station.NAMainHandler.updateReadings(NAMainHandler.java:41)
Dec 13 13:12:52 pitaya start-service.sh[4347]: at org.openhab.binding.netatmo.handler.NetatmoDeviceHandler.updateChannels(NetatmoDeviceHandler.java:92)
Dec 13 13:12:52 pitaya start-service.sh[4347]: at org.openhab.binding.netatmo.handler.NetatmoDeviceHandler$1.run(NetatmoDeviceHandler.java:64)

Dec 13 13:12:52 pitaya start-service.sh[4347]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

and goes straight through okhttp to make the HTTP calls.

watou commented 7 years ago

That library is full of System.out.println calls. 😦

hakan42 commented 7 years ago

Kill it. Kill it with fire! Kill it with nuclear fire from orbit! 😈

9037568 commented 7 years ago

So the possible fixes are:

hakan42 commented 7 years ago

O.k., back to serious discussion, I thought that our chosen http client was the one that comes with Jetty.

One reason I could imagine for chosing okhttp would be that it is used for OAUTH setup. Do we have any alternative in the ESH core for this? Also, should discussion be moved to community.openhab.org ?

robnielsen commented 7 years ago

BTW, this is the OH2 Netatmo binding, not the OH 1 Netatmo binding. Shouldn't the defect created at https://github.com/openhab/openhab2-addons/issues?

hakan42 commented 7 years ago

Ah, damn, opened the ticket in the wrong repo again :(

I will create a new one over there.