def sample_indication(self, buf, addr): # Parse the I/O sample: io_sample = parse_is(buf) # Calculate channel values: light_mv, temperature_mv, current_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) light = round(light_mv,0) if light < 0: # clamp to be zero or higher light = 0 power_state = self.property_get("power_on").value # TODO: CRA Max could you remove this offset code? Change to clip at 0. if not power_state: self.offset = current_mv * (157.0 /47.0) if self.offset >= 600.0: ## Probably a current spike from flipping the power relay self.offset = 520.0 current = round( (current_mv * (157.0 / 47.0) - self.offset) / 180.0 * 0.7071, 3) pf_adj = self.get_power_factor() # compute powerfactor adjusted current if 1.0 >= pf_adj and 0.0 <= pf_adj: current *= pf_adj if current <= 0.05: # Clip the noise at the bottom of this sensor: current = 0.0 temperature = (temperature_mv - 500.0) / 10.0 # self-heating correction temperature = (temperature - 4.0) - (0.017*current**2 + 0.631*current) temperature = round(temperature, 2) # Update channels: self.property_set("light", Sample(0, light, "brightness")) self.property_set("temperature", Sample(0, temperature, "C")) self.property_set("current", Sample(0, current, "A")) # check the realtime clock and compare to the last power_on_time # turn off if the idle_off_setting has been met or exceeded idle_off_setting = SettingsBase.get_setting(self, "idle_off_seconds") if (power_state and idle_off_setting > 0): if ((time.time() - self.__power_on_time) >= idle_off_setting): power_on_state_bool = self.property_get("power_on") power_on_state_bool.value = False self.prop_set_power_control(power_on_state_bool)
def _sample_indication(self, buf, addr): """\ Receive and parse an I/O sample """ self.__tracer.debug('Sample indication') io_sample = parse_is(buf) # Calculate channel values: light_mv, temperature_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2")) light = round(light_mv) temperature = round((temperature_mv - 500.0) / 10.0 - 4.0, 2) # Update channels: self.property_set("light", Sample(0, light, "brightness")) self.property_set("temperature", Sample(0, temperature, "C"))
def sample_indication(self, buf, addr): # Parse the I/O sample: io_sample = parse_is(buf) # Calculate channel values: # upbutton_mv, onbutton_mv, downbutton_mv = \ # map(lambda cn: sample_to_mv(io_sample[cn]), ("AD0", "AD1", "AD2")) # Calculate sensor channel values: if io_sample.has_key("AD1") and io_sample.has_key("AD2") and io_sample.has_key("AD3"): light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) up = round(light_mv, 2) on = round(temperature_mv, 2) down = round(humidity_mv, 2) power_state = self.property_get("power_on").value # Update channels: self.property_set("up", Sample(0, up, "mv")) self.property_set("on", Sample(0, on, "mv")) self.property_set("down", Sample(0, down, "mv")) # wire up any inputs input_source = SettingsBase.get_setting(self, 'input_source') cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cdb = cm.channel_database_get() # cp.subscribe(input_source, self.prop_set_input) # try: # source_name = SettingsBase.get_setting(self, 'input_source') source_name = self.property_get("user_input_1").value if( source_name != None): source_chan = cdb.channel_get( source_name) # pre-load the starting value, which won't be published to us self.my_input = source_chan.get().value # self.property_set("adder_reg2", Sample(0, my_input)) self.property_set("utemp", Sample(0, self.my_input, "F"))
def sample_indication(self, buf, addr): msg = [] # Parse the I/O sample: io_sample = parse_is(buf) # Calculate sensor channel values: if io_sample.has_key("AD1") and io_sample.has_key("AD2") and io_sample.has_key("AD3"): light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) # # handle temperature - first as celsius # scale = "C" temperature = (temperature_mv - 500.0) / 10.0 if not SettingsBase.get_setting(self, "sleep"): # self-heating correction if running full-time - reduce 2 DegC temperature -= 2.0 temperature = round(temperature, 2) self.property_set("temperature", Sample(0, temperature, scale)) msg.append( "%d %s" % (temperature, scale)) # # handle the light value # light = round(light_mv,0) if light < 0: # clamp to be zero or higher light = 0 self.property_set("light", Sample(0, light, "brightness")) msg.append( ", %d brightness" % light) # # handle humidity - might be missing # if self.property_exists("humidity"): humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / 0.0062 if humidity < 0.0: # clamp to min of 0% humidity = 0.0 elif humidity > 100.0: # clamp to be max of 100% humidity = 100.0 self.property_set("humidity", Sample(0, humidity, "%")) msg.append( ", %d RH%%" % humidity) else: # it remains the original default humidity = 0 # Low battery check (attached to DIO11/P1): # Invert the signal it is actually not_low_battery: if io_sample.has_key("DIO11"): low_battery = not bool(io_sample["DIO11"]) if low_battery != bool(self.property_get("low_battery").value): self.property_set("low_battery", Sample(0, low_battery)) if low_battery: msg.append( ", low_battery") # try to keep memory use from dragging out self.__tracer.debug("".join(msg)) del msg return
def sample_indication(self, buf, addr): # if we haven't gotten initial state yet, ask for it if self.property_get('power_on').value == UNKNOWN_POWER_STATE: if not self._set_initial_power_state(): self.__tracer.warning('Power state unknown, ignoring ' 'sample indication.') return # Parse the I/O sample: io_sample = parse_is(buf) # Calculate channel values: light_mv, temperature_mv, current_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ('AD1', 'AD2', 'AD3')) light = round(light_mv, 0) if light < 0: # clamp to be zero or higher light = 0 power_state = Boolean(self.property_get("power_on").value) # TODO: CRA Max could you remove this offset code? Change to # clip at 0. if not power_state: self.offset = current_mv * (157.0 / 47.0) if self.offset >= 600.0: # Probably a current spike from flipping the power relay self.offset = 520.0 current = round((current_mv * (157.0 / 47.0) - self.offset) \ / 180.0 * 0.7071, 3) pf_adj = self.get_power_factor() # compute powerfactor adjusted current if 1.0 >= pf_adj and 0.0 <= pf_adj: current *= pf_adj if current <= 0.05: # Clip the noise at the bottom of this sensor: current = 0.0 temperature = (temperature_mv - 500.0) / 10.0 # self-heating correction temperature = (temperature - 4.0) - \ (0.017 * current ** 2 + 0.631 * current) temperature = round(temperature, 2) # Update channels: self.property_set("light", Sample(0, light, "brightness")) self.property_set("temperature", Sample(0, temperature, "C")) self.property_set("current", Sample(0, current, "A")) self.__tracer.debug('Power:%r light:%d %0.1fC %0.2fA', power_state, light, temperature, current) # check the realtime clock and compare to the last power_on_time # turn off if the idle_off_setting has been met or exceeded idle_off_setting = SettingsBase.get_setting(self, "idle_off_seconds") if (power_state and idle_off_setting > 0): if ((digitime.time() - self.__power_on_time) \ >= idle_off_setting): power_on_state_bool = self.property_get("power_on") power_on_state_bool.value = False self.prop_set_power_control(power_on_state_bool) self.__tracer.debug('Idle Off True')
def sample_indication(self, buf, addr): # check if we want to scroll a trace line or not do_trace = SettingsBase.get_setting(self, "trace") if do_trace: msg = ['XBeeSensor(%s): ' % self.__name] # Parse the I/O sample: io_sample = parse_is(buf) # Calculate sensor channel values: if io_sample.has_key("AD1") and io_sample.has_key("AD2") and io_sample.has_key("AD3"): light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) # # handle temperature - first as celsius # scale = "F" temperature = temperature_mv if not SettingsBase.get_setting(self, "sleep"): # self-heating correction if running full-time - reduce 2 DegC temperature -= .001 temperature = round(temperature, 2) #self.property_set("motion", Sample(0, temperature, scale)) #if do_trace: # msg.append( "%d %s" % (temperature, scale)) # # handle the light value # light = round((light_mv / 10), 2) if light < 0: # clamp to be zero or higher light = 0 self.property_set("temperature", Sample(0, light, "F")) # if do_trace: # msg.append( ", %d brightness" % light) # # handle humidity - might be missing # if self.property_exists("humidity"): humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / 0.0062 if humidity < 0.0: # clamp to min of 0% humidity = 0.0 elif humidity > 100.0: # clamp to be max of 100% humidity = 100.0 self.property_set("humidity", Sample(0, humidity, "%")) if do_trace: msg.append( ", %d RH%%" % humidity) else: # it remains the original default humidity = 0 activate = self.property_get("power_on").value # Low battery check (attached to DIO11/P1): # Invert the signal it is actually not_low_battery: if io_sample.has_key("DIO2") and activate: low_battery = not bool(io_sample["DIO2"]) if low_battery != bool(self.property_get("low_battery").value): self.property_set("low_battery", Sample(0, low_battery)) if do_trace: if low_battery: msg.append( ", low_battery") # try to keep memory use from dragging out msg = "".join( msg) print msg del msg temp = self.property_get("temperature").value SettingsBase.set_pending_setting(self, 'temp', temp) motion = self.property_get("low_battery").value if activate and motion: self.property_set("motion_event", Sample(0, Boolean(True, style=STYLE_ONOFF))) else: self.property_set("motion_event", Sample(0, Boolean(False, style=STYLE_ONOFF))) return
def sample_indication(self, buf, addr): # wire up any inputs # input_source = SettingsBase.get_setting(self, 'input_source') cm = self.__core.get_service("channel_manager") cp = cm.channel_publisher_get() cdb = cm.channel_database_get() # cp.subscribe(input_source, self.prop_set_input) # try: # source_name = SettingsBase.get_setting(self, 'input_source') source_name = self.property_get("user_input_1").value if( source_name != None): source_chan = cdb.channel_get( source_name) # pre-load the starting value, which won't be published to us self.my_input = source_chan.get().value # self.property_set("adder_reg2", Sample(0, my_input)) self.property_set("driving_temp", Sample(0, self.my_input, "F")) # self.property_set("input", Sample(0, self.my_input)) # cp.subscribe(source_name, self.update_power_state1) # cp.subscribe( source_name, self.prop_set_input ) # self.property_set("2_high", Sample(0, 1.0)) # Parse the I/O sample: io_sample = parse_is(buf) # Calculate channel values: # upbutton_mv, onbutton_mv, downbutton_mv = \ # map(lambda cn: sample_to_mv(io_sample[cn]), ("AD0", "AD1", "AD2")) if io_sample.has_key("AD0") and io_sample.has_key("AD1") and io_sample.has_key("AD2"): light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD0", "AD1", "AD2")) up = (round(temperature_mv, 2)) / 10 red_light = round(light_mv) # on = round(temperature_mv, 2) # down = round(humidity_mv, 2) # power_state = self.property_get("power_on").value # Update channels: self.property_set("temperature", Sample(0, up, "F")) self.property_set("red_light", Sample(0, red_light, "mv")) # self.property_set("on", Sample(0, on, "mv")) # self.property_set("down", Sample(0, down, "mv")) red = self.property_get("red_light").value heat = self.property_get("heat").value old = self.property_get("switch_to_old").value on = self.property_get("heat_ac_on").value old_on = self.property_get("old_thermostat_on").value if red_light < 100.0 and old_on: self.property_set("old_thermostat_on", Sample(0, Boolean(False, style=STYLE_ONOFF))) if red_light > 100.0 and not old_on: self.old_thermostat(Sample(0, Boolean("on", STYLE_ONOFF))) # if red_light > 100.0 and not old_on: # self.old_thermostat(Sample(0, Boolean("on", STYLE_ONOFF))) # self.property_set("2_low", Sample(0, 1.0)) # if red_light < 100 and old: # self.property_set("switch_to_old", Sample(0, Boolean(False, style=STYLE_ONOFF))) # self.property_set("old_thermostat_on", Sample(0, Boolean(False, style=STYLE_ONOFF))) # # if red_light < 100 and old_on: # self.property_set("switch_to_old", Sample(0, Boolean(False, style=STYLE_ONOFF))) # self.property_set("old_thermostat_on", Sample(0, Boolean(False, style=STYLE_ONOFF))) driving = self.property_get("driving_temp").value des_temp = self.property_get("desired_temp").value ac = self.property_get("AC").value temp_plus = des_temp + 0.5 temp_minus = des_temp - 0.5 if heat and on and driving > temp_plus: self.prop_set_power_control2_low(Sample(0, Boolean("on", STYLE_ONOFF))) time.sleep(0.75) self.prop_set_power_control2_low(Sample(0, Boolean("off", STYLE_ONOFF))) # self.property_set("2_low", Sample(0, 1.0)) if heat and not on and driving < temp_minus: self.prop_set_power_control2_high(Sample(0, Boolean("on", STYLE_ONOFF))) time.sleep(0.75) self.prop_set_power_control2_high(Sample(0, Boolean("off", STYLE_ONOFF))) if ac and not on and driving > temp_plus: self.prop_set_power_control2_high(Sample(0, Boolean("on", STYLE_ONOFF))) time.sleep(0.75) self.prop_set_power_control2_high(Sample(0, Boolean("off", STYLE_ONOFF))) # self.property_set("2_low", Sample(0, 1.0)) if ac and on and driving < temp_minus: self.prop_set_power_control2_low(Sample(0, Boolean("on", STYLE_ONOFF))) time.sleep(0.75) self.prop_set_power_control2_low(Sample(0, Boolean("off", STYLE_ONOFF))) # self.property_set("2_high", Sample(0, 1.0)) time.sleep(5.0)
def sample_indication(self, buf, addr): # check if we want to scroll a trace line or not if self.count == 720: self.get_signal() if self.count == 720: self.count = 0 if self.count < 722: self.count += 1 do_trace = SettingsBase.get_setting(self, "trace") if do_trace: msg = ['XBeeSensor(%s): ' % self.__name] # Parse the I/O sample: io_sample = parse_is(buf) # Calculate sensor channel values: if io_sample.has_key("AD1") and io_sample.has_key("AD2") and io_sample.has_key("AD3"): light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) # # handle temperature - first as celsius # scale = self.include_unit temperature = (((((temperature_mv - 500.0) / 10.0) * (1.8) ) + 32) + 2.6) if not SettingsBase.get_setting(self, "sleep"): # self-heating correction if running full-time - reduce 2 DegC temperature -= 2.0 temperature = round(temperature, 2) self.property_set("temperature", Sample(0, temperature, scale)) if do_trace: msg.append( "%d %s" % (temperature, scale)) # # handle the light value # light = round(light_mv,0) if light < 0: # clamp to be zero or higher light = 0 self.property_set("light", Sample(0, light, "brightness")) if do_trace: msg.append( ", %d brightness" % light) # # handle humidity - might be missing # if self.property_exists("humidity"): humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / 0.0062 if humidity < 0.0: # clamp to min of 0% humidity = 0.0 elif humidity > 100.0: # clamp to be max of 100% humidity = 100.0 self.property_set("humidity", Sample(0, humidity, "%")) if do_trace: msg.append( ", %d RH%%" % humidity) else: # it remains the original default humidity = 0 # Low battery check (attached to DIO11/P1): # Invert the signal it is actually not_low_battery: if io_sample.has_key("DIO11"): low_battery = not bool(io_sample["DIO11"]) if low_battery != bool(self.property_get("low_battery").value): self.property_set("low_battery", Sample(0, low_battery)) if do_trace: if low_battery: msg.append( ", low_battery") # try to keep memory use from dragging out msg = "".join( msg) print msg del msg excl = self.property_get("excl").value if excl: self.property_set("excl", Sample(0, value=Boolean(bool(0), style=STYLE_ONOFF))) return
def sample_indication(self, buf, addr): # save time of last data, plus we want ALL of the samples to have # exact same timestamp (leaving 0 means some may be 1 second newer) self._last_timestamp = digitime.time() if self.__tracer.info(): msg = [] else: msg = None # Parse the I/O sample: io_sample = parse_is(buf) # Calculate sensor channel values: if "AD1" in io_sample and "AD2" in io_sample and \ "AD3" in io_sample: light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) # # handle temperature - first as celsius # scale = "C" temperature = (temperature_mv - 500.0) / 10.0 if not SettingsBase.get_setting(self, "sleep"): # self-heating correction if running full-time - reduce 2 DegC temperature -= 2.0 temperature = round(temperature, 2) self.property_set("temperature", Sample(self._last_timestamp, temperature, scale)) if msg is not None: msg.append("%d %s" % (temperature, scale)) # # handle the light value # light = round(light_mv, 0) if light < 0: # clamp to be zero or higher light = 0 self.property_set("light", Sample(self._last_timestamp, light, "brightness")) if msg is not None: msg.append(", %d brightness" % light) # # handle humidity - might be missing # if self.property_exists("humidity"): humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / \ 0.0062 if humidity < 0.0: # clamp to min of 0% humidity = 0.0 elif humidity > 100.0: # clamp to be max of 100% humidity = 100.0 self.property_set("humidity", Sample(self._last_timestamp, humidity, "%")) if msg is not None: # cannot use %% in string, __tracer will misunderstand msg.append(", %d RH" % humidity) else: # it remains the original default humidity = 0 # Low battery check (attached to DIO11/P1): # Invert the signal it is actually not_low_battery: if "DIO11" in io_sample: low_battery = not bool(io_sample["DIO11"]) if low_battery != bool(self.property_get("low_battery").value): self.property_set("low_battery", Sample(self._last_timestamp, low_battery)) if low_battery and msg is not None: msg.append(", low_battery") # try to keep memory use from dragging out if msg is not None: self.__tracer.info("".join(msg)) del msg return
def sample_indication(self, buf, addr): self._tracer.calls("XBeeRPM.sample_indication()") # save time of last data, plus we want ALL of the samples to have # exact same timestamp (leaving 0 means some may be 1 second newer) self._last_timestamp = digitime.time() # new method for mesh health monitoring self.set_time_of_last_data(self._last_timestamp) # if we haven't gotten initial state yet, ask for it if self.property_get('power_on').value == UNKNOWN_POWER_STATE: if not self._set_initial_power_state(): self._tracer.warning('Power state unknown, ignoring ' 'sample indication.') return # Parse the I/O sample: io_sample = parse_is(buf) # Calculate channel values: light_mv, temperature_mv, current_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ('AD1', 'AD2', 'AD3')) light = round(light_mv, 0) if light < 0: # clamp to be zero or higher light = 0 power_state = Boolean(self.property_get("power_on").value, style=STYLE_ONOFF) # TODO: CRA Max could you remove this offset code? Change to # clip at 0. if not power_state: self.offset = current_mv * (157.0 / 47.0) if self.offset >= 600.0: # Probably a current spike from flipping the power relay self.offset = 520.0 current = round((current_mv * (157.0 / 47.0) - self.offset) \ / 180.0 * 0.7071, 3) pf_adj = self.get_power_factor() # compute powerfactor adjusted current if 1.0 >= pf_adj and 0.0 <= pf_adj: current *= pf_adj if current <= 0.05: # Clip the noise at the bottom of this sensor: current = 0.0 temperature = (temperature_mv - 500.0) / 10.0 # self-heating correction temperature = (temperature - 4.0) - \ (0.017 * current ** 2 + 0.631 * current) if SettingsBase.get_setting(self, "degf"): temperature = (temperature * 1.8) + 32.0 units = 'F' else: units = 'C' temperature = round(temperature, 2) # Update channels: self.property_set("light", Sample(self._last_timestamp, light, "brightness")) self.property_set("temperature", Sample(self._last_timestamp, temperature, units)) self.property_set("current", Sample(self._last_timestamp, current, "A")) ## Check if sample has information about the power state if io_sample.has_key('AD4'): ## Define it as a boolean compare_state = Boolean(io_sample['AD4'], style=STYLE_ONOFF) ## compare to current power_state if not compare_state == power_state: ## It's different, set the power state to the new value self._tracer.warning("Power state was: %s, but now it is: %s" % (power_state, compare_state)) self._tracer.warning("Returning power state to: %s" % (power_state)) self.prop_set_power_control(Sample(0, str(power_state))) if self._tracer.info(): self._tracer.info('Power:%r light:%d %0.1f%s %0.2fA', power_state, light, temperature, units, current) # check the realtime clock and compare to the last power_on_time # turn off if the idle_off_setting has been met or exceeded idle_off_setting = SettingsBase.get_setting(self, "idle_off_seconds") if (power_state and idle_off_setting > 0): if ((digitime.time() - self.__power_on_time) \ >= idle_off_setting): power_on_state_bool = self.property_get("power_on") power_on_state_bool.value = False self.prop_set_power_control(power_on_state_bool) self._tracer.debug('Idle Off True')
def sample_indication(self, buf, addr): self._tracer.calls("XBeeSensor.sample_indication()") # save time of last data, plus we want ALL of the samples to have # exact same timestamp (leaving 0 means some may be 1 second newer) self._last_timestamp = digitime.time() # new method for mesh health monitoring self.set_time_of_last_data(self._last_timestamp) if self._tracer.info(): msg = [] else: msg = None # Parse the I/O sample: io_sample = parse_is(buf) # Calculate sensor channel values: if "AD1" in io_sample and "AD2" in io_sample and \ "AD3" in io_sample: light_mv, temperature_mv, humidity_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2", "AD3")) # # handle temperature - first as celsius # temperature = (temperature_mv - 500.0) / 10.0 if not SettingsBase.get_setting(self, "sleep"): # self-heating correction if running full-time - reduce 2 DegC temperature -= 2.0 if SettingsBase.get_setting(self, "degf"): temperature = (temperature * 1.8) + 32.0 units = 'F' else: units = 'C' # offset is a simple float value - we don't care if DegC or DegF temperature += SettingsBase.get_setting(self, "offset") temperature = round(temperature, 2) self.property_set("temperature", Sample(self._last_timestamp, temperature, units)) if msg is not None: msg.append("%d %s" % (temperature, units)) # # handle the light value # light = round(light_mv, 0) if light < 0: # clamp to be zero or higher light = 0 self.property_set( "light", Sample(self._last_timestamp, light, "brightness")) if msg is not None: msg.append(", %d brightness" % light) # # handle humidity - might be missing # if self.property_exists("humidity"): humidity = ((humidity_mv * 108.2 / 33.2) / 5000.0 - 0.16) / \ 0.0062 if humidity < 0.0: # clamp to min of 0% humidity = 0.0 elif humidity > 100.0: # clamp to be max of 100% humidity = 100.0 self.property_set("humidity", Sample(self._last_timestamp, humidity, "%")) if msg is not None: # cannot use %% in string, __tracer will misunderstand msg.append(", %d RH" % humidity) else: # it remains the original default humidity = 0 # Low battery check (attached to DIO11/P1): # Invert the signal it is actually not_low_battery: if "DIO11" in io_sample: low_battery = not bool(io_sample["DIO11"]) if low_battery != bool(self.property_get("low_battery").value): self.property_set("low_battery", Sample(self._last_timestamp, low_battery)) if low_battery and msg is not None: msg.append(", low_battery") # try to keep memory use from dragging out if msg is not None: self._tracer.info("".join(msg)) del msg return
def sample_indication(self, buf, addr): excl = self.property_get("excl").value if excl: self.property_set("excl", Sample(0, value=Boolean(bool(0), style=STYLE_ONOFF))) # Parse the I/O sample: extended_address = SettingsBase.get_setting(self, "extended_address") if self.count > 20: try: db = self.__xbee_manager.xbee_device_ddo_get_param(extended_address, "DB", use_cache=True) # sv = self.__xbee_manager.xbee_device_ddo_get_param(extended_address, # "%V", use_cache=True) try: dd = struct.unpack(">B", db) #print dd except: self.property_set("signal", Sample(0, value="0", unit="")) print "failed 4" # try: # sv = struct.unpack(">H", sv) # except: # self.property_set("volts", Sample(0, value="failed", unit="")) # print sv dd = str(dd) dd = dd[1:3] dd = "-" + dd + " dB" # print "signal strength =" # print dd self.property_set("signal", Sample(0, value=str(dd), unit="")) # sv = str(sv) # sv = sv[1:5] # sv = int(sv) # print sv # volts = (sv * 1.1719) / 1000 # print "volts =" # print volts # self.property_set("volts", Sample(0, value=str(volts), unit="")) except: self.property_set("signal", Sample(0, value="disconnected", unit="")) print "failed to get signal and voltage" if self.count < 22: self.count += 1 io_sample = parse_is(buf) # Calculate channel values: light_mv, temperature_mv = \ map(lambda cn: sample_to_mv(io_sample[cn]), ("AD1", "AD2")) light = round(light_mv) temperature = round((((temperature_mv - 500.0) / 10.0 - 4.0)) * 1.8 + 32, 2) # Update channels: self.property_set("light", Sample(0, light, "brightness")) self.property_set("temperature", Sample(0, temperature, self.include_unit))