Use servo to switch the light, it can controlled through HTTP command and also arranged by scheduling.
Step by Step Introduction
Built a electric imp agent code for receiving commands form internet.
The device side is scheduling the on/off automatically, and off work at weekend.
Here is the Device Code: (The position of servo is depend on how to setup the switch)
// These constants may be different for your servo
 
const SERVO_MIN = 0.03
const SERVO_MAX = 0.1
 
// Create global variable for the pin to which the servo is connected
// then configure the pin for PWM
 
servo Agent Code is here:
// Log the URLs we need
server.log("Turn Switch On: " + http.agenturl() + "?servo=1");
server.log("Turn Switch Off: " + http.agenturl() + "?servo=0");
 
function requestHandler(request, response) {
  try {
    // check if the user sent led as a query parameter
    if ("servo" in request.query) {
      
      // if they did, and servo=1.. set our variable to 1
      if (request.query.servo == "1" || request.query.servo == "0") {
        // convert the led query parameter to an integer
        local servoonoff = request.query.servo.tointeger();
 
        // send "led" message to device, and send ledState as the data
        device.send("servo", servoonoff); 
      }
    }
    // send a response back saying everything was OK.
    response.send(200, "OK");
  } catch (ex) {
    response.send(500, "Internal Server Error: " + ex);
  }
}
// register the HTTP handler
http.onrequest(requestHandler);





Comments