comparison service/rfid_pn532_py/rfid.py @ 435:80e403e107b1

more error handling Ignore-this: f0fdd453ae131f867fdffc558603d09a
author drewp@bigasterisk.com
date Sat, 13 Apr 2019 15:23:46 -0700
parents 2409446ccfa2
children aff8ca01f8eb
comparison
equal deleted inserted replaced
434:2409446ccfa2 435:80e403e107b1
8 from rdflib.parser import StringInputSource 8 from rdflib.parser import StringInputSource
9 from twisted.internet import reactor, task, defer 9 from twisted.internet import reactor, task, defer
10 import cyclone.web 10 import cyclone.web
11 from cyclone.httpclient import fetch 11 from cyclone.httpclient import fetch
12 import cyclone 12 import cyclone
13 import logging, time, json, random, string 13 import logging, time, json, random, string, traceback
14 from logsetup import log, enableTwistedLog 14 from logsetup import log, enableTwistedLog
15 from greplin import scales 15 from greplin import scales
16 from greplin.scales.cyclonehandler import StatsHandler 16 from greplin.scales.cyclonehandler import StatsHandler
17 from export_to_influxdb import InfluxExporter 17 from export_to_influxdb import InfluxExporter
18 from tags import NfcDevice, FakeNfc 18 from tags import NfcDevice, FakeNfc, NfcError, AuthFailedError
19 19
20 ROOM = Namespace('http://projects.bigasterisk.com/room/') 20 ROOM = Namespace('http://projects.bigasterisk.com/room/')
21 21
22 ctx = ROOM['frontDoorWindowRfidCtx'] 22 ctx = ROOM['frontDoorWindowRfidCtx']
23 23
125 if self.overwrite_any_tag and not looksLikeBigasterisk(textLit): 125 if self.overwrite_any_tag and not looksLikeBigasterisk(textLit):
126 log.info("block 1 was %r; rewriting it", textLit) 126 log.info("block 1 was %r; rewriting it", textLit)
127 tag.writeBlock(1, randomBody()) 127 tag.writeBlock(1, randomBody())
128 textLit = Literal(tag.readBlock(1).rstrip('\x00')) 128 textLit = Literal(tag.readBlock(1).rstrip('\x00'))
129 finally: 129 finally:
130 # This might not be appropriate to call after
131 # readBlock fails. I am getting double
132 # exceptions.
130 tag.disconnect() 133 tag.disconnect()
131 self.startCardRead(cardIdUri, textLit) 134 self.startCardRead(cardIdUri, textLit)
132 except OSError as e: 135 except AuthFailedError as e:
136 log.error(e)
137 except (NfcError, OSError) as e:
138 traceback.print_exc()
133 log.error(e) 139 log.error(e)
134 reactor.stop() 140 reactor.stop()
135 def flushOldReads(self, now): 141 def flushOldReads(self, now):
136 for uri in list(self.log): 142 for uri in list(self.log):
137 if self.log[uri] < now - self.expireSecs: 143 if self.log[uri] < now - self.expireSecs: