Jump to content

BST

Members
  • Gesamte Inhalte

    2
  • Benutzer seit

  • Letzter Besuch

Posts erstellt von BST

  1. Servus,

     

    in einem unserer Projekte (Python) nutzen wir einen Master Brick mit WiFi Extension 2.0 und einen mit WiFi Extension (alte Version). Für beide wird ein CALLBACK_CONNECTED registriert. Das funktioniert auch bei dem Master Brick mit dem alten WiFi-Modul hervorragend: Die als CALLBACK gesetzte Funktion wird immer augerufen, wenn die WLAN-Verbindung neu augebaut wird - egal, ob zum ersten Mal per .connect() Befehl oder nach einem Abrruch der Verbindung, z.B. weil das Brick Stromausfall hatte.

    Anders bei dem Brick mit WiFi Extension 2.0: Beim ersten Verbindungsaufbau per .connect() Befehl wird der Callback korrekt ausgelöst, wenn dann aber die WiFi-Verbindung unterbrochen wird und wieder aufgebaut ist, wird der Callback NICHT ausgelöst. Kennt jemand dieses Verhalten, ist das bekannt oder ein Bug? Machen wir etwas falsch? Code im Anhang.

    LG Johannes

    #!/usr/bin/python3
    #---------------- Library --------------------------
    from tinkerforge.ip_connection import IPConnection
    from tinkerforge.bricklet_sound_pressure_level import BrickletSoundPressureLevel
    from tinkerforge.bricklet_oled_64x48 import BrickletOLED64x48
    from tinkerforge.bricklet_dual_relay import BrickletDualRelay
    import time
    import datetime
    
    
    # -------------- Implementation ---------------------
    class rugged:
        HOST1 = "brickie"
        HOST2 = "brickie2"
        PORT = 4223
        
        def __init__(self):
            self.oled1 = None
            self.dr1 = None
            self.spl1 = None
            self.oled2 = None
            self.dr2 = None
            self.spl2 = None
            
            self.ipcon1 = IPConnection()
            self.ipcon2 = IPConnection()
            
            self.ipcon1.register_callback(IPConnection.CALLBACK_ENUMERATE,self.cb_enumerate1)
            self.ipcon1.register_callback(IPConnection.CALLBACK_CONNECTED,self.cb_connected1)
            
            self.ipcon2.register_callback(IPConnection.CALLBACK_ENUMERATE,self.cb_enumerate2)
            self.ipcon2.register_callback(IPConnection.CALLBACK_CONNECTED,self.cb_connected2)
            isConnected1 = False
            isConnected2 = False
            while not (isConnected1 and isConnected2):
                if not isConnected1:
                    try:
                        print('Connecting to Brick 1...')
                        self.ipcon1.connect(rugged.HOST1, rugged.PORT)
                        isConnected1 = True
                        print('Connected to Brick 1!')
                    except OSError:
                        print('Could not connect to Brick1. Will retry in 5 seconds...')
                        time.sleep(5)
                if not isConnected2:
                    try:
                        print('Connecting to Brick 2...')
                        self.ipcon2.connect(rugged.HOST2, rugged.PORT)
                        isConnected2 = True
                        print('Connected to Brick 2!')
                    except OSError:
                        print('Could not connect to Brick2. Will retry in 5 seconds...')
                        time.sleep(5)
                
            self.ipcon1.enumerate()
            self.ipcon2.enumerate()
        
        
        def cb_dB1(self, decibel):
    	#This part should not matter
                
        def cb_enumerate1(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type):
            if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
               enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
                
                if device_identifier == BrickletSoundPressureLevel.DEVICE_IDENTIFIER:
                    self.spl1 = BrickletSoundPressureLevel(uid, self.ipcon1)
                    self.spl1.set_decibel_callback_configuration(100,False,"x",0,0)
                    self.spl1.register_callback(self.spl1.CALLBACK_DECIBEL,self.cb_dB1)
                
                if device_identifier == BrickletOLED64x48.DEVICE_IDENTIFIER:
                    self.oled1 = BrickletOLED64x48(uid, self.ipcon1)
                    self.oled1.clear_display()
                    
                if device_identifier == BrickletDualRelay.DEVICE_IDENTIFIER:
                    self.dr1 = BrickletDualRelay(uid, self.ipcon1)
                    
        def cb_connected1(self, connected_reason):
            self.ipcon1.enumerate()
            
        def cb_dB2(self, decibel):
    	#This part should not matter
    
        def cb_enumerate2(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type):
            if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
               enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
                
                if device_identifier == BrickletSoundPressureLevel.DEVICE_IDENTIFIER:
                    self.spl2 = BrickletSoundPressureLevel(uid, self.ipcon2)
                    self.spl2.set_decibel_callback_configuration(100,False,"x",0,0)
                    self.spl2.register_callback(self.spl2.CALLBACK_DECIBEL,self.cb_dB2)
                
                if device_identifier == BrickletOLED64x48.DEVICE_IDENTIFIER:
                    self.oled2 = BrickletOLED64x48(uid, self.ipcon2)
                    self.oled2.clear_display()
                    
                if device_identifier == BrickletDualRelay.DEVICE_IDENTIFIER:
                    self.dr2 = BrickletDualRelay(uid, self.ipcon2)
                    
        def cb_connected2(self, connected_reason):
            self.ipcon2.enumerate()
            
            
    if __name__ == "__main__":
        temp=rugged()
        input('Program is running. Press enter to exit.')
        temp.ipcon1.disconnect()
        temp.ipcon2.disconnect()

     

×
×
  • Neu erstellen...