Connect to LAN device via REST

Hello, I’m strugling to connect my alarm system via Rest interface. The problem that it could be connected only as LAN connected device.
I’m trying to use HubAction from both SmartApp and DeviceHandler but not able to get a response back. Hub version #3. I wonder if I should contact the support of something wrong with my code? Here is it
try {
def hubAction = new physicalgraph.device.HubAction(
[
method: “GET”,
path: “/ISAPI/Event/triggers/”,
headers: [
HOST: “192.168.0.220”, //IP of my device
Authorization: “Basic XXXXXtaWXXXX9uZGFWZXXX”
]
],
null, //hub.id - sending actual hub id does not help as well
[ callback: handleResponse ]
)
sendHubCommand(hubAction)
}
catch (Exception e) {
logger(“postToInfluxDB(): Exception {e} on {hubAction}”,“error”)
}
def handleResponse(physicalgraph.device.HubResponse hubResponse) //Never called with respose

The same story with Device handler

  1. Add physical device in Service Manager smart app
    def hub = location.hubs[0]
    def DNI = “192.168.0.220”
    def childDevice = addChildDevice(“myspace”, “MyAlarmDevice”, DNI, hub.id, [name: app.label, label: app.label, data: [“mac”: “4CBD8F64AED1”, “ip”: “192.168.0.220” , “port”: “80”], completedSetup: true]) //ip": “C0A800DC0” , “port”: “50” - wont work as well

  2. in DeviceHandler configure
    def userpass = "Basic " + userpassascii.encodeAsBase64().toString()
    def headers = [:]
    headers.put(“HOST”, “192.168.0.220:80”)
    headers.put(“Authorization”, userpass)

    def result = new physicalgraph.device.HubAction(
    method: “GET”,
    path: “/ISAPI/Event/triggers/”,
    headers: headers,
    //body: “{test JSON}”,
    protocol: physicalgraph.device.Protocol.LAN
    /callback: parse/
    /“C0A800DC:50”/
    )
    return result
    }
    def parse(description) //Never called back.
    Could someone help with what is wrong with my code?

I’m a bit rusty with this, but the key is usually to get the DNI of the device correct.

If you are just expecting a response to a request, setting the DNI to the hex encoded IP:PORT used to communicate with the device usually works e.g. C0A8004C:1BB0.

Alternatively use the MAC e.g. F0455910B963 as that works for the above and for unsolicited messages from the device.

Hello,

Unfortunately MAC won’t work as well, nothing is returned back:

 def result = new physicalgraph.device.HubAction(
          [
     	method: "GET",
	         path: "/ISAPI/Event/triggers/",
	         headers: headers,
             protocol: physicalgraph.device.Protocol.LAN
          ], 
        "4CBD8F64AED1"
)

Try to omit the host and use a callback instead which is separate from parse. Also check that your hub and devices are able to communicate on port 80.

I’ve changed host my laptop to sniff requests. Now it is bit better. I have my parse method called. BUT ip looks weird: ip:00000192!!!
Can it be some UnPn issue or some caching issue?
6:19:32 PM: debug Parsing message:‘addressChangeType:01, mac:448500CED83F, ip:00000192, port:8080’
6:19:26 PM: debug GET /myLockTest LAN
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.110:8080
Content-Type: application/json
Authorization: Basic YWRtaW46SG9uZGFWZWk1
debug Return device handler:

Code itself:

def childDevice = addChildDevice(“alexhomesmartaps1”, “MyAlarm Switch1”, DNI, hub.id, [name: app.label, label: app.label, data: [“mac”: “448500CED83F”, “ip”: “C0A8006E” , “port”: “1F90”], completedSetup: true]) //ip": “C0A800DC0” , “port”: “50”

  try {
    def hubAction = new physicalgraph.device.HubAction(
    	[
            method: "GET",
            path: "/ISAPI/Event/triggers/",
            headers: [
 	            HOST: "192.168.0.110:8080",
             ]
         ],    
         null
    )		
    sendHubCommand(hubAction)

Why ip 00000192 instead of 192.168.0.110?
No request to my laptop but method parse called with message returned: “‘addressChangeType:01, mac:448500CED83F, ip:00000192, port:8080’”

Just as follow up. Finally I’ve got it.

  1. Disabled UPnP services on Windows and in Router (where I installed REST server for debugging purposes)
  2. Make sure DNI - is MAC adress of the device
  3. MAC, IP and Port of the device must be in HEX. ie. addChildDevice(… [name, label, data: [“mac”: “4CBD8F64AED1”, “ip”: “C0A8004C” , “port”: “1BB0”]
  4. Restart Hub after all manipulation and create new smartApp(old one seems to be cached with wrong device information)

Topic closed