# HG changeset patch # User drewp@bigasterisk.com # Date 1313383617 25200 # Node ID 4c44c80a6a728c2ac6a7f56e0158af0ac030dc82 # Parent be855a1116199217afd03479c1d93107e1b4d839 move garage door opener from parport to arduino Ignore-this: c7d21f40841af0e64b26dd4991e441ae diff -r be855a111619 -r 4c44c80a6a72 service/garageArduino/garage/garage.pde --- a/service/garageArduino/garage/garage.pde Mon Aug 08 00:31:31 2011 -0700 +++ b/service/garageArduino/garage/garage.pde Sun Aug 14 21:46:57 2011 -0700 @@ -8,6 +8,14 @@ // the phototransistor on analog2 is jameco 2006414 + pinMode(3, OUTPUT); + digitalWrite(3, LOW); + // this drives a relay for the garage door. There is a + // LP filter on it so the garage doesn't open if there's + // an arduino power-on glitch. It may be that atmel has + // circuitry to prevent such glitches, so a pull-down + // resistor may be enough. I haven't checked carefully. + Serial.begin(115200); } @@ -61,6 +69,11 @@ Serial.print("{\"threshold\":"); Serial.print(threshold); Serial.print("}\n"); + } else if (cmd == 0x04) { + digitalWrite(3, arg); + Serial.print("{\"garage\":"); + Serial.print(arg ? "true" : "false"); + Serial.print("}\n"); } } } diff -r be855a111619 -r 4c44c80a6a72 service/garageArduino/garageArduino.py --- a/service/garageArduino/garageArduino.py Mon Aug 08 00:31:31 2011 -0700 +++ b/service/garageArduino/garageArduino.py Sun Aug 14 21:46:57 2011 -0700 @@ -5,19 +5,20 @@ from __future__ import division -import cyclone.web, json, traceback, os, sys, time -from twisted.python import log -from twisted.internet import reactor, task +import cyclone.web, json, traceback, os, sys, time, logging +from twisted.internet import reactor, task, defer from twisted.web.client import getPage sys.path.append("/my/proj/house/frontdoor") from loggingserial import LoggingSerial +sys.path.append("/my/proj/homeauto/lib") +from cycloneerr import PrettyErrorHandler +from logsetup import log sys.path.append("../../../room") from carbondata import CarbonClient sys.path.append("/my/site/magma") from stategraph import StateGraph from rdflib import Namespace, RDF, Literal -sys.path.append("/my/proj/homeauto/lib") -from cycloneerr import PrettyErrorHandler + ROOM = Namespace("http://projects.bigasterisk.com/room/") DEV = Namespace("http://projects.bigasterisk.com/device/") @@ -46,6 +47,11 @@ self.ser.write("\x60\x03"+chr(max(1 << 2, t) >> 2)) return self.ser.readJson()['threshold'] + def setGarage(self, level): + """set garage door opener pin""" + self.ser.write("\x60\x04"+chr(int(bool(level)))) + return self.ser.readJson()['garage'] + class Index(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): @@ -112,6 +118,19 @@ def put(self): pass +class GarageDoorOpen(PrettyErrorHandler, cyclone.web.RequestHandler): + def post(self): + self.set_header("Content-Type", "text/plain") + self.settings.arduino.setGarage(True) + self.write("pin high, waiting..\n") + self.flush() + d = defer.Deferred() + def finish(): + self.settings.arduino.setGarage(False) + self.write("pin low. Done") + d.callback(None) + reactor.callLater(1.5, finish) # this time depends on the LP circuit + return d class Application(cyclone.web.Application): def __init__(self, ard, poller): @@ -122,6 +141,7 @@ (r'/housePower', HousePower), (r'/housePower/raw', HousePowerRaw), (r'/housePower/threshold', HousePowerThreshold), + (r'/garageDoorOpen', GarageDoorOpen), ] settings = {"arduino" : ard, "poller" : poller} cyclone.web.Application.__init__(self, handlers, **settings) @@ -220,7 +240,10 @@ 'boardName' : 'garage', # gets sent with updates } - #log.startLogging(sys.stdout) + #from twisted.python import log as twlog + #twlog.startLogging(sys.stdout) + + log.setLevel(logging.DEBUG) ard = ArduinoGarage() diff -r be855a111619 -r 4c44c80a6a72 service/garageArduino/index.html --- a/service/garageArduino/index.html Mon Aug 08 00:31:31 2011 -0700 +++ b/service/garageArduino/index.html Sun Aug 14 21:46:57 2011 -0700 @@ -19,6 +19,8 @@

Talking to an arduino uno on host slash

+

Pulse pin 3 to trigger garage door opener

+

PIR sensor (in a box) measuring front door motion:

phototransistor watching IR pulses on the power meter: last pulse was ; current power usage is watts (assuming kwh/blink)

@@ -73,4 +75,4 @@ // ]]> - \ No newline at end of file +