// Agent Code //-------------------------------------------------- // POST Rain Data to Website API //-------------------------------------------------- // Basic wrapper to create an execute an HTTP POST function rainLog(v) { // Set up outgoing request object local request = http.get("https://www.yoursite.com/gauge/reportrain.php?data=" + v); // Define the response handler function handleResponse(responseTable) { // Called when the imp receives a response from the remote service if (responseTable.statuscode == 200) { server.log("Rain Data Sent: " + v); } else { // Log an error server.log("Error response: " + responseTable.statuscode); } } // Send the request asynchronously. This will not block the imp CPU request.sendasync(handleResponse); } device.on("rain", function(v) { rainLog(v); }); // Device Code #require "Button.class.nut:1.2.0" function poll(){ // Check rain gauge every 5 minutes if(tipcount > 0){ agent.send("rain", tipcount); } tipcount=0; local timer = imp.wakeup(300, poll); } tipcount <- 0; // Configure Input Pins tipper <- Button(hardware.pinT, DIGITAL_IN_PULLUP, Button.NORMALLY_HIGH, function() { server.log("Button pressed"); } ); tipper.onPress(function() { tipcount++; server.log("Tipper: " + tipcount); }); poll();