Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmartApp triggers ok, but bridge.deviceNotification(json) not triggered #205

Open
dcolley opened this issue Jul 8, 2019 · 1 comment
Open

Comments

@dcolley
Copy link

dcolley commented Jul 8, 2019

I [mostly] followed the README with mosquitto running natively on rpi3.
pub and sub work from other computers in the house, to it seems to be fine.

The server.js is also running on the rpi3, listening on port 8085.

I created a Sim Switch, and linked the SmartApp to the on/off Switch

// Receive an event from a device
def inputHandler(evt) {
	log.debug "MBA: inputHandler firing..."
    //log.debug "  name: '${evt.displayName}'"
    //log.debug "  value: '${evt.value}'"
    //log.debug "  type: '${evt.name}'"

    if (
        state.ignoreEvent
        && state.ignoreEvent.name == evt.displayName
        && state.ignoreEvent.type == evt.name
        && state.ignoreEvent.value == evt.value
    ) {
        log.debug "Ignoring event ${state.ignoreEvent}"
        state.ignoreEvent = false;
    } else {
        def json = new JsonOutput().toJson([
            path: "/push",
            body: [
                name: evt.displayName,
                value: evt.value,
                type: evt.name
            ]
        ])

		//String ip = bridge.getConf("ip")
		//log.debug "MBA: inputHandler: bridge.ip='${ip}'"
		//log.debug "bridge:"
		//log.debug "${bridge}"
        log.debug "Forwarding device event to bridge: ${json}"
        if(bridge == null) {
	        log.debug "MBA: bridge == null !!!!"
        } else {
    	    bridge.deviceNotification(json)
        }
    }
}

Ok, the bridge is not NULL, but it's just the name of the bridge... I would expect it to be an object

When I trigger a Sim Switch, I can see the ST live log

12d065a0-ac58-4d40-b06b-5b4ab5180756  23:14:59: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Sim Switch","value":"on","type":"switch"}}
12d065a0-ac58-4d40-b06b-5b4ab5180756  23:14:59: debug MQTT Device
12d065a0-ac58-4d40-b06b-5b4ab5180756  23:14:59: debug bridge:
12d065a0-ac58-4d40-b06b-5b4ab5180756  23:14:59: debug MBA: inputHandler firing...

As you can see, 'forwarding to device' debug message is logged.

However, in the device handler - there is nothing logged.

// Send message to the Bridge
def deviceNotification(message) {
    log.debug "MBH: deviceNotification: '${message}'" // <<==== WE NEVER GET HERE
    if (device.hub == null) {
        log.error "Hub is null, must set the hub in the device settings so we can get local hub IP and port"
        return
    }
    
    log.debug "Sending '${message}' to device"
    setNetworkAddress()

    def slurper = new JsonSlurper()
    def parsed = slurper.parseText(message)
    
    if (parsed.path == '/subscribe') {
        parsed.body.callback = device.hub.getDataValue("localIP") + ":" + device.hub.getDataValue("localSrvPortTCP")
    }

    def headers = [:]
    headers.put("HOST", "$ip:$port")
    headers.put("Content-Type", "application/json")

	// this action will "POST" the "parsed.body" to the MQTT server "parsed.path"
    log.debug "MBH: deviceNotification(): parsed.path='${parsed.path}'"
    log.debug "MBH: deviceNotification(): parsed.body='${parsed.body}'"
    def hubAction = new physicalgraph.device.HubAction(
        method: "POST",
        path: parsed.path,
        headers: headers,
        body: parsed.body,
        callback: calledBackHandler  // I ADDED THIS, but it's not triggered
    )
    hubAction
}

How can I force / debug the connection from the SmartApp to the DeviceHandler?

@dcolley
Copy link
Author

dcolley commented Jul 10, 2019

If anyone is interested, I also asked the question here: https://community.smartthings.com/t/mqtt-bridge-smartapp-does-not-trigger-dh/167834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant