Beispiel #1
0
 def setUp(self):
     self.messages = []
     self.serial = Serial(None, None)
     self.xbee = XBeeWrapper()
     self.xbee.default_port_name = 'serial'
     self.xbee.serial = self.serial
     self.xbee.on_message = self.on_message
     self.xbee.connect()
Beispiel #2
0
class TestXBee(unittest.TestCase):

    serial = None
    xbee = None
    messages = []

    def setUp(self):
        self.messages = []
        self.serial = Serial(None, None)
        self.xbee = XBeeWrapper()
        self.xbee.default_port_name = 'serial'
        self.xbee.serial = self.serial
        self.xbee.on_message = self.on_message
        self.xbee.connect()

    def tearDown(self):
        self.xbee.disconnect()

    def on_message(self, address, port, value):
        self.messages += [{
            'address': address,
            'port': port,
            'value': value
        }]

    def wait(self):
        while len(self.messages) == 0:
            time.sleep(.1)
        time.sleep(.1)
    def test_x90_malformed(self):
        self.serial.feed('900013a20040401122012340' + binascii.hexlify('AABBCCDD\n')) # Receive mal-formed serial packet
        self.wait()
        self.assertEquals(1, len(self.messages))
        self.assertEquals('0013a20040401122', self.messages[0]['address'])
        self.assertEquals('serial', self.messages[0]['port'])
        self.assertEquals('AABBCCDD', self.messages[0]['value'])

    def test_x90_wellformed(self):
        self.serial.feed('900013a20040401122012340' + binascii.hexlify('status:1\n')) # Receive well-formed serial packet
        self.wait()
        self.assertEquals(1, len(self.messages))
        self.assertEquals('0013a20040401122', self.messages[0]['address'])
        self.assertEquals('status', self.messages[0]['port'])
        self.assertEquals('1', self.messages[0]['value'])

    def test_x92(self):
        self.serial.feed('920013a200406bfd090123010110008010000B00')  # IO Sample DIO12:1, ADC7(Supply Voltage):2816
        self.wait()
        self.assertEquals(2, len(self.messages))
        self.assertEquals('0013a200406bfd09', self.messages[0]['address'])
        self.assertEquals('adc7', self.messages[0]['port'])
        self.assertEquals(2816, self.messages[0]['value'])
        self.assertEquals('0013a200406bfd09', self.messages[1]['address'])
        self.assertEquals('dio12', self.messages[1]['port'])
        self.assertEquals(1, self.messages[1]['value'])
Beispiel #3
0
    mqtt.password = config.get('mqtt', 'password', None)
    mqtt.keepalive = config.get('mqtt', 'keepalive', 60)
    mqtt.clean_session = config.get('mqtt', 'clean_session', False)
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.set_will = config.get('mqtt', 'set_will', True)

    try:
        serial = Serial(
            config.get('radio', 'port', '/dev/ttyUSB0'),
            config.get('radio', 'baudrate', 9600)
        )
    except SerialException as e:
        sys.exit(e)

    xbee = XBeeWrapper()
    xbee.serial = serial
    xbee.default_port_name = config.get('radio', 'default_port_name', 'serial')
    xbee.sample_rate = config.get('general', 'sample_rate', 0)
    xbee.change_detection = config.get('general', 'change_detection', False)

    processor = Processor(config.get('processor', 'filters', []))

    xbee2mqtt = Xbee2MQTT(resolve_path(config.get('daemon', 'pidfile', '/tmp/xbee2mqtt.pid')))
    xbee2mqtt.stdout = resolve_path(config.get('daemon', 'stdout', '/dev/null'))
    xbee2mqtt.stderr = resolve_path(config.get('daemon', 'stderr', xbee2mqtt.stdout))
    xbee2mqtt.discovery_on_connect = config.get('general', 'discovery_on_connect', True)
    xbee2mqtt.duplicate_check_window = config.get('general', 'duplicate_check_window', 5)
    xbee2mqtt.default_output_topic_pattern = config.get(
        'general', 'default_output_topic_pattern', '/raw/xbee/{address}/{port}'
    )
    mqtt = MosquittoWrapper(config.get('mqtt', 'client_id', None))
    mqtt.host = config.get('mqtt', 'host', 'localhost')
    mqtt.port = config.get('mqtt', 'port', 1883)
    mqtt.username = config.get('mqtt', 'username', None)
    mqtt.password = config.get('mqtt', 'password', None)
    mqtt.keepalive = config.get('mqtt', 'keepalive', 60)
    mqtt.clean_session = config.get('mqtt', 'clean_session', False)
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.set_will = config.get('mqtt', 'set_will', True)

    serial = Serial(
        config.get('radio', 'port', '/dev/ttyUSB0'),
        config.get('radio', 'baudrate', 9600)
    )
    xbee = XBeeWrapper()
    xbee.serial = serial
    xbee.default_port_name = config.get('radio', 'default_port_name', 'serial')

    processor = Processor(config.get('processor', 'filters', []))

    xbee2mqtt = Xbee2MQTT(resolve_path(config.get('general', 'pidfile', '/tmp/xbee2mqtt.pid')))
    xbee2mqtt.stdout = xbee2mqtt.stderr = resolve_path(config.get('general', 'stdout', '/dev/null'))
    xbee2mqtt.debug = config.get('general', 'debug', False)
    xbee2mqtt.duplicate_check_window = config.get('general', 'duplicate_check_window', 5)
    xbee2mqtt.default_topic_pattern = config.get('general', 'default_topic_pattern', '/raw/xbee/{address}/{port}')
    xbee2mqtt.publish_undefined_topics = config.get('general', 'publish_undefined_topics', True)
    xbee2mqtt.load(config.get('general', 'routes', {}))
    xbee2mqtt.logger = logger
    xbee2mqtt.mqtt = mqtt
    xbee2mqtt.xbee = xbee
Beispiel #5
0
    logger = logging.getLogger()
    logger.setLevel(config.get('daemon', 'logging_level', logging.INFO))
    logger.addHandler(handler)

    mqtt = MosquittoWrapper(config.get('mqtt', 'client_id', None))
    mqtt.host = config.get('mqtt', 'host', 'localhost')
    mqtt.port = config.get('mqtt', 'port', 1883)
    mqtt.keepalive = config.get('mqtt', 'keepalive', 60)
    mqtt.clean_session = config.get('mqtt', 'clean_session', False)
    mqtt.qos = config.get('mqtt', 'qos', 0)
    mqtt.retain = config.get('mqtt', 'retain', True)
    mqtt.set_will = config.get('mqtt', 'set_will', True)

    serial = Serial(config.get('radio', 'port', '/dev/ttyUSB0'),
                    config.get('radio', 'baudrate', 9600))
    xbee = XBeeWrapper()
    xbee.serial = serial
    xbee.default_port_name = config.get('radio', 'default_port_name', 'serial')

    processor = Processor(config.get('processor', 'filters', []))

    xbee2mqtt = Xbee2MQTT(
        resolve_path(config.get('general', 'pidfile', '/tmp/xbee2mqtt.pid')))
    xbee2mqtt.stdout = xbee2mqtt.stderr = resolve_path(
        config.get('general', 'stdout', '/dev/null'))
    xbee2mqtt.debug = config.get('general', 'debug', False)
    xbee2mqtt.duplicate_check_window = config.get('general',
                                                  'duplicate_check_window', 5)
    xbee2mqtt.default_topic_pattern = config.get('general',
                                                 'default_topic_pattern',
                                                 '/raw/xbee/{address}/{port}')