Mercurial > ~darius > hgwebdir.cgi > beermon
diff MonitorDev.py @ 16:67a4dc218bbf
- Add commented out entries for ZigBee experiment.
- Send a return and sync up before sending out commands.
author | darius |
---|---|
date | Tue, 29 Jan 2008 11:39:22 +0000 |
parents | 8ada8d5cca15 |
children |
line wrap: on
line diff
--- a/MonitorDev.py Tue Jan 29 11:27:20 2008 +0000 +++ b/MonitorDev.py Tue Jan 29 11:39:22 2008 +0000 @@ -3,7 +3,7 @@ ############################################################################ # Monitoring/control interface to hardware for beermon # -# $Id: MonitorDev.py,v 1.3 2007/10/23 01:05:22 darius Exp $ +# $Id: MonitorDev.py,v 1.4 2008/01/29 11:39:22 darius Exp $ # # Depends on: Python 2.3 (I think) # @@ -91,7 +91,11 @@ # Setup locking & spawn SSH self.commsLock = threading.Lock() + #self.p = pexpect.spawn('/usr/bin/cu', ['-l', '/dev/cuaU1', '-s', '38400']) self.p = pexpect.spawn('/usr/bin/ssh', ['-xt', '-enone', '-i', '/home/darius/.ssh/id_wrt', 'root@wrt', '(echo logged in; microcom -D/dev/cua/1)']) + + self.p.timeout = 30 + #assert(self.p.expect('Connected') == 0) assert(self.p.expect('logged in') == 0) self.p.timeout = 3 self.setspeed() @@ -110,7 +114,7 @@ log.debug("minHeatOvershoot - %3.2f, minCoolOvershoot - %3.2f" % (self.minHeatOvershoot, self.minCoolOvershoot)) self.start() - + def setspeed(self): """Set the speed microcom talks to the serial port to 38400""" self.commsLock.acquire() @@ -123,7 +127,7 @@ self.p.send('f') assert(self.p.expect('done!') == 0) self.commsLock.release() - + def find1wire(self): """Scan the bus for 1-wire devices""" self.commsLock.acquire() @@ -145,7 +149,7 @@ idx = self.p.expect([self.romre, self.promptre]) if (idx == 0): # Matched a ROM - #print "Found ROM " + self.p.match.group() + #log.debug("Found ROM " + self.p.match.group()) devlist.append(self.p.match.group(0)) elif (idx == 1): # Matched prompt, exit @@ -176,7 +180,7 @@ except OWReadError: # Ignore this - just results in no update reflected by lastUpdate pass - + return(self.temps) def readTemp(self, id): @@ -188,13 +192,11 @@ assert(self.p.expect(cmd) == 0) # Eat EOL left from expect self.p.readline() - line = self.p.readline().strip() self.commsLock.release() # 'CRC mismatch' can mean that we picked the wrong ROM.. if (re.match('CRC mismatch', line) != None): raise OWReadError - return(line) def setState(self, state): @@ -230,9 +232,11 @@ self.commsLock.acquire() # Need the extra spaces cause the parser in the micro is busted + self.p.sendline('') + assert(self.p.expect('> ') == 0) cmd = 'out c %02x' % relay self.p.sendline(cmd) - # Echo + # Echo assert(self.p.expect(cmd) == 0) self.commsLock.release()