Skip to content

Instantly share code, notes, and snippets.

@StuffAndyMakes
Last active December 26, 2015 17:49
Show Gist options
  • Select an option

  • Save StuffAndyMakes/7189930 to your computer and use it in GitHub Desktop.

Select an option

Save StuffAndyMakes/7189930 to your computer and use it in GitHub Desktop.
Agent code for iPotti #2 bathroom availability monitoring system
device.on( "lightChanged", function( json ) {
// Set URL to your web service
local url = "http://somedomain.com/api/for/ipotti";
// Set Content-Type header to json
local headers = { "Content-Type": "application/json" };
// encode data and log
local body = http.jsonencode( json );
server.log( "JSON payload going to iPotti server: " + body );
// send data to your web service
//http.post( url, headers, body ).sendsync();
// this is teh async way to do it
local request = http.post( url, headers, body);
request.sendasync( function ( res ) {
server.log( "iPotti server returned HTTP status " + res.statuscode );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment