Here it is:
`
//Garage door status monitor, alarm, and opener
//Identify the output ports
//Status reports “Open” or “Closed”
//Alarm reports “Normal” or “Alarmed”
//push the button connected to pin 1 on agent call
//the for loop holds the button down before it is released
function pressbutton(buttonState) {
buttonState=0;
server.log(“checkpoint3”);
hardware.pin1.write(1);
server.log(“checkpoint7”);
for(local a=0;a<5000;a+=1);
//imp.sleep(0.5);
server.log("checkpoint8");
hardware.pin1.write(0);
server.log("checkpoint4");
}
server.log(“checkpoint5”);
//Pin5 is connected to a magnetic reed switch that monitors the door status
//Debounce digital status of pin5
ignore <- false;
function debounce() {
ignore = false;
check_state();
}
//Function to watch the state of the door and to send outputs when the stats changes
function check_state() {
//Check state of the door
local doorstatus=hardware.pin5.read();
//Check date (required to find the current time)
local d = date();
//Set current GMT hour
local hournow = d.hour;
//Preset alarm status
local alarmstatus = false;
//If statements set the times for alarm
if (hournow >= 4)
if (hournow <= 11)
//Check to see if door is open
if (doorstatus == 1)
//If door is open during hours of concern, set alarm
alarmstatus = true;
//Report status of door to output 1
// out1.set(doorstatus?“Open”:“Closed”);
agent.send(“DoorState”, doorstatus?“Open”:“Closed”);
//Log door status
server.log(doorstatus?“open”:“closed”);
//Log alarm status
server.log(alarmstatus?“Alarmed”:“Normal”);
//Report status of alarm to output 2
// out2.set(alarmstatus?“Alarmed”:“Normal”);
agent.send(“AlarmState”, alarmstatus?“Alarmed”:“Normal”);
//Show door status on planner
server.log(doorstatus?“open”:“closed”);
}
//Continues debounce procedures
function switched () {
if(!ignore) {
check_state();
ignore = true;
// imp.wakeup(0.05, debounce);
}
}
//Configure the digital pins
hardware.pin5.configure(DIGITAL_IN_PULLUP, switched);
hardware.pin1.configure(DIGITAL_OUT);
//Check to see if the door has opened or closed
check_state();
//watchdog keep alive–necessary to continually update COSM and Sen.se streams
function watchdog() {
imp.wakeup(60, watchdog);
server.log(“watchdog”);
check_state();
}
agent.on(“button”, pressbutton);
// start sending something every ~1 minutes
watchdog();
`