My overall goal is to update the percentage of battery left in the advertiser and then either go to a nine second sleep to conserve as much power as possible and then wake up and repeat the process. Right now I am trying to see if using a timer event will allow the project to last long enough on a small battery (30mAH) or if I should investigate using some external circuitry to produce a wake up pulse so the battery can be separated from the micro and have minimal draw on the battery. Any suggestions on how this can be verified would be appreciated.
In addition, I have been attempting to work with the beacon examples and have managed to introduce some kind of fatal error when I start the advertising. The init seems to be functioning okay but I may be missing an important init step. I am not sure if that is the case. I have included what I think are the relevant parts of this code below. If more is needed just let me know.
I am trying to make an undirected, non-connectable, no timeout advertising beacon with a nine second delay that updates a battery percentage parameter.
//-----------------------------------------------------------------------------
static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] = /**< Information advertised by the Beacon. */
{
APP_DEVICE_TYPE, // Manufacturer specific information. Specifies the device type in this implementation.
APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the
// manufacturer specific data in this implementation.
APP_BEACON_UUID, // 128 bit UUID value.
APP_PRD_ID_OFS, // Manufacturer specific information. Product ID offset value.
APP_PCB_REV, // Manufacturer specific information. PCB Revision Level.
APP_FW_MAJ_VERS, // Manufacturer specific information. Firmware Major Version
APP_FW_MIN_VERS, // Manufacturer specific information. Firmware Minor Version
APP_MEASURED_RSSI, // Manufacturer specific information. The Beacon's measured TX power in this implementation.
APP_BATT_PCNT_LVL // Manufacturer specific information. The Beacon's measured Battery power in percent
};
//-----------------------------------------------------------------------------
static uint8_array_t ary_beacon_info =
{
.size = 0x0001, // Number of array entries
.p_data = m_beacon_info // pointer to the data
};
//-----------------------------------------------------------------------------
static void advertising_init(void)
{
uint32_t loc_err_code;
ble_advertising_init_t init;
memset(&init, 0, sizeof(init));
F_Manuf_Data.company_identifier = APP_COMPANY_IDENTIFIER;
F_Manuf_Data.data = ary_beacon_info;
init.advdata.name_type = BLE_ADVDATA_NO_NAME; //BLE_ADVDATA_FULL_NAME;
init.advdata.include_appearance = false;
init.advdata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
init.advdata.p_manuf_specific_data = &F_Manuf_Data;
// init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
// init.advdata.uuids_complete.p_uuids = m_adv_uuids;
init.config.ble_adv_fast_enabled = true;
// init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_interval = NON_CONNECTABLE_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = 0; // Never time out APP_ADV_DURATION;
init.evt_handler = on_adv_evt;
loc_err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(loc_err_code);
}
//-----------------------------------------------------------------------------
static void advertising_start(void)
{
ret_code_t loc_err_code;
loc_err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(loc_err_code);
NRF_LOG_INFO(" ble_advertising_start");
loc_err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
APP_ERROR_CHECK(loc_err_code);
NRF_LOG_INFO(" bsp_indication_set");
}
//-----------------------------------------------------------------------------
int main(void)
{
// Initialize.
log_init();
timers_init();
leds_init();
power_management_init();
ble_stack_init();
advertising_init();
// Start execution.
NRF_LOG_INFO("Beacon example started.");
advertising_start();
// Enter main loop.
for (;;)
{
idle_state_handle();
}
}
The defines that I am using are as follows:
#define APP_BEACON_INFO_LENGTH 0x18 /**< Total length of information advertised by the Beacon. */
#define APP_ADV_DATA_LENGTH 0x16 /**< Length of manufacturer specific data in the advertisement. */
#define APP_DEVICE_TYPE 0x02 /**< 0x02 refers to Beacon. */
#define APP_MEASURED_RSSI 0xB3 /**< The Beacon's measured RSSI at 1 meter distance in dBm. */
#define APP_BATT_PCNT_LVL 80 /**< The percentage amount of battery left. */
#define APP_COMPANY_IDENTIFIER 0x0059 /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */
#define APP_PRD_ID_OFS 0x00 /**< Product ID Offset. */
#define APP_PCB_REV 0x00 /**< PCB Revision Level. */
#define APP_FW_MAJ_VERS 0x00 /**< Firmware Major Version. */
#define APP_FW_MIN_VERS 0x80 /**< Firmware Minor Version. */
#define APP_BEACON_UUID 0x01, 0x12, 0x23, 0x34, \
0x45, 0x56, 0x67, 0x78, \
0x89, 0x9a, 0xab, 0xbc, \
0xcd, 0xde, 0xef, 0xf0 /**< Proprietary UUID for Beacon. */
I have the nRF_Log enabled and this is what I see continuously:
<info> app_timer: RTC: initialized.
<info> app: Beacon example started.
<error> app: Fatal error
<warning> app: System reset
<info> app_timer: RTC: initialized.
<info> app: Beacon example started.
<error> app: Fatal error
<warning> app: System reset
Any help identifying the fatal error or figuring out why it cannot get past ble_advertising_start would be greatly appreciated.