BobRak / OpenHAB-Smartthings

53 stars 54 forks source link

Understanding the mechanism #97

Closed wang70880 closed 3 years ago

wang70880 commented 3 years ago

Hi BobRak, first I want to thank you for providing such a useful binding. Recently I tried to read the source code and to understand the mechanism. Now I know that openHAB and SmartThings Hub are communicated via HTTP, however, there are some parts I can not figure it out:

I hope you can give me some hints and instructions. Again, thanks for your contribution!

BobRak commented 3 years ago

bridgeHandler.getSmartthingsIp(), bridgeHandler.getSmartthingsPort()) are the IP and port of the smartthings hub. When you configure the smartthings device handler you have to specify that IP and port for smartthings to listen on. It is on the device preferences screen.

OpenHAB includes an http servlet. Everything to openHAB goes to the openHAB IP and port. The SmartthingsServlet class tells openHAB the path that it wants to receive messages from. This line: httpService.registerServlet(PATH, this, servletParams, httpService.createDefaultHttpContext());

wang70880 commented 3 years ago

Thanks BobRak. Now I figured out how openHAB received messages from SmartThings Hub. However, how does openHABDeviceHandler in SmartThings receive message from openHAB? I looked at the installed function in OpenHabDeviceHandler.groovy, however, I don't think it is registered to listen to the SmartThings port and ip address.

def installed() {
    def ip = device.hub.getDataValue("localIP")
    def port = device.hub.getDataValue("localSrvPortTCP")
    log.debug "HTTP Bridge device handler installed. Listening on ${ip} + ":" + ${port}"
}

In my view, it only got the ip and port of the SmartThings Hub, and logged them. Why is the listening functionality implemented here?

BobRak commented 3 years ago

Why are you asking me all of these questions?

wang70880 commented 3 years ago

Why are you asking me all of these questions?

I just tried to understand how the openHAB-SmartThings binding works.