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

How to switch between beacon modes without buttons?

Hi,

I'm using nRF51822 Bluetooth Smart Beacon Kit. Is it possible to to switch between beacon mode and configuration mode without the need to press SW2 button e.g.: by sending some instructions, or from beacon mode to DFU mode? Any ideas are very welcome.

Thx

Parents
  • Hi Adam I also interesting about this application, so I modified the Beacon Source code to obtain the same result without press SW2 button. For the other point, entry in DFU without press SW1, I'm still working but I didn't found any solution. Below you can find a snippet code for the first step:

    • in the main.c you must put:

    if (mode == beacon_mode_config) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; ble_advdata_manuf_data_t manuf_specific_data; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    		  manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data        = (uint8_t *) clbeacon_info;
        manuf_specific_data.data.size          = APP_BEACON_INFO_LENGTH;
    		
        ble_uuid_t adv_uuids[] = {{BCS_UUID_SERVICE, m_bcs.uuid_type}};
    
        // Build and set advertising data
        memset(&advdata, 0, sizeof(advdata));
        //advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance      = false;
        advdata.flags.size              = sizeof(flags);
        advdata.flags.p_data            = &flags;
    			advdata.p_manuf_specific_data   = &manuf_specific_data;
        
        memset(&scanrsp, 0, sizeof(scanrsp));
    			scanrsp.name_type                = BLE_ADVDATA_FULL_NAME;
        scanrsp.uuids_complete.uuid_cnt  = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        scanrsp.uuids_complete.p_uuids   = adv_uuids;
        
        err_code = ble_advdata_set(&advdata, &scanrsp);
        APP_ERROR_CHECK(err_code);
        
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
        
        m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        m_adv_params.p_peer_addr = NULL;
        m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval    = APP_ADV_INTERVAL;
        m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;           
    }
    else
    {
        APP_ERROR_CHECK_BOOL(false);
    } 
    
    • comment the lines:

    //err_code = app_button_is_pushed(CONFIG_MODE_BUTTON_PIN, &config_mode); //APP_ERROR_CHECK(err_code);

    • finally you must remember to put: bool config_mode = true;

    In this mode the beacon is always connectable.

    If anyone have suggestion to entry in bootloader mode without press SW1, please reply in this thread, thank you. I read the question in devzone.nordicsemi.com/.../ but I can not understand the operation of the function:

    static void on_write(ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if (p_evt_write->handle == 3) // device name handle { NRF_POWER->GPREGRET = 1; sd_nvic_SystemReset(); } }

    What is the device name handle? And in which source code I must to put this function?

    I'm waiting for an answer, thank you.

Reply
  • Hi Adam I also interesting about this application, so I modified the Beacon Source code to obtain the same result without press SW2 button. For the other point, entry in DFU without press SW1, I'm still working but I didn't found any solution. Below you can find a snippet code for the first step:

    • in the main.c you must put:

    if (mode == beacon_mode_config) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; ble_advdata_manuf_data_t manuf_specific_data; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    		  manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data        = (uint8_t *) clbeacon_info;
        manuf_specific_data.data.size          = APP_BEACON_INFO_LENGTH;
    		
        ble_uuid_t adv_uuids[] = {{BCS_UUID_SERVICE, m_bcs.uuid_type}};
    
        // Build and set advertising data
        memset(&advdata, 0, sizeof(advdata));
        //advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance      = false;
        advdata.flags.size              = sizeof(flags);
        advdata.flags.p_data            = &flags;
    			advdata.p_manuf_specific_data   = &manuf_specific_data;
        
        memset(&scanrsp, 0, sizeof(scanrsp));
    			scanrsp.name_type                = BLE_ADVDATA_FULL_NAME;
        scanrsp.uuids_complete.uuid_cnt  = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        scanrsp.uuids_complete.p_uuids   = adv_uuids;
        
        err_code = ble_advdata_set(&advdata, &scanrsp);
        APP_ERROR_CHECK(err_code);
        
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
        
        m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        m_adv_params.p_peer_addr = NULL;
        m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval    = APP_ADV_INTERVAL;
        m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;           
    }
    else
    {
        APP_ERROR_CHECK_BOOL(false);
    } 
    
    • comment the lines:

    //err_code = app_button_is_pushed(CONFIG_MODE_BUTTON_PIN, &config_mode); //APP_ERROR_CHECK(err_code);

    • finally you must remember to put: bool config_mode = true;

    In this mode the beacon is always connectable.

    If anyone have suggestion to entry in bootloader mode without press SW1, please reply in this thread, thank you. I read the question in devzone.nordicsemi.com/.../ but I can not understand the operation of the function:

    static void on_write(ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if (p_evt_write->handle == 3) // device name handle { NRF_POWER->GPREGRET = 1; sd_nvic_SystemReset(); } }

    What is the device name handle? And in which source code I must to put this function?

    I'm waiting for an answer, thank you.

Children
No Data
Related