Ejemplo n.º 1
0
 def _read(self):
     dallas = self.parent
     dallas.reset()
     dallas.matchrom(self.address)
     dallas.readscratch()
     result = dallas.readbytes(9)
     if crc_of(result) == 0:
         t = unpack('<h', result[:2])[0]
         self.result = t
         if self.bad_crc_count > 10:  #was logged as bad
             msglog.log('DallasBus', 'information', 'Resumed: %s' % \
                             as_node_url(self))
         self.bad_crc_count = 0
         t = uptime_secs()
         self.scan_period = t - self._last_read_time
         self._last_read_time = t
         if self.debug:
             print "TEMPERATURE SENSOR: _read value", self.result
     else:
         if self.bad_crc_count < 11:
             self.bad_crc_count += 1
             if self.bad_crc_count == 10:
                 self.result = None  #return ETimeout to gets
                 raise EInvalidResponse('Failed read ten times: %s' % \
                                    as_node_url(self))
         if self.debug:
             print "TEMPERATURE SENSOR: BAD CRC", result
     return
Ejemplo n.º 2
0
 def get(self, skipCache=0):
     t = uptime_secs()
     if self._ttl > t and skipCache == 0:  # return cached value
         return self._value
     self._ttl = t + self.ttl  # set time of ttl expire
     self._value = self._data_type(self.convert())
     return self._value
Ejemplo n.º 3
0
 def _scan_sensors(self):
     self.children_nodes()  # trigger autodiscovery to get the ball rolling
     while 1:
         try:
             while self.running:
                 sensors = self.children_nodes(auto_discover=0)[:]
                 for sensor in sensors:
                     # add a little pause based on number of sensors
                     delay = 11.0 / len(
                         sensors)  # roughly one sensor per sec
                     if delay < 0.5:
                         delay = 0.5
                     pause(delay)
                     try:
                         if not self.running: break
                         sensor.result = self._read_temperature_for(sensor)
                         if sensor.bad_crc_count > 10:  #was logged as bad
                             msglog.log('DallasBus', 'information', 'Resumed: %s' % \
                                     as_node_url(sensor))
                         sensor.bad_crc_count = 0
                         # update the scan_period that shows up in configuration
                         t = uptime_secs()
                         sensor.scan_period = t - sensor._last_read_time
                         sensor._last_read_time = t
                     except:
                         if sensor.bad_crc_count < 11:
                             sensor.bad_crc_count += 1
                             if sensor.bad_crc_count == 10:
                                 sensor.result = None  #return ETimeout to gets
                                 msglog.log('DallasBus', 'information', 'Failed: %s' % \
                                            as_node_url(sensor))
                 if not sensors: pause(17)  # slow down if no dallas bus
         except:
             if self.debug: msglog.exception()
         pause(30)
Ejemplo n.º 4
0
 def get(self, skipCache=0):
     t = uptime_secs()
     if self._ttl > t and skipCache == 0: # return cached value
         return self._value
     self._ttl = t + self.ttl # set time of ttl expire
     self._value = self._data_type(self.convert())
     return self._value
Ejemplo n.º 5
0
 def _scan_sensors(self):
     self.children_nodes() # trigger autodiscovery to get the ball rolling
     while 1:
         try:
             while self.running:
                 sensors = self.children_nodes(auto_discover=0)[:]
                 for sensor in sensors:
                     # add a little pause based on number of sensors
                     delay = 11.0 / len(sensors) # roughly one sensor per sec
                     if delay < 0.5:
                         delay = 0.5
                     pause(delay)
                     try:
                         if not self.running: break
                         sensor.result = self._read_temperature_for(sensor)
                         if sensor.bad_crc_count > 10: #was logged as bad
                             msglog.log('DallasBus', 'information', 'Resumed: %s' % \
                                     as_node_url(sensor))
                         sensor.bad_crc_count = 0
                         # update the scan_period that shows up in configuration
                         t = uptime_secs()
                         sensor.scan_period = t - sensor._last_read_time
                         sensor._last_read_time = t
                     except:
                         if sensor.bad_crc_count < 11:
                             sensor.bad_crc_count += 1
                             if sensor.bad_crc_count == 10:
                                 sensor.result = None #return ETimeout to gets
                                 msglog.log('DallasBus', 'information', 'Failed: %s' % \
                                            as_node_url(sensor))
                 if not sensors: pause(17) # slow down if no dallas bus
         except:
             if self.debug: msglog.exception()
         pause(30)
Ejemplo n.º 6
0
 def _read(self):
     dallas = self.parent
     dallas.reset()
     dallas.matchrom(self.address)
     dallas.readscratch()
     result = dallas.readbytes(9)
     if crc_of(result) == 0:
         t = unpack('<h', result[:2])[0]
         self.result = t
         if self.bad_crc_count > 10: #was logged as bad
             msglog.log('DallasBus', 'information', 'Resumed: %s' % \
                             as_node_url(self))
         self.bad_crc_count = 0
         t = uptime_secs()
         self.scan_period = t - self._last_read_time
         self._last_read_time = t
         if self.debug:
             print "TEMPERATURE SENSOR: _read value", self.result
     else:
         if self.bad_crc_count < 11:
             self.bad_crc_count += 1
             if self.bad_crc_count == 10:
                 self.result = None #return ETimeout to gets
                 raise EInvalidResponse('Failed read ten times: %s' % \
                                    as_node_url(self))
         if self.debug:
             print "TEMPERATURE SENSOR: BAD CRC", result
     return