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?

  • Hi,

    The key difference is in gatt_discover(), the NCS v2.9.0 is

    	err = bt_gatt_dm_start(conn,
    			       BT_UUID_NUS_SERVICE,
    			       &discovery_cb,
    			       &nus_client);

    the multi-NUS version is,

     
    	err = bt_gatt_dm_start(conn,
    					BT_UUID_NUS_SERVICE,
    					&discovery_cb,
    					nus_client);
    the multi-NUS version does not have the address-of operator before nus_client, 
    so how to fix multi-NUS sample to run in NCS v2.9.0?
    I attached the project on the following,
  • Hello,

    I ran the sample that you attached just now, and this is what it prints over UART:

    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    felix multi-nus central
    Starting Bluetooth Central UART example
    central : Connected CE:20:8F:A0:A2:4D (random), number: 0
    num_nus_conns = 3, L687
    NUS Client module initializedService discovery completed
    Scanning successfully started L514
    ctx->data = 0x2000a0e8
    nus=0x2000a0e8
    i = 0
    central : Connected E3:4A:AE:AC:E6:6E (random), number: 1
    num_nus_conns = 3, L687
    NUS Client module initializedService discovery completed
    Scanning successfully started L514
    ctx->data = 0x2000a0e8
    nus=0x2000a12c
    ctx->data != nus
    ctx->data = 0x2000a12c
    nus=0x2000a12c
    i = 1
    

    Then the two devkits programmed with the default peripheral_uart prints this:

    *** Booting My Application v2.9.0-0a85ae2bebaa ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    Starting Nordic UART service example
    00
    

    *** Booting My Application v2.9.0-0a85ae2bebaa ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    Starting Nordic UART service example
    00
    

    So apparently, it does pass the check "if (ctx->data == nus)"

    James168 said:
    the multi-NUS version does not have the address-of operator before nus_client, 

    The reason for this is that in the multinus application, the nus_client is declared as a pointer, so it already points to the address. 

    Do you not see the same log?

    Best regards,

    Edvin

  • I don't notice they are declared for different type, one is non-pointer,

    static struct bt_nus_client nus_client;
    the other is pointer,
    struct bt_nus_client *nus_client = bt_conn_ctx_get(&conns_ctx_lib, conn);
    I have no problem for this issue now.
  • Hi,

    The first peripheral_uart after reset failed to reconnect to central_uart.

    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    Starting Bluetooth Central UART example
    ********** bt_scan_start, err=0, L967
    Scanning successfully started
    central : Connected C1:69:8A:90:CB:FC (random), connected number: 1
    NUS Client module initialized
    ********** bt_scan_stop, L711
    Stop LE scan failed (err 0)
    gatt_discover(), err=0, L623
    ********** bt_scan_start, err=0, L502
    ctx->data = 0x2000a0e8
    nus=0x2000a0e8
    i = 0
    discovery_complete(), err=0, L565
    central : Connected F1:75:4A:A8:7E:11 (random), connected number: 2
    NUS Client module initialized
    ********** bt_scan_stop, L711
    Stop LE scan failed (err 0)
    gatt_discover(), err=0, L623
    ********** bt_scan_start, err=0, L502
    ctx->data = 0x2000a0e8
    nus=0x2000a12c
    ctx->data != nus
    ctx->data = 0x2000a12c
    nus=0x2000a12c
    i = 1
    discovery_complete(), err=0, L565
    central : Disconnected C1:69:8A:90:CB:FC (random), connected num: 1

    C1:69:8A:90:CB:FC connects to central (line 6~line 15), then F1:75:4A:A8:7E:11 connects to central (line 16~line28). press the reset button of C1:69:8A:90:CB:FC, it disconnects (line 29), but it can't reconnect to central.

    I attach the project as the following, just add some debug message.

    central_uart_v290_multi_nus_250311_reconnect_fail.7z

  • You are getting the scan_connecting_error() callback, meaning that it attempted to reconnect to the device, but failed. Not exactly sure why this happens, but you can start scanning again inside this callback:

    static void scan_connecting_error(struct bt_scan_device_info *device_info)
    {
        int err;
    	LOG_WRN("Connecting failed");
        err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
        if (err) {
            printk("started to scan again. Ret: %d\n", err);
        }
    }

    That fixed it for me, at least.

    Oh, and I see that you experimented with logging. By default, this sample uses RTT logging, in case you were not aware. So if you open an RTT terminal, such as JLink RTT Viewer (Part of the JLink bundle from Segger.com), and connect to your board, you should see the log. You need to reconnect the RTT viewer every time you recompile and flash the board, because it needs to look for the new location of the RTT buffer in RAM. 

    Best regards,

    Edvin

Related