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() {
logger("updated()","trace")
// 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,
)
hubAction
}
catch (Exception e) {
logger("postToServer(): Exception ${e} on ${hubAction}","info")
}
}
I am not receiving any messages from the hub. Any suggestions?