/* Agent for imp Web-Controlled LEDs by: Jim Lindblom SparkFun Electronics date: November 1, 2013 Mdified by Michael Morken */ // At the start, print a message to say we're online, and print the agent URL: server.log("LED Web Control Agent Online: " + http.agenturl()); // requestHandler handles all http requests coming into the agent. It's only // setup to look for a select few requests: "led", "rgb", "user" and "timer". function requestHandler(request, response) { try { // Try provides us with exception handling, in case a runtime error occurs // check if the user sent led as a query parameter if ("led" in request.query) { // if they did, and led=1.. set our variable to 1 if ((request.query.led == "1") || (request.query.led == "0")) { // convert the led query parameter to an integer local ledStatus = request.query.led.tointeger(); // send "led" message to device, and send ledState as the data device.send("led", ledStatus); } } // check if a "user" query was received. if ("user" in request.query) { device.send("user", request.query.user); // Simply pass the value out to the imp. } // check if a "timer" query was received: if ("timer" in request.query) { // convert to an integer, and pass it out to the imp. device.send("timer", request.query.timer.tointeger()); } // send a response back saying everything was OK. response.send(200, "Thanks " + request.query.user + "!!!!"); //Sending back the User Information to the site local userName = {"userName": ""+request.query.user+""} } catch (ex) { response.send(500, "Internal Server Error: " + ex); } } // Set up a handler for HTTP requests. This is the function that we defined above. // https://electricimp.com/docs/api/http/onrequest/ http.onrequest(requestHandler);