def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ # ~ self.kernel_modprobe('i2c-dev') # ~ self.kernel_modprobe('i2c-bcm2708') JNTBus.__init__(self, **kwargs) # ~ self._i2c_lock = threading.Lock() # ~ self.load_extensions(OID) # ~ self._ada_i2c = I2C # ~ """ The shared ADAFruit I2C bus """ # ~ self.export_attrs('i2c_acquire', self.i2c_acquire) # ~ self.export_attrs('i2c_release', self.i2c_release) # ~ self.export_attrs('get_i2c_device', self.get_i2c_device) # ~ self.export_attrs('get_busnum', self.get_busnum) # ~ self.export_attrs('get_adafruit_i2c', self.get_adafruit_i2c) # ~ self.export_attrs('software_reset', self.software_reset) # ~ self.export_attrs('require_repeated_start', self.require_repeated_start) uuid = "%s_busnum" % OID self.values[uuid] = self.value_factory['config_integer']( options=self.options, uuid=uuid, node_uuid=self.uuid, help='The I2C bus number to use. Set it to None to get default bus', label='BusNum', default=None, )
def stop(self): """Stop the bus """ self.stop_check() for bus in self.buses: self.buses[bus].stop() JNTBus.stop(self)
def start(self, mqttc, trigger_thread_reload_cb=None, **kwargs): """Start the bus """ if hasattr(self, "get_graph"): delattr(self, "get_graph") self._fsm = self.create_fsm() JNTBus.start(self, mqttc, trigger_thread_reload_cb, **kwargs) try: self._fsm_slow_start = self.nodeman.slow_start * len(self.get_components()) except Exception: self._fsm_slow_start = self.nodeman.slow_start logger.info("[%s] - Can't set slow_start. Using default value %s", self.__class__.__name__, self._fsm_slow_start, exc_info=True) try: self._fsm_timer_delay = self.options.get_option(self.oid, 'fsm_timer_delay', default=self._fsm_timer_delay) except Exception: logger.info("[%s] - Can't set fsm_timer_delay from configuration file. Using default value %s", self.__class__.__name__, self._fsm_timer_delay, exc_info=True) try: self._fsm_max_retries = self.options.get_option(self.oid,'fsm_max_retries', default=self._fsm_max_retries) except Exception: logger.info("[%s] - Can't set fsm_max_retries from configuration file. Using default value %s", self.__class__.__name__, self._fsm_max_retries, exc_info=True) self._fsm_boot_lock.acquire() try: self.stop_boot_timer() logger.debug("[%s] - Will boot fsm in %s seconds", self.__class__.__name__, self._fsm_timer_delay + self._fsm_slow_start) self._fsm_boot_timer = threading.Timer(self._fsm_timer_delay + self._fsm_slow_start, self.on_boot_timer) self._fsm_boot_timer.start() except Exception: logger.exception("[%s] - Error when trying to boot fsm at try %s", self.__class__.__name__, self._fsm_retry) finally: self._fsm_boot_lock.release()
def start(self, mqttc, trigger_thread_reload_cb=None): """Start the bus """ for bus in self.buses: self.buses[bus].start(mqttc, trigger_thread_reload_cb=None) JNTBus.start(self, mqttc, trigger_thread_reload_cb) self._statemachine = self.create_fsm()
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._camera_lock = threading.Lock() self.camera = None uuid = "%s_led" % OID self.values[uuid] = self.value_factory["config_boolean"]( options=self.options, uuid=uuid, node_uuid=self.uuid, help="Led state", label="led", default=True ) uuid = "%s_actions" % OID self.values[uuid] = self.value_factory["action_list"]( options=self.options, uuid=uuid, node_uuid=self.uuid, help="The actions on the camera", label="Actions", list_items=["start_preview", "stop_preview"], set_data_cb=self.rpicamera_set_action, is_writeonly=True, cmd_class=COMMAND_CAMERA_PREVIEW, genre=0x01, ) self.export_attrs("camera_acquire", self.camera_acquire) self.export_attrs("camera_release", self.camera_release) self.export_attrs("camera", self.camera)
def start(self, mqttc, trigger_thread_reload_cb=None): """Start the bus """ for bus in self.buses: self.buses[bus].start(mqttc, trigger_thread_reload_cb=None) JNTBus.start(self, mqttc, trigger_thread_reload_cb) self.on_check()
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._spi_lock = threading.Lock() self.load_extensions(OID) self._ada_gpio = None try: self._ada_gpio = GPIO.get_platform_gpio() except : logger.exception("[%s] - Can't get GPIO", self.__class__.__name__) self._ada_spi = None try: self._ada_spi = SPI except : logger.exception("[%s] - Can't get SPI", self.__class__.__name__) self.export_attrs('_ada_spi', self._ada_spi) self.export_attrs('_ada_gpio', self._ada_gpio) self.export_attrs('spi_acquire', self.spi_acquire) self.export_attrs('spi_release', self.spi_release) self.export_attrs('spi_locked', self.spi_locked) self.export_attrs('get_spi_device', self.get_spi_device) self.export_attrs('get_spi_device_pin', self.get_spi_device_pin)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._spi_lock = threading.Lock() self.load_extensions(OID) self._ada_gpio = None try: self._ada_gpio = GPIO.get_platform_gpio() except: logger.exception("[%s] - Can't get GPIO", self.__class__.__name__) self._ada_spi = None try: self._ada_spi = SPI except: logger.exception("[%s] - Can't get SPI", self.__class__.__name__) self.export_attrs('_ada_spi', self._ada_spi) self.export_attrs('_ada_gpio', self._ada_gpio) self.export_attrs('spi_acquire', self.spi_acquire) self.export_attrs('spi_release', self.spi_release) self.export_attrs('spi_locked', self.spi_locked) self.export_attrs('get_spi_device', self.get_spi_device) self.export_attrs('get_spi_device_pin', self.get_spi_device_pin)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ oid = kwargs.pop('oid', 'fake') JNTBus.__init__(self, oid=oid, **kwargs)
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self.lock = threading.Lock() self.mifare = None
def start(self, mqttc, trigger_thread_reload_cb=None): JNTBus.start(self, mqttc, trigger_thread_reload_cb) self.store = RrdStoreThread("datarrd_store", self.options.data) self.store.config_thread(cache_rrd_ttl=self.values["cache_rrd_ttl"].data, cache_pickle_ttl=self.values["cache_pickle_ttl"].data, cache_dead_ttl=self.values["cache_dead_ttl"].data) self.store.start()
def start(self, mqttc, trigger_thread_reload_cb=None): """Start the bus """ JNTBus.start(self, mqttc, trigger_thread_reload_cb) try: self.mifare = nxppy.Mifare() except: logger.exception("Exception when starting NXP bus")
def stop(self): """Stop the bus """ #~ try: #~ self.mifare = None #~ except: #~ logger.exception("Exception when stopping NXP bus") JNTBus.stop(self)
def stop(self): """Stop the bus """ try: self.mifare = None except: logger.exception("Exception when stopping NXP bus") JNTBus.stop(self)
def start(self, mqttc, trigger_thread_reload_cb=None): """Start the bus """ JNTBus.start(self, mqttc, trigger_thread_reload_cb) try: self.gpio = GPIO.get_platform_gpio() except Exception: logger.exception("[%s] - Exception when starting GPIO bus", self.__class__.__name__) self.update_attrs('gpio', self.gpio)
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._sound_lock = threading.Lock() self.load_extensions(OID) self.export_attrs('sound_acquire', self.sound_acquire) self.export_attrs('sound_release', self.sound_release) self.export_attrs('sound_locked', self.sound_locked)
def stop(self): """Stop the bus """ JNTBus.stop(self) try: self.gpio.cleanup() except Exception: logger.exception("[%s] - Exception when stopping GPIO bus", self.__class__.__name__) self.gpio = None self.update_attrs('gpio', self.gpio)
def stop(self): """ """ JNTBus.stop(self) if self.camera is not None: try: self.camera.close() except Exception: logger.exception("[%s] - an't start component camera", self.__class__.__name__) self.camera = None self.update_attrs("camera", self.camera)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._tellstick_lock = threading.Lock() self._lock_delay = 0.25 self.load_extensions(OID) self.cant_aggregate(OID) self.sensors = {}
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ self.kernel_modprobe('i2c-dev') self.kernel_modprobe('i2c-bcm2708') JNTBus.__init__(self, **kwargs) self._i2c_lock = threading.Lock() self.load_extensions(OID) self._ada_i2c = I2C """ The shared ADAFruit I2C bus """ self.export_attrs('i2c_acquire', self.i2c_acquire) self.export_attrs('i2c_release', self.i2c_release)
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ self.kernel_modprobe('w1-gpio') self.kernel_modprobe('w1-therm') JNTBus.__init__(self, **kwargs) uuid="%s_sensors_dir"%OID self.values[uuid] = self.value_factory['config_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The sensor directory', label='dir.', default='/sys/bus/w1/devices/', )
def __init__(self, **kwargs): """ :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._lock = threading.Lock() self.gpio = None uuid="%s_boardmode"%OID self.values[uuid] = self.value_factory['config_list'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The board mode to use', label='Boardmode', default='BOARD', list_items=['BCM', 'BOARD'], ) self.export_attrs('gpio', self.gpio)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['1wire'] = OnewireBus(masters=[self], **kwargs) uuid="{:s}_temperature".format(OID) self.values[uuid] = self.value_factory['sensor_temperature'](options=self.options, uuid=uuid, node_uuid=self.uuid, get_data_cb=self.get_temperature_cb, help='The average temperature of tutorial. Can be use as a good quality source for a thermostat.', label='Temp', ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value
def stop(self, **kwargs): """Stop the bus """ if hasattr(self, "halt"): self.halt() if hasattr(self, "get_graph"): delattr(self, "get_graph") self._fsm_boot_lock.acquire() event = kwargs.get('event', threading.Event()) logger.info("[%s] - Stop the node manager with event %s", self.__class__.__name__, event) try: self.stop_boot_timer() finally: self._fsm_boot_lock.release() event.wait(0.25) self._fsm = None JNTBus.stop(self, **kwargs)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['camera'] = CameraBus(masters=[self], **kwargs) self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['spibus'] = SPIBus(masters=[self], **kwargs) self.buses['i2cbus'] = I2CBus(masters=[self], **kwargs) self._lapinoo_lock = threading.Lock() self.check_timer = None uuid="%s_timer_delay"%OID self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=45, )
def start(self, mqttc, trigger_thread_reload_cb=None): """Start the bus """ directory = self.get_public_directory() for didir in CAMERA_DIR: ndir = os.path.join(directory, didir) if not os.path.exists(ndir): os.makedirs(ndir) JNTBus.start(self, mqttc, trigger_thread_reload_cb) try: if self.camera_acquire(): self.camera = picamera.PiCamera() self.update_attrs("camera", self.camera) else: raise RuntimeError("Can't lock camera") except Exception: logger.exception("[%s] - Can't start component camera", self.__class__.__name__) finally: self.camera_release()
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['camera'] = CameraBus(masters=[self], **kwargs) self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['spibus'] = SPIBus(masters=[self], **kwargs) self.buses['i2cbus'] = I2CBus(masters=[self], **kwargs) self._lapinoo_lock = threading.Lock() self.check_timer = None uuid = "%s_timer_delay" % OID self.values[uuid] = self.value_factory['config_integer']( options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=45, )
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs) self._lock = threading.Lock() self._server = None if 'home_dir' in self.options.data and self.options.data['home_dir'] is not None: dirname = self.options.data['home_dir'] directory = os.path.join(dirname, 'public') if not os.path.exists(directory): os.makedirs(directory) uuid="host" self.values[uuid] = self.value_factory['config_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The host or IP to use for the server', label='Host', default='localhost', ) uuid="port" self.values[uuid] = self.value_factory['config_integer'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The port', label='Port', default=8081, ) uuid="actions" self.values[uuid] = self.value_factory['action_list'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The action on the HTTP server', label='Actions', list_items=['start', 'stop', 'reload'], set_data_cb=self.set_action, is_writeonly = True, cmd_class=COMMAND_WEB_CONTROLLER, genre=0x01, )
def __init__(self, **kwargs): """ :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """ JNTBus.__init__(self, **kwargs)
def stop(self): JNTBus.stop(self)
def start(self, mqttc, trigger_thread_reload_cb=None): JNTBus.start(self, mqttc, trigger_thread_reload_cb)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.buses = {} self.buses['gpiobus'] = GpioBus(masters=[self], **kwargs) self.buses['1wire'] = OnewireBus(masters=[self], **kwargs) self._statemachine = None self.check_timer = None uuid="{:s}_timer_delay".format(OID) self.values[uuid] = self.value_factory['config_float'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The delay between 2 checks', label='Timer.', default=30, ) uuid="{:s}_temperature_critical".format(OID) self.values[uuid] = self.value_factory['config_float'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The critical temperature. If 2 of the 3 temperature sensors are up to this value, a security notification is sent.', label='Critical', default=50, ) uuid="{:s}_temperature".format(OID) self.values[uuid] = self.value_factory['sensor_temperature'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='The average temperature of tutorial.', label='Temp', ) poll_value = self.values[uuid].create_poll_value(default=300) self.values[poll_value.uuid] = poll_value uuid="{:s}_overheat".format(OID) self.values[uuid] = self.value_factory['sensor_boolean'](options=self.options, uuid=uuid, node_uuid=self.uuid, help='Temperature overheat.', label='Overheat', default=False, ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value uuid="{:s}_transition".format(OID) self.values[uuid] = self.value_factory['transition_fsm'](options=self.options, uuid=uuid, node_uuid=self.uuid, list_items=[ v['trigger'] for v in self.transitions ], fsm_bus=self, ) poll_value = self.values[uuid].create_poll_value() self.values[poll_value.uuid] = poll_value uuid="{:s}_state".format(OID) self.values[uuid] = self.value_factory['sensor_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, genre=0x01, help='The state of the fsm.', get_data_cb = self.get_state, label='State', ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value self._bus_lock = threading.Lock() self.presence_events = {} self.state = "sleeping"
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs) self.states = [ 'booting', 'halted', 'sleeping', 'working', ] """The fsm states : - the first state must be booting - do what you want with the other ones. """ self.transitions = [ { 'trigger': 'boot', 'source': 'booting', 'dest': 'sleeping', }, { 'trigger': 'halt', 'source': '*', 'dest': 'halted', }, { 'trigger': 'sleep', 'source': '*', 'dest': 'sleeping', }, { 'trigger': 'work', 'source': '*', 'dest': 'working', }, ] """The fsm transitions - the first transition is used to get out the boot state : its a good idea to check values availability in ths trigger. - the second transition is used to stop the machine. - do what you want with the other ones. """ self._fsm = None """The finish state machine""" self._fsm_boot_timer = None """The timer that's start the finish state machine""" self._fsm_boot_lock = threading.Lock() """The timer that's start the finish state machine""" self._fsm_timer_delay = 3.1 """The timer delay between 2 retries""" self._fsm_max_retries = 5 """The max retries to boot the fsm""" self._fsm_retry = 0 """The current retry to boot the fsm""" self._fsm_slow_start = 0 """The slow delay to boot the fsm""" self.state = self.states[0] """Initial state of the fsm""" self._bus_lock = threading.Lock() """A lock for the bus""" uuid="{:s}_transition".format(self.oid) self.values[uuid] = self.value_factory['transition_fsm'](options=self.options, uuid=uuid, node_uuid=self.uuid, list_items=[ v['trigger'] for v in self.transitions ], fsm_bus=self, ) poll_value = self.values[uuid].create_poll_value() self.values[poll_value.uuid] = poll_value config_value = self.values[uuid].create_config_value(default=self.transitions[0]['trigger']) self.values[config_value.uuid] = config_value uuid="{:s}_state".format(self.oid) self.values[uuid] = self.value_factory['sensor_string'](options=self.options, uuid=uuid, node_uuid=self.uuid, genre = 0x01, get_data_cb = self.get_state, help='The state of the fsm.', label='State', ) poll_value = self.values[uuid].create_poll_value(default=60) self.values[poll_value.uuid] = poll_value
def start(self, mqttc, trigger_thread_reload_cb=None): JNTBus.start(self, mqttc, trigger_thread_reload_cb) self._server = HttpServerThread("http_server", self.options.data) self._server.config(host=self.values["host"].data, port=self.values["port"].data) self._server.start()
def stop(self): if self._server is not None: self._server.stop() self._server = None JNTBus.stop(self)
def __init__(self, **kwargs): """ """ JNTBus.__init__(self, **kwargs)