This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue: Identifying beacons with 128-bit UUID for nRF9160 DK (PCA 10090)

Hi,

I am currently working on "asset_tracker" application.

Actually, I need to read 128-bit UUID values of the BLE ibeacons present nearby the board (PCA10090)  to be captured in "asset_tracker", application.

Looking forward to your help.

Please guide me the correct way and let me know how to read 128-bit UUID values and implement the same for asset tracker application.

Parents
  • I modified the ble_lte_gateway example in NCS v1.1.0 to scan for beacons, parse the advertising data and store the 128 bit UUID, the major and the minor value. Execute these steps to get the example up and running

    • Follow the steps explained here to build and run the LTE Sensor Gateway example
    • Swap the file <..>\ncs\nrf\samples\nrf9160\lte_ble_gateway\src\ble.c with the file provided below, then rebuild and flash your example.

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    
    #include <zephyr.h>
    
    #include <bluetooth/gatt.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt_dm.h>
    #include <bluetooth/scan.h>
    
    #include <dk_buttons_and_leds.h>
    #include <misc/byteorder.h>
    
    #include <nrf_cloud.h>
    #include "aggregator.h"
    
    #define BEACON_UUID_START 4
    #define BEACON_UUID_SIZE 16
    
    #define BEACON_MAJOR_START 20
    #define BEACON_MAJOR_SIZE 2
    
    #define BEACON_MINOR_START 22
    #define BEACON_MINOR_SIZE 2
    
    uint8_t beacon_uuid[16];
    uint8_t beacon_major[2];
    uint8_t beacon_minor[2];
    
    static bool adv_data_found(struct bt_data *data, void *user_data)
    {
            int i, index;
    
    	if(data->type== BT_DATA_MANUFACTURER_DATA) {
               printk("--------------\n");
               printk("Manuf. data: ");
    	   for(i=0; i < data->data_len; i++){
                    printk("%x, ", data->data[i]);
               }
               printk("\n");
               printk("Beacon uuid: ");
               for(i=0; i < BEACON_UUID_SIZE; i++){
                    index = i + BEACON_UUID_START;
                    beacon_uuid[i] = (uint8_t)data->data[index];
                    printk("%x,", data->data[index]);
               }
               printk("\n");
    
               printk("Beacon major: ");
               for(i=0; i < BEACON_MAJOR_SIZE; i++){
                    index = i + BEACON_MAJOR_START;
                    beacon_major[i] = (uint8_t)data->data[index];
                    printk("%x,", data->data[index]);
               }
               printk("\n");
                printk("Beacon minor: ");
               for(i=0; i < BEACON_MINOR_SIZE; i++){
                    index = i + BEACON_MINOR_START;
                    beacon_minor[i] = (uint8_t)data->data[index];
                    printk("%x,", data->data[index]);
               }
               printk("\n\n");
    	   return false;
    	}
    
    
    	return true;
    }
    
    static void scan_cb(const bt_addr_le_t *addr, s8_t rssi, u8_t adv_type,
    		    struct net_buf_simple *ad)
    {
            printk("scan callback\n");
            bt_data_parse(ad, adv_data_found, NULL);
    }
    
    void scan_connecting_error(struct bt_scan_device_info *device_info)
    {
    	printk("Connection to peer failed!\n");
    }
    
    //BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL, scan_connecting_error, NULL);
    
    static void scan_start(void)
    {
    	int err;
    
            err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, scan_cb);
    	if (err) {
    		printk("Starting scanning failed (err %d)\n", err);
    		return;
            }
    }
    
    static void ble_ready(int err)
    {
    	printk("Bluetooth ready\n");
    
    	//bt_conn_cb_register(&conn_callbacks);
    	scan_start();
    }
    
    void ble_init(void)
    {
    	int err;
    
    	printk("Initializing Bluetooth..\n");
    	err = bt_enable(ble_ready);
    	if (err) {
    		printk("Bluetooth init failed (err %d)\n", err);
    		return;
    	}
    }
    

    Best regards,

    Simon

  • Where can I find the sample scan_beacons, please?

Reply Children
Related