Esempio n. 1
0
    def __init__(self, config, sensors):
        self.conf = config
        self.sensors = sensors

        # check for mandatory configuration
        if 'mqtt_host' not in self.conf or 'enocean_port' not in self.conf:
            raise Exception(
                "Mandatory configuration not found: mqtt_host/enocean_port")
        mqtt_port = int(
            self.conf['mqtt_port']) if 'mqtt_port' in self.conf else 1883
        mqtt_keepalive = int(self.conf['mqtt_keepalive']
                             ) if 'mqtt_keepalive' in self.conf else 0
        self.mqtt_prefix = self.conf['mqtt_prefix']

        # setup mqtt connection
        client_id = self.conf[
            'mqtt_client_id'] if 'mqtt_client_id' in self.conf else ''
        self.mqtt = mqtt.Client(client_id=client_id)
        self.mqtt.on_connect = self._on_connect
        self.mqtt.on_disconnect = self._on_disconnect
        self.mqtt.on_message = self._on_mqtt_message
        self.mqtt.on_publish = self._on_mqtt_publish
        if 'mqtt_user' in self.conf:
            logging.info("Authenticating: " + self.conf['mqtt_user'])
            self.mqtt.username_pw_set(self.conf['mqtt_user'],
                                      self.conf['mqtt_pwd'])
        if str(self.conf.get('mqtt_ssl')) in ("True", "true", "1"):
            logging.info("Enabling SSL")
            ca_certs = self.conf[
                'mqtt_ssl_ca_certs'] if 'mqtt_ssl_ca_certs' in self.conf else None
            certfile = self.conf[
                'mqtt_ssl_certfile'] if 'mqtt_ssl_certfile' in self.conf else None
            keyfile = self.conf[
                'mqtt_ssl_keyfile'] if 'mqtt_ssl_keyfile' in self.conf else None
            self.mqtt.tls_set(ca_certs=ca_certs,
                              certfile=certfile,
                              keyfile=keyfile)
            if str(self.conf.get('mqtt_ssl_insecure')) in ("True", "true",
                                                           "1"):
                logging.warning("Disabling SSL certificate verification")
                self.mqtt.tls_insecure_set(True)
        if str(self.conf.get('mqtt_debug')) in ("True", "true", "1"):
            self.mqtt.enable_logger()
        logging.debug("Connecting to host " + self.conf['mqtt_host'] +
                      ", port " + str(mqtt_port) + ", keepalive " +
                      str(mqtt_keepalive))
        self.mqtt.connect_async(self.conf['mqtt_host'],
                                port=mqtt_port,
                                keepalive=mqtt_keepalive)
        self.mqtt.loop_start()

        # setup enocean communication
        try:
            self.enocean = SerialCommunicator(self.conf['enocean_port'])
        except serial.serialutil.SerialException:
            logging.exception('Serial Error')
            sys.exit(1)
        self.enocean.start()
        # sender will be automatically determined
        self.enocean_sender = None
 def __init__(self, hass, ser):
     """Initialize the EnOcean dongle."""
     from enocean.communicators.serialcommunicator import SerialCommunicator
     self.__communicator = SerialCommunicator(port=ser,
                                              callback=self.callback)
     self.__communicator.start()
     self.__devices = []
Esempio n. 3
0
def listen():
    jeedom_socket.open()
    logging.debug("Start listening...")
    globals.COMMUNICATOR = SerialCommunicator(port=_device)
    globals.COMMUNICATOR.start()
    if globals.COMMUNICATOR.base_id is None:
        logging.error("No base id from enocean key, shutdown")
        shutdown()

    logging.info('The Base ID of your controler is %s.' %
                 enocean.utils.to_hex_string(
                     globals.COMMUNICATOR.base_id).replace(':', ''))
    globals.JEEDOM_COM.send_change_immediate({
        'baseid':
        str(enocean.utils.to_hex_string(globals.COMMUNICATOR.base_id)).replace(
            ':', '')
    })
    packet = Packet(PACKET.COMMON_COMMAND, [0x03])
    globals.COMMUNICATOR.send(packet)
    try:
        thread.start_new_thread(read_socket, ('socket', ))
        logging.debug('Read Socket Thread Launched')
        thread.start_new_thread(read_communicator, ('read', ))
        logging.debug('Read Device Thread Launched')
    except KeyboardInterrupt:
        logging.error("KeyboardInterrupt, shutdown")
        shutdown()
Esempio n. 4
0
    def __init__(self, hass, ser):
        """Initialize the EnOcean dongle."""

        self.__communicator = SerialCommunicator(port=ser,
                                                 callback=self.callback)
        self.__communicator.start()
        self.hass = hass
        self.hass.helpers.dispatcher.dispatcher_connect(
            SIGNAL_SEND_MESSAGE, self._send_message_callback)
Esempio n. 5
0
    def __init__(self, config, sensors):
        self.conf = config
        self.sensors = sensors

        # check for mandatory configuration
        if 'mqtt_host' not in self.conf or 'enocean_port' not in self.conf:
            raise Exception(
                "Mandatory configuration not found: mqtt_host/enocean_port")
        mqtt_port = int(
            self.conf['mqtt_port']) if 'mqtt_port' in self.conf else 1883
        mqtt_keepalive = int(self.conf['mqtt_keepalive']
                             ) if 'mqtt_keepalive' in self.conf else 0

        # setup mqtt connection
        client_id = self.conf[
            'mqtt_client_id'] if 'mqtt_client_id' in self.conf else ''
        self.mqtt = mqtt.Client(client_id=client_id)
        self.mqtt.on_connect = self._on_connect
        self.mqtt.on_disconnect = self._on_disconnect
        self.mqtt.on_message = self._on_mqtt_message
        self.mqtt.on_publish = self._on_mqtt_publish
        if 'mqtt_user' in self.conf:
            logging.info("Authenticating: " + self.conf['mqtt_user'])
            self.mqtt.username_pw_set(self.conf['mqtt_user'],
                                      self.conf['mqtt_pwd'])
        if 'mqtt_ssl' in self.conf:
            logging.info("Enabling SSL")
            ca_certs = self.conf[
                'mqtt_ssl_ca_certs'] if 'mqtt_ssl_ca_certs' in self.conf else None
            certfile = self.conf[
                'mqtt_ssl_certfile'] if 'mqtt_ssl_certfile' in self.conf else None
            keyfile = self.conf[
                'mqtt_ssl_keyfile'] if 'mqtt_ssl_keyfile' in self.conf else None
            self.mqtt.tls_set(ca_certs=ca_certs,
                              certfile=certfile,
                              keyfile=keyfile)
            if 'mqtt_ssl_insecure' in self.conf:
                logging.warning("Disabling SSL certificate verification")
                self.mqtt.tls_insecure_set(True)
        self.mqtt.connect_async(self.conf['mqtt_host'],
                                port=mqtt_port,
                                keepalive=mqtt_keepalive)
        self.mqtt.loop_start()

        # setup enocean communication
        self.enocean = SerialCommunicator(self.conf['enocean_port'])
        self.enocean.start()
        # sender will be automatically determined
        self.enocean_sender = None
Esempio n. 6
0
    def __init__(self, port, callback):
        # Initialize parent class
        super(enOcean_link, self).__init__()

        # Set debug mode if needed
        # from enocean.consolelogger import init_logging
        # init_logging()

        # Set port
        try:
            self.c = SerialCommunicator(port=port, callback=callback)
            self.c.start()
        except:
            print("Error opening serial port (", port, ")")
            raise

        return
Esempio n. 7
0
    def __init__(self, hass, ser):
        """Initialize the EnOcean dongle."""
        super().__init__(self)
        self.hass = hass
        self.ser = ser
        self.communicator = None
        """Connect to serial port of the EnOcean dongle."""
        self.communicator = SerialCommunicator(
            port=self.ser, callback=self.communicator_callback)
        # switch off automated teach-in, as it gets caught in infinite loop for UTE
        self.communicator.teach_in = False
        self.communicator.start()
        self.dev_id = self.communicator.base_id
        _LOGGER.debug(f"[EnOceanDongle] self.dev_id: {self.dev_id}")

        unsubscribe_dispatcher = self.hass.helpers.dispatcher.async_dispatcher_connect(
            SIGNAL_SEND_PACKET, self.send_packet)
        self.hass.data[DOMAIN][DATA_DISPATCHERS].append(unsubscribe_dispatcher)
def main():
    global influxClient, communicator

    # init_logging()
    communicator = SerialCommunicator(port='/dev/ttyUSB0')
    communicator.start()

    logger.info('The Base ID of your module is %s.' %
                enocean.utils.to_hex_string(communicator.base_id))

    # connect to the database
    connect_to_ddbb()

    # endless loop receiving radio packets
    while communicator.is_alive():
        try:
            # Loop to empty the queue...
            packet = communicator.receive.get(block=True, timeout=1)

            # RORG: 0xA5, FUNC: 0x02, TYPE: 0x05, Manufacturer: 0x2D
            # 01:80:F5:BC->FF:FF:FF:FF (-74 dBm): 0x01 ['0xa5', '0x8', '0x28', '0x2d', '0x80', '0x1',

            if packet.packet_type == PACKET.RADIO:
                if packet.rorg == RORG.BS4 and packet.sender_hex in ENOCEAN_DEVICES:
                    meas = enocean_parse_and_publish(
                        packet, ENOCEAN_DEVICES[packet.sender_hex])

        except queue.Empty:
            continue
        except KeyboardInterrupt:
            logger.exception("Manually closing the application, exit")
            break
        except Exception as exc:
            logger.exception(exc)
            break

        time.sleep(0.1)

    # if we reached here, exit
    stop_application()
Esempio n. 9
0
    def __init__(self, config, sensors):
        self.conf = config
        self.sensors = sensors

        # setup mqtt connection
        self.mqtt = mqtt.Client()
        self.mqtt.on_connect = self._on_connect
        self.mqtt.on_disconnect = self._on_disconnect
        self.mqtt.on_message = self._on_mqtt_message
        self.mqtt.on_publish = self._on_mqtt_publish
        if 'mqtt_user' in self.conf:
            logging.info("Authenticating: " + self.conf['mqtt_user'])
            self.mqtt.username_pw_set(self.conf['mqtt_user'],
                                      self.conf['mqtt_pwd'])
        self.mqtt.connect(self.conf['mqtt_host'], int(self.conf['mqtt_port'],
                                                      0))
        self.mqtt.loop_start()

        # setup enocean communication
        self.enocean = SerialCommunicator(self.conf['enocean_port'])
        self.enocean.start()
        # sender will be automatically determined
        self.enocean_sender = None
Esempio n. 10
0
    def run(self):
        self.__wait()
        self.__get_comm()
        if self.comm is None:
            self.comm = SerialCommunicator(port=self.port,
                                           callback=self.__enqueue)
            logger.info("Starting EnOcean listener on port %s" % self.port)
            # Workaround for setting thread name coherent with plugin's thread name
            self.comm.name = self.name
            self.comm.start()
            if self.comm.base_id:
                logger.info("The Base ID of your module is %s" %
                            utils.to_hex_string(self.comm.base_id))
            self.__set_comm()
        self.__ready()
        self.__set_queue()

        while self.comm.is_alive():
            if self.queue.qsize() > 0:
                packet = self.queue.get()
                if hasattr(packet, 'sender_hex'):
                    if packet.sender_hex == self.addr:
                        self.decode(packet)
            time.sleep(1)
Esempio n. 11
0
except ImportError:
    import Queue as queue


def assemble_radio_packet(transmitter_id):
    return RadioPacket.create(rorg=RORG.BS4,
                              rorg_func=0x20,
                              rorg_type=0x01,
                              sender=transmitter_id,
                              CV=50,
                              TMP=21.5,
                              ES='true')


init_logging()
communicator = SerialCommunicator()
communicator.start()
print('The Base ID of your module is %s.' %
      enocean.utils.to_hex_string(communicator.base_id))

if communicator.base_id is not None:
    print('Sending example package.')
    communicator.send(assemble_radio_packet(communicator.base_id))

# endless loop receiving radio packets
while communicator.is_alive():
    try:
        # Loop to empty the queue...
        packet = communicator.receive.get(block=True, timeout=1)

        if packet.packet_type == PACKET.RADIO and packet.rorg == RORG.BS4:
Esempio n. 12
0
except ImportError:
    import Queue as queue


def assemble_radio_packet(transmitter_id):
    return RadioPacket.create(rorg=RORG.BS4,
                              rorg_func=0x20,
                              rorg_type=0x01,
                              sender=transmitter_id,
                              CV=50,
                              TMP=21.5,
                              ES='true')


init_logging()
communicator = SerialCommunicator(port="/dev/ttyUSB0")
communicator.start()
print('The Base ID of your module is %s.' %
      enocean.utils.to_hex_string(communicator.base_id))

if communicator.base_id is not None:
    print('Sending example package.')
    communicator.send(assemble_radio_packet(communicator.base_id))

# endless loop receiving radio packets
while communicator.is_alive():
    try:
        # Loop to empty the queue...
        packet = communicator.receive.get(block=True, timeout=1)

        if packet.packet_type == PACKET.RADIO and packet.rorg == RORG.BS4:
Esempio n. 13
0
from enocean import utils
import traceback
import sys

try:
    import queue
except ImportError:
    import Queue as queue

init_logging()
"""
'/dev/ttyUSB0' might change depending on where your device is.
To prevent running the app as root, change the access permissions:
'sudo chmod 777 /dev/ttyUSB0'
"""
communicator = SerialCommunicator(port=u'/dev/ttyUSB0', callback=None)
packet = Packet(PACKET.COMMON_COMMAND, [0x03])

communicator.daemon = True
communicator.start()
communicator.send(packet)

while communicator.is_alive():
    try:
        receivedPacket = communicator.receive.get(block=True, timeout=1)
        if receivedPacket.packet_type == PACKET.RESPONSE:
            print('Return Code: %s' %
                  utils.to_hex_string(receivedPacket.data[0]))
            print('APP version: %s' %
                  utils.to_hex_string(receivedPacket.data[1:5]))
            print('API version: %s' %
Esempio n. 14
0
def assemble_radio_packet(transmitter_id):
    # print(transmitter_id)
    # print(enocean.utils.from_hex_string('05:0F:11:A3'))
    return RadioPacket.create(
        rorg=RORG.VLD,
        rorg_func=0x01,
        rorg_type=0x0B,
        sender=transmitter_id,
        destination=enocean.utils.from_hex_string('05:0F:11:A3'),
        command=1,
        OV=100)


init_logging()
communicator = SerialCommunicator(port='/dev/ttyUSB0')
communicator.start()
print('The Base ID of your module is %s.' %
      enocean.utils.to_hex_string(communicator.base_id))

if communicator.base_id is not None:
    print('Sending example package.')
    communicator.send(assemble_radio_packet(communicator.base_id))

# endless loop receiving radio packets
while communicator.is_alive():
    try:
        # Loop to empty the queue...
        packet = communicator.receive.get(block=True, timeout=1)
        print(packet)
        if packet.packet_type == PACKET.RADIO_ERP1 and packet.rorg == RORG.VLD:
Esempio n. 15
0
 def __init__(self):
     self.communicator = SerialCommunicator(port='/dev/ttyUSB0')
     self.communicator.start()