Is there anybody can help me to solve this "httpPostJson()" problem?


#1

I’m trying to write a SmartApp to send the state of a device to a server (my VPS). The code is as follows:

preferences {
section(“Collect the motion data:”) {
input “motion_sensor”, “capability.motionSensor”, required: true
}
}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()

}

def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.

subscribe(motion_sensor, "motion.active", postData)

}

def postData(evt) {
def params = [
uri: “104.160.33.4”,
// or uri: “www.baidu.com
]

try {
	httpPostJson(params) {
    log.debug "Do nothing on the response."
	}
} catch (e) {
	log.debug "something went wrong: $e"
}

}
// TODO: implement event handlers

This SmartApp is supposed to send some data to a remote server once it is triggered by a “Motion” event.

But once I triggered the motion sensor, it outputs some debug information:

“something went wrong: java.lang.reflect.UndeclaredThrowableException”

Is there anybody can help me? Thank you very much.


#2

I’ve solved this: “www.baidu.com” --> “http://www.baidu.com

How stupid I am.

:slight_smile: