thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.72k stars 829 forks source link

[BUG] BLE connector not connecting with multiple BLE devices on startup with latest Bleak Client introduced- TB gateway release ver3.0 #688

Closed jayneev closed 2 years ago

jayneev commented 2 years ago

Describe the bug BLE Connector clients - TB Gateway release ver 3.0, not able to connect to multiple devices on startup. Bleak multiple clients fail to connect concurrently to all devices. Test summary: 1) BLE connector not able to connect with more than 1-2 BLE devices simultaneously. At present BLE connector connects OK with max 1 device and intermittently 2 devices. 2) BLE data received are not published to the remote TB application. 3) BLE Connect/Disconnect, reconnect scenario not handled i.e. Once device disconnected, no further connection establishment attempts by TB gateway. Query: Is this Bleak client able to connect to more multiple BLE devices (e.g 3 devices ) in parallel? Was this tested and verified before > 1 BLE device connections to Bleak Client?

Connector name (If bug in the some connector): BLE Connector

Error traceback (If available):


{
  "name": "BLE Connector",
  "passiveScanMode": false,
  "showMap": false,
  "scanner": {
    "timeout": 10000,
    "deviceName": "Device name"
  },
  "devices": [
    {
      "name": "Dev1",
      "MACAddress": "F7:A2:AD:F4:4E:D9",
      "pollPeriod": 5000,
      "showMap": true,
      "addrType": "public",
      "timeout": 10000,
      "telemetry": [
        {
          "key": "MyData",
          "method": "notify",
          "characteristicUUID": "1e821401-4a30-45b4-9e17-93f34e283081",
          "valueExpression": "[0:3]"
        }
       ],
      "attributes": [                                                  
        {                                                              
          "key": "name",                                               
          "method": "read",                                            
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb",
          "valueExpression": "[:]"                                     
        }                                                              
      ],                                                               
      "attributeUpdates": [                                            
        {                                                              
          "attributeOnThingsBoard": "sharedName",                      
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb" 
        }                                                              
      ],                                                               
      "serverSideRpc": [                                               
      ]                                                                
    },
    {                                                                  
      "name": "Dev2",                                                 
      "MACAddress": "F9:C2:A9:B4:12:D9",                               
      "pollPeriod": 5000,                                              
      "showMap": true,                                                 
      "addrType": "public",                                            
      "timeout": 10000,                                                
      "telemetry": [                                                   
        {                                                              
          "key": "MyData",                                               
          "method": "notify",                                          
          "characteristicUUID": "1e821401-4a30-45b4-9e17-93f34e283081",
          "valueExpression": "[0:3]"                                   
        }
      ],                                                               
      "attributes": [                                                  
        {                                                              
          "key": "name",                                               
          "method": "read",                                            
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb",
          "valueExpression": "[:]"                                     
        }                                                              
      ],                                                               
      "attributeUpdates": [                                            
        {                                                              
          "attributeOnThingsBoard": "sharedName",                      
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb" 
        }                                                              
      ],                                                               
      "serverSideRpc": [                                               
      ]                                                                
    },                                                                 
    {                                                                  
      "name": "Dev3",                                                 
      "MACAddress": "17:C2:BF:74:5D:5E",                               
      "pollPeriod": 5000,                                              
      "showMap": true,                                                 
      "addrType": "public",                                            
      "timeout": 10000,                                                
      "telemetry": [                                                   
        {                                                              
          "key": "MyData",                                               
          "method": "notify",                                          
          "characteristicUUID": "1e821401-4a30-45b4-9e17-93f34e283081",
          "valueExpression": "[0:3]"                                   
        }
       ],
      "attributes": [                                                  
        {                                                              
          "key": "name",                                               
          "method": "read",                                            
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb",
          "valueExpression": "[:]"                                     
        }                                                              
      ],                                                               
      "attributeUpdates": [                                            
        {                                                              
          "attributeOnThingsBoard": "sharedName",                      
          "characteristicUUID": "00002a00-0000-1000-8000-00805f9b34fb" 
        }                                                              
      ],                                                               
      "serverSideRpc": [                                               
      ]                                                                
    }                                                                  
  ]                                                                    
} 

**Versions (please complete the following information):**
 - OS:  Linux 4.9
 - Thingsboard IoT Gateway version 3.0 latest master branch
 - Python version 3.8
samson0v commented 2 years ago

Hi @jayneev, please, send the logs of the Gateway.

jayneev commented 2 years ago

@samson0v, mailed you the logs to your e-mail. Please check.

samson0v commented 2 years ago

Hi @jayneev, we found the bug and will fix it. I will let you know.

samson0v commented 2 years ago

@jayneev currently, there is no bug with connecting 3 or more devices. We tested different scenarios (with different device counts, different poll periods, different attrs counts and telemetries counts, different methods of data receiving).

But we found the bug with Data Process Thread generation thanks to you.

So, it seems that you have some misconfiguration or some problems with the devices. Thanks for your interest in ThingsBoard IoT Gateway!

jayneev commented 2 years ago

@samson0v, Can we connect today for online test demo at our end to make you understand the issues? Please advice your online availability today.

samson0v commented 2 years ago

Hi @jayneev, let's make a call. I am available from now till 17:00 Ukrainian time via Microsoft teams. Or if you can't today, we can make a call tomorrow. Make sure you have installed the latest version of Gateway.

jayneev commented 2 years ago

Hi @samson0v, saw your message very late, let's connect tommorrow 02:00 PM Ukrainian time (5:00 PM IST). I will send you Microsoft teams requests separately.