def handle(self, *args, **options): ser = serial.Serial(dev, 9600, timeout=2) ser.setRTS(True) ser.setRTS(False) while True: try: line = ser.readline() ts = datetime.now() l = line.split("\t") x, y, z = tuple(l) r = Reading(x=x, y=y, z=z, timeStamp=ts) r.save() except Exception, e: print e
def __init__(self): ser = serial.Serial(dev, 57600, timeout=2) ser.setRTS(True) ser.setRTS(False) while True: try: line = ser.readline() # print line ts = datetime.now() l = line.split("\t") x, y, z = tuple(l) r = Reading(x=x, y=y, z=z, timeStamp=ts) r.save() except Exception: pass ser.close
def writeObservation(self): #static objects objBldg = self.getOrCreateBuilding(self.getBuilding()) objRoom = self.getOrCreateRoom(self.getRoom(), self.getBuilding()) objSensortype = self.getOrCreateSensorType(self.getSensorType()) objUnit = self.getOrCreateUnit(self.getUnit()) objOwner = self.getOrCreateOwner(self.getOwner()) objRack = self.getOrCreateRack(self.getRack(),self.getCommonName(), self.getRoom(),self.getBuilding(),self.getOwner()) objSensor = Sensor(sensor_type_id=objSensortype.pk, rack_id=objRack.pk) objSensor.save() #try writing to the DB try: objReading = Reading(timestamp=self.getTimestamp(), value=self.getReading(), owner_id=objOwner.pk, sensor_id=objSensor.pk, unit_id=objUnit.pk) #commit changes to db objReading.save() except: print "Error: Could not write the changes to DB"