Weird POST issue

I'm having a very weird issue when creating a driver for my 3d printer

I need to send a basic post command, at the moment just triggered from a button on the driver, e.g. "http://192.168.25.206/printer/gcode/script?script=FIRMWARE_RESTART"

Following that I want to call another command to get an updated status, am I hitting a restriction in Hubitat or am I tired and missing something obvious here?

The issue is that this works:

def FIRMWARE_RESTART(){
    sendCommand("/printer/gcode/script?script=FIRMWARE_RESTART")
}

But this doesn't, if I put anything after the sendCommand then nothing happens, not even the POST:

def FIRMWARE_RESTART(){
    sendCommand("/printer/gcode/script?script=FIRMWARE_RESTART")
    x = 1 //Just a basic example, as anything here stops the above from successfully working?
}

The command being called

def sendCommand(command){
	def headers = [:] 
    headers.put("HOST", "${ip}:${port}")
    try {
        def hubAction = new hubitat.device.HubAction(
            method: POST,
            path: command,
            headers: headers
            )
    }
    catch (Exception e) {
        log.debug "runCmd hit exception ${e} on ${hubAction}"
	}
}

I have seen and experienced that issue. Anything after the post fails to make it do the device. I never found a direct way around it. I did get creative. Maybe try a runIn (scheduled before the post)???

1 Like

As a workaround, and perhaps something you'd want to do for other reasons anyway (I almost never use the non-async HTTP calls in Hubitat), could you use asynchttpPost() instead? If you need to wait for the POST to finish before performing the next action, you can do that in the callback method instead of inside the calling method.

2 Likes

This is where I was heading, but a little expensive when only needing to pause for < 1 second!

This is what I used thanks, this seems to fix my problem!

Surely this is a bug though?

1 Like