Many-to-one sensor collector topology, which BLE sample is better to modify?

Hi, 

1) I want to collect sensor data using BLE like the following topology, the sensor devices are battery-powered, which sample in the NCS is suitable to modify?

2) Does NUS central/peripheral can do many-to-one topology in this usage? or need to use BLE mesh?

  • To add bt_scan_start() to callback function scan_connecting_error() still fail to reconnect sometime, and the original multi-NUS sample has the same error even modify scan_connectiing_error(). 

    The connect context library seems unstable.

  • Yes, I noticed. Not sure whether it is the peripheral not picking up the connection requests, or if it is the scheduling of the scanning/connecting that fails. I will try to capture a sniffer trace to see if I can find anything on air. I'll do it later today if I have time. If not, tomorrow. 

    Best regards,

    Edvin

  • Sorry, I was unable to go into the office today. I will look into it next week.

    I'm sorry for the inconvenience.

    Best regards,

    Edvin

  • Hi,

    1) From the wireshark log, the central (F2:76:DA:88:7F:67) seems stop to send scan_req, although the RTT log show "Scanning successfully started".

    central_uart_v290_multi_nus_250318.pcapng

    00> [00:11:24.754,577] <inf> central_uart: Scanning successfully started
    00> [00:11:25.172,515] <inf> central_uart: Filters matched. Address: C1:69:8A:90:CB:FC (random) connectable: 0
    00> [00:11:25.175,720] <wrn> bt_conn: Found valid connection (0x20002000) with address C1:69:8A:90:CB:FC (random) in disconnected state 
    00> [00:11:25.176,269] <wrn> central_uart: Connecting failed
    00> [00:11:25.179,870] <inf> central_uart: Scanning successfully started
    00> [00:11:25.821,533] <inf> central_uart: Filters matched. Address: C1:69:8A:90:CB:FC (random) connectable: 0
    00> [00:11:25.825,714] <wrn> bt_conn: Found valid connection (0x20002000) with address C1:69:8A:90:CB:FC (random) in disconnected state 
    00> [00:11:25.826,263] <wrn> central_uart: Connecting failed
    00> [00:11:25.829,864] <inf> central_uart: Scanning successfully started
    00> [00:11:26.246,063] <inf> central_uart: Filters matched. Address: C1:69:8A:90:CB:FC (random) connectable: 0
    00> [00:11:26.248,840] <wrn> bt_conn: Found valid connection (0x20002000) with address C1:69:8A:90:CB:FC (random) in disconnected state 
    00> [00:11:26.249,389] <wrn> central_uart: Connecting failed

    2) reconnect successfully log:

    00> [00:01:10.733,825] <inf> central_uart: Disconnected: C1:69:8A:90:CB:FC (random), reason 0x08 
    00> [00:01:10.742,736] <inf> central_uart: Filters matched. Address: C1:69:8A:90:CB:FC (random) connectable: 0
    00> [00:01:10.946,624] <inf> central_uart: Connected: C1:69:8A:90:CB:FC (random)
    00> [00:01:10.953,399] <inf> central_uart: NUS Client module initialized
    00> [00:01:10.959,747] <err> central_uart: Stop LE scan failed (err 0)
    00> [00:01:10.984,466] <inf> central_uart: MTU exchange done
    00> [00:01:11.083,831] <err> bt_smp: pairing failed (peer reason 0x3)
    00> [00:01:11.084,350] <wrn> central_uart: Security failed: C1:69:8A:90:CB:FC (random) level 1 err 4 
    00> [00:01:11.087,707] <wrn> central_uart: Pairing failed conn: C1:69:8A:90:CB:FC (random), reason 4 
    00> [00:01:11.783,660] <inf> central_uart: Service discovery completed
    00> [00:01:11.788,757] <inf> central_uart: Scanning successfully started L514
    00> [00:01:11.799,011] <inf> central_uart: Sent data to NUS server 1: 01

    reconnect failed log:

    00> [00:02:15.226,318] <inf> central_uart: Disconnected: F1:75:4A:A8:7E:11 (random), reason 0x08 
    00> [00:02:15.882,629] <inf> central_uart: Filters matched. Address: F1:75:4A:A8:7E:11 (random) connectable: 0
    00> [00:02:15.883,758] <wrn> bt_conn: Found valid connection (0x20002000) with address F1:75:4A:A8:7E:11 (random) in disconnected state 
    00> [00:02:15.884,307] <wrn> central_uart: Connecting failed
    00> [00:02:15.887,878] <inf> central_uart: Scanning successfully started
    00> [00:02:16.622,924] <inf> central_uart: Filters matched. Address: F1:75:4A:A8:7E:11 (random) connectable: 0
    00> [00:02:16.624,389] <wrn> bt_conn: Found valid connection (0x20002000) with address F1:75:4A:A8:7E:11 (random) in disconnected state 
    00> [00:02:16.624,938] <wrn> central_uart: Connecting failed
    00> [00:02:16.628,540] <inf> central_uart: Scanning successfully started
    00> [00:02:16.730,133] <inf> central_uart: Filters matched. Address: F1:75:4A:A8:7E:11 (random) connectable: 0
    00> [00:02:16.730,987] <wrn> bt_conn: Found valid connection (0x20002000) with address F1:75:4A:A8:7E:11 (random) in disconnected state 

    00> [00:02:15.883,758] <wrn> bt_conn: Found valid connection (0x20002000) with address F1:75:4A:A8:7E:11 (random) in disconnected state 

    is output from 

    bool bt_conn_exists_le(uint8_t id, const bt_addr_le_t *peer)
    {
    	struct bt_conn *conn = bt_conn_lookup_addr_le(id, peer);
    
    	if (conn) {
    		/* Connection object already exists.
    		 * If the connection state is not "disconnected",then the
    		 * connection was created but has not yet been disconnected.
    		 * If the connection state is "disconnected" then the connection
    		 * still has valid references. The last reference of the stack
    		 * is released after the disconnected callback.
    		 */
    		LOG_WRN("Found valid connection (%p) with address %s in %s state ", conn,
    			bt_addr_le_str(peer), state2str(conn->state));
    		bt_conn_unref(conn);
    		return true;
    	}
    
    	return false;
    }

    According to the comment, "If the connection state is "disconnected" then the connection
    still has valid references."

  • Ok, I see what's going on. Please see:

    00> [00:01:46.234,741] <inf> central_uart: Disconnected: E3:4A:AE:AC:E6:6E (random), reason 0x08 
    00> [00:01:47.230,865] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:47.329,833] <inf> central_uart: Connected: E3:4A:AE:AC:E6:6E (random)
    00> [00:01:47.336,364] <inf> central_uart: NUS Client module initialized
    00> [00:01:47.342,803] <err> central_uart: Stop LE scan failed (err 0)
    00> [00:01:47.449,584] <inf> central_uart: MTU exchange done
    00> [00:01:47.699,645] <inf> central_uart: Security changed: E3:4A:AE:AC:E6:6E (random) level 2
    00> [00:01:48.549,499] <inf> central_uart: Service discovery completed
    00> [00:01:48.554,351] <inf> central_uart: Scanning successfully started L514
    00> [00:01:48.558,898] <inf> central_uart: Sent data to NUS server 0: 00
    00> àY
    00> [00:01:52.749,603] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:52.750,061] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:52.750,061] <wrn> central_uart: Connecting failed
    00> [00:01:53.480,438] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:53.482,025] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:53.482,025] <wrn> central_uart: Connecting failed
    00> [00:01:53.583,038] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:53.585,113] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:53.585,113] <wrn> central_uart: Connecting failed
    00> [00:01:53.690,216] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:53.691,314] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:53.691,345] <wrn> central_uart: Connecting failed
    00> [00:01:53.792,144] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:53.792,602] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:53.792,602] <wrn> central_uart: Connecting failed
    00> [00:01:54.113,372] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:54.117,004] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:54.117,004] <wrn> central_uart: Connecting failed
    00> [00:01:54.536,834] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:54.537,872] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:54.537,902] <wrn> central_uart: Connecting failed
    00> [00:01:54.641,754] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:54.642,211] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:54.642,242] <wrn> central_uart: Connecting failed
    00> [00:01:55.273,284] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:55.276,672] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:55.276,702] <wrn> central_uart: Connecting failed
    00> [00:01:55.378,540] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:55.380,249] <wrn> bt_conn: Found valid connection (0x20002530) with address E3:4A:AE:AC:E6:6E (random) in connected state 
    00> [00:01:55.380,249] <wrn> central_uart: Connecting failed
    00> [00:01:55.749,725] <inf> central_uart: Disconnected: E3:4A:AE:AC:E6:6E (random), reason 0x08 
    00> [00:01:55.787,689] <inf> central_uart: Filters matched. Address: E3:4A:AE:AC:E6:6E (random) connectable: 0
    00> [00:01:56.099,243] <inf> central_uart: Connected: E3:4A:AE:AC:E6:6E (random)
    00> [00:01:56.105,743] <inf> central_uart: NUS Client module initialized
    00> [00:01:56.112,091] <err> central_uart: Stop LE scan failed (err 0)
    00> [00:01:56.249,572] <inf> central_uart: MTU exchange done

    You can see that the disconnected event occurs after the initial attempts to connect. And the log also says that it is already connected to the device with that address. So what happens is that you reset the DK (peripheral), and then it will start advertising immediately. Since the central is already scanning, it will immediately trigger the filter match, and try to connect, but it will fail to connect because it is still in a connection with the device with the same address. Then, later, when the central receives an latency timeout (disconnect reason 08), it will regard the old connection as disconnected. Then it will be able to connect to the peripheral again.

    The reason you don't see this in the normal central_uart application is because it is not scanning while it is in a connection. 

    In reality, you wouldn't see this issue either, because the peripheral wouldn't advertise while in a connection. And if they are getting out of range, they will still remain in a connection, until they time out at the same point in time (it is part of the connection parameters). Hence, the peripheral wouldn't start advertising before the central would consider the device disconnected. And should you for some reason experience a reset on the peripheral, it would still connect, but it takes a short while. 

    Best regards,

    Edvin

Related