BLE Central and Mesh

Hi,

I want to implement a system in which a thingy:53 will scan for beacons, gets their RSSI value and publishes them to a mesh network using custom models.

Then I want to use a RPi 4B to get these values and publish them to a cloud.

Can anyone guide me and let me know where I should start and steps to follow.

Regards,
Jeason

Parents Reply
  • Aha, if so then I will have to look some more into this. 

    Could you tell me some more about your central/Thingy:53? Does this support both Bluetooth Mesh and BLE? 

    How far into the procedure do you get? Are you able to pick up the RSSI values? Does the socket error occur when you attempt to get the RSSI values or after/when publishing it on the mesh model?

    Could you post the device log showing the error you're getting?

    Kind regards,
    Andreas

Children
  • As far as I know the thingy has a nRF5340 chip and it supports both Mesh and BLE concurrently.

    The model has a get function which gets rssi values by performing a passive scan with an accept list to filter unwanted advertisements. But when it runs I get a 

    "Socket already connected" error from bt_le_start_scan() command.

    However the get function works perfectly when i move it a an application which only does BLE.

    My understanding is that when it comes to a mesh, it has an in built functions which already scan for other mesh devices and is preventing me from making an another scan. Is there a way around this?

    Do we have a guide for concurrent mesh and central application?
  • Jeason said:
    As far as I know the thingy has a nRF5340 chip and it supports both Mesh and BLE concurrently.

    Yes, that is correct. I should've been more specific. What I meant is if your application supports both protocols concurrently

    Thank you for clarifying. I will dig around some and see if I can find an answer to your questions

    I will get back to you when I know some more

    Kind regards,
    Andreas

  • In my application I have enabled mesh and observer role in the prj.conf file. I don't really know what else to configure in my application to concurrently use both protocols at the same time.

    Since I did not know if my custom model has having the issue I was using the sensor model and instead of getting the sensor value, I initiate a BLE scan, gets RSSI of one beacons and pass that to rsp->val1.

    But this also gave me the same error. However if I give a bt_le_scan_stop() command before I initiate my scan it does not give me an error and I am getting my reading on the nrF mesh iOS app.

    # Use deferred logging
    CONFIG_NCS_SAMPLES_DEFAULTS=n
    CONFIG_LOG=y
    CONFIG_ASSERT=y
    CONFIG_ASSERT_NO_COND_INFO=y
    CONFIG_ASSERT_NO_MSG_INFO=y
    
    # General configuration
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_NVS_LOOKUP_CACHE=y
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_NVS_NAME_CACHE=y
    CONFIG_HWINFO=y
    CONFIG_DK_LIBRARY=y
    CONFIG_PM_SINGLE_IMAGE=y
    CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000
    CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE=y
    
    # Temperature sensor
    CONFIG_SENSOR=y
    CONFIG_BME680=y
    
    # Bluetooth configuration
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_COMPANY_ID=0x0059
    CONFIG_BT_DEVICE_NAME="Mesh Sensor"
    CONFIG_BT_L2CAP_TX_MTU=498
    CONFIG_BT_L2CAP_TX_BUF_COUNT=8
    CONFIG_BT_BUF_ACL_TX_SIZE=37
    CONFIG_BT_OBSERVER=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_SETTINGS=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_FILTER_ACCEPT_LIST=y
    
    # Disable unused Bluetooth features
    CONFIG_BT_PHY_UPDATE=n
    
    # Bluetooth mesh configuration
    CONFIG_BT_MESH=y
    CONFIG_BT_MESH_RELAY=y
    CONFIG_BT_MESH_FRIEND=y
    CONFIG_BT_MESH_ADV_BUF_COUNT=13
    CONFIG_BT_MESH_TX_SEG_MAX=10
    CONFIG_BT_MESH_PB_GATT=y
    CONFIG_BT_MESH_GATT_PROXY=y
    CONFIG_BT_MESH_PROXY_USE_DEVICE_NAME=y
    CONFIG_BT_MESH_DK_PROV=y
    CONFIG_BT_MESH_SUBNET_COUNT=2
    CONFIG_BT_MESH_APP_KEY_COUNT=3
    CONFIG_BT_MESH_CRPL=32
    CONFIG_BT_MESH_MSG_CACHE_SIZE=64
    
    # Bluetooth mesh models
    CONFIG_BT_MESH_SENSOR_SRV=y
    CONFIG_BT_MESH_ONOFF_SRV=y
    CONFIG_BT_MESH_SENSOR_SRV_SENSORS_MAX=5
    

  • Hi again,

    Jeason said:
    In my application I have enabled mesh and observer role in the prj.conf file. I don't really know what else to configure in my application to concurrently use both protocols at the same time.

    If you haven't done so already, you could have a look at https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bluetooth/mesh/ble_peripheral_lbs_coex/README.html and modify this so it acts as a central instead of a peripheral and test if that works or to validate that you've configured everything correct by examining that sample. 

    I'm waiting for a reply from the developers regarding if it is possible to modify the peripheral coexistence sample to be a central instead, but I suspect there are some considerations that you need to make. One item is that you may get some degradation of the Mesh network as the device needs to act as a BLE Central and scan for the nodes instead of listening to the Mesh network as a mesh device. But with moderate

    BLE activity I believe this should be possible. 

    Jeason said:
    But this also gave me the same error. However if I give a bt_le_scan_stop() command before I initiate my scan it does not give me an error and I am getting my reading on the nrF mesh iOS app.

    Could you post the section of the code for the case where you have a successful scan?

    Kind regards,
    Andreas

  • void update_scan_filter(void)
    {
        int err;
    
        err = bt_le_filter_accept_list_clear();
        if (err) {
            printk("Clear filter on device address error: %d\n", err);
        }
        static bt_addr_le_t m_dev_address_tag1 =
        {
            .type   = BT_ADDR_LE_PUBLIC,
        };
        memcpy(m_dev_address_tag1.a.val, tag1ID, BT_ADDR_SIZE);
    
        err = bt_le_filter_accept_list_add(&m_dev_address_tag1);
        if (err) {
            printk("Set filter on device address error: %d\n", err);
        }
    
    
    
    }
    
    
    
    
    
    static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
                 struct net_buf_simple *ad)
    {
        char addr_str[BT_ADDR_LE_STR_LEN];
        if (type != BT_GAP_ADV_TYPE_ADV_IND &&
            type != BT_GAP_ADV_TYPE_ADV_DIRECT_IND) {
            return;
        }
    
        bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
        printk("Device found: %s (RSSI %d)\n", addr_str, rssi);
        Rssi = rssi;
        bt_le_scan_stop();
    }
    
    static void start_scan(void)
    {
        int err;
    
        bt_le_scan_stop();
        update_scan_filter();
    
        struct bt_le_scan_param param ={
            .type = BT_LE_SCAN_TYPE_PASSIVE,
            .options = BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST,
            .interval = BT_GAP_SCAN_FAST_INTERVAL,
            .window = BT_GAP_SCAN_FAST_WINDOW,
        };
        err = bt_le_scan_start(&param, device_found);
        if (err) {
            printk("Scanning failed to start (err %d)\n", err);
            return;
        }
    
        printk("Scanning successfully started\n");
    }
    
    int AmbientTemperatureGet(struct bt_mesh_sensor_srv *srv,
                 struct bt_mesh_sensor *sensor,
                 struct bt_mesh_msg_ctx *ctx,
                 struct sensor_value *rsp)
    {
    
    
        start_scan();
       
        rsp->val1 = Rssi;
        rsp->val2 = 0;
        return 0;
       
    }

Related