Skip to content

Instantly share code, notes, and snippets.

@bkeifer
Last active January 25, 2016 04:22
Show Gist options
  • Save bkeifer/15e4b9ef2519dbdbeb2c to your computer and use it in GitHub Desktop.
Save bkeifer/15e4b9ef2519dbdbeb2c to your computer and use it in GitHub Desktop.
THIS WORKS:
------------------
curl -X POST -H 'Accept: */*' -H 'Content-type: text/xml; charset=utf-8' -H 'SOAPAction: "urn:Belkin:service:deviceevent:1#SetAttributes"' -d '<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetAttributes xmlns:u="urn:Belkin:service:deviceevent:1">
<attributeList>&lt;attribute&gt;&lt;name&gt;FanMode&lt;/name&gt;&lt;value&gt;2&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;DesiredHumidity&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;CurrentHumidity&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;WaterAdvise&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;NoWater&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;FilterLife&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;ExpiredFilterTime&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;</attributeList>
</u:SetAttributes>
</s:Body>
</s:Envelope>' http://humidifier.lan:$1/upnp/control/deviceevent1
THIS DOESN'T:
------------------
def body = """
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetAttributes xmlns:u="urn:Belkin:service:deviceevent:1">
<attributeList>&lt;attribute&gt;&lt;name&gt;FanMode&lt;/name&gt;&lt;value&gt;1&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;DesiredHumidity&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;CurrentHumidity&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;WaterAdvise&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;NoWater&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;FilterLife&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;&lt;attribute&gt;&lt;name&gt;ExpiredFilterTime&lt;/name&gt;&lt;value&gt;NULL&lt;/value&gt;&lt;/attribute&gt;</attributeList>
</u:SetAttributes>
</s:Body>
</s:Envelope>
"""
postRequest('/upnp/control/deviceevent1', 'urn:Belkin:service:deviceevent:1#SetAttributes', body)
private postRequest(path, SOAPaction, body) {
// Send a post request
def result = new physicalgraph.device.HubAction([
'method': 'POST',
'path': path,
'body': body,
'headers': [
'HOST': getHostAddress(),
'Content-type': 'text/xml; charset=utf-8',
'SOAPAction': "\"${SOAPaction}\""
]
], device.deviceNetworkId)
log.debug "RESULT: ${result}"
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment