Sending JSON to arduino with hubaction

I want to send JSON data to my arduino from my SmartThings hub. I set up my arduino as a web server and tested that it will receive messages. I used POSTMAN to confirm.

I can confirm that the header data is there with this log entry

Below is my code that sets up my header data… and the post function:

def updated() {

    // Set Server Host variables config:
    state.serverHost = settings.prefHost
    state.serverPort = settings.prefPort
	state.serverAddress = state.serverHost + ":" + state.serverPort
    logger("Setting Server Variables: Server Address ${state.serverAddress}","info")
    state.headers = [:] 
    state.headers.put("HOST", "${state.serverAddress}\body")
    state.headers.put("Content-Type", "application/json")

def postToServer(data) {
    logger("postToServer(): Posting data to Server: Host: [${state.headers}] Data: [${data}]","info")
    logger("Setting Server Variables: Server Address ${state.serverAddress}","info")
    try {
        def hubAction = new physicalgraph.device.HubAction(
            method: "POST",
            path: "",
            body: data,
            headers: state.headers,
    catch (Exception e) {
		logger("postToServer(): Exception ${e} on ${hubAction}","info")

I am not receiving any messages from the hub. Any suggestions?

Webcore allows you to send we calls.

1 Like

Would this work?

I’d say HOST must contain only host:port combination. The rest should be in path. If you want you can use uri for all that. I’d also add application/json for “Content-type”.

That is info for building a SmartApp and not a DTH. You are building a DTH to trigger the action from your smartapp right?