Getting a response back from sendHubCommand()

(Robert Cooper) #1

So, after a lot of feeling around, I have been able to get HubActions to fire from device types, but I’ll be damned if I can figure out the juju to make sendHubCommand for HTTP from a SmartApp work.

subscribe(location, null, handlerMethod, [filterEvents:false])

…doesn’t ever seem to give me back my LAN response, and I am not sure why. Before I punt on this and do something stupid like create a device just to make network requests, it anybody has some idea on what the problem is, that would be keen.

(John S) #2

That seems right. Have you logged the calls into handlerMethod to see what you’re getting? You need to parse the response in the method, but it should be getting called with whatever the hubAction returns.

Can you post a small test app showing what you’re trying to do?

(Robert Cooper) #3

Yeah. Literally the only thing I am getting back from my handler method is the “register” action for the smart app. I can see the request/response hitting my http server, so I know that is at least firing, but I am never getting my result back as a local event. :confused:

Here is the minimalist test I put together to try and debug this. (I added the runAt because I thought maybe there was something where I needed to wait for the register even to come back before I could even send the hub command:

def initialize() {
	log.debug "Initialize."
    subscribe(location, null, lanResponseHandler, [filterEvents:false])
    runIn(10, scan)

def scan(){
	def result = new physicalgraph.device.HubAction(
            method: "GET",
            path: "/rest/device/list",
            headers: [
                    HOST: "",
    log.debug result.toString()

def lanResponseHandler(evt) {
	log.debug "entering lanResponceHandler"
    log.debug ""

(John S) #4

That seems correct to me :frowning:

(Alex Hart) #5

Did you ever get this to work?

(dcvn) #6

def initialize() {
subscribe(location, “ssdpTerm.ssdp:all”, ssdpHandler, [filterEvents:false])
// subscribe(location, “ssdpTerm.urn:schemas-upnp-org:device:Basic:1”, ssdpHandler)
// subscribe(location, “ssdpTerm.urn:schemas-upnp-org:device:ZonePlayer:1”, ssdpHandler, [filterEvents:false])
log.debug "initialized subscribed"

void ssdpDiscover() {
log.debug "LAN look"
sendHubCommand(new physicalgraph.device.HubAction(“lan discovery ssdp:all”, physicalgraph.device.Protocol.LAN))
// sendHubCommand(new physicalgraph.device.HubAction(“lan discovery urn:schemas-upnp-org:device:ZonePlayer:1”, physicalgraph.device.Protocol.LAN))

void ssdpHandler(evt) {
log.debug "ssdp handler called"
def description = evt.description
def hub = evt?.hubId

def parsedEvent = parseEventMessage(description)
parsedEvent << ["hub":hub]

def devices = getDevices()
String ssdpUSN = parsedEvent.ssdpUSN.toString()
if (!devices."${ssdpUSN}") {
    devices << ["${ssdpUSN}": parsedEvent]


(dcvn) #7

I feel I’m close…
Not working yet, but no errors

(Joe) #8

Have you ever gotten this to work? I am trying the same thing