Closed wang70880 closed 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());
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?
Why are you asking me all of these questions?
Why are you asking me all of these questions?
I just tried to understand how the openHAB-SmartThings binding works.
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:
In SmartthingsHandlerFactory.sendDeviceCommand(), openHAB sends commands to SmartThings Hub via the following code. I guess such command is received and processed via parse() function in OpenHabDeviceHandler.groovy. But I am curious that why the http request sent to (bridgeHandler.getSmartthingsIp(), bridgeHandler.getSmartthingsPort()) will be assured to be received by the OpenHabDeviceHandler? I didn't see any port listening code in OpenHabDeviceHandler.groovy.
Also, why is the message sent from SmartThings Hub assured to be received by the openhab SmartThings Binding? I didn't see any port listening code in the SmartThings binding.
I hope you can give me some hints and instructions. Again, thanks for your contribution!