Skip to content

Commit 8b55daf

Browse files
committed
add mac to device name
1 parent 004b958 commit 8b55daf

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

apps/firmware/src/ble_stack.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,26 @@ void gap_params_init(void)
454454

455455
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
456456

457+
// Get the current mac
458+
ble_gap_addr_t gap_addr;
459+
memset(&gap_addr, 0, sizeof(gap_addr));
460+
err_code = sd_ble_gap_addr_get(&gap_addr);
461+
462+
char name[strlen(DEVICE_NAME) + 7];
463+
sprintf(name, "%s_%02X%02X", DEVICE_NAME, gap_addr.addr[1], gap_addr.addr[0]);
464+
457465
err_code = sd_ble_gap_device_name_set(&sec_mode,
458-
(const uint8_t *)DEVICE_NAME,
459-
strlen(DEVICE_NAME));
466+
(const uint8_t *)name,
467+
strlen(name));
460468
APP_ERROR_CHECK(err_code);
461469

462470
/* YOUR_JOB: Use an appearance value matching the application's use case.
463471
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_);
464472
APP_ERROR_CHECK(err_code); */
465473

474+
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG);
475+
APP_ERROR_CHECK(err_code);
476+
466477
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
467478

468479
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;

apps/firmware/src/main.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,30 @@
2828

2929
/**
3030
* advertising interval in milliseconds
31+
*
32+
* According to power profiler https://devzone.nordicsemi.com/power/w/opp/2/online-power-profiler-for-bluetooth-le
33+
* average current is 11 µA with a 3000msec interval on a nRF52810
34+
* so life expectancy of a CR2032 coin-cell (the one used on Moko M1) would be about 1.5 year
35+
* and life expectancy of a CR2477 coin-cell (the one used on Moko M2) would be about 6 years
3136
*/
32-
#define ADVERTISING_INTERVAL 500
37+
#define ADVERTISING_INTERVAL 3000
3338

34-
//static char public_key[28] = "OFFLINEFINDINGPUBLICKEYHERE!";
39+
static char public_key[28] = "OFFLINEFINDINGPUBLICKEYHERE!";
40+
41+
//Test1
42+
/*
3543
static char public_key[28] = {0x4e, 0xe3, 0xf3, 0xc5, 0xbf, 0x2f, 0xcb, 0x61,
3644
0x06, 0xc2, 0xb5, 0x1d, 0x80, 0xff, 0x60, 0xb8,
3745
0x77, 0x77, 0x2b, 0xe5, 0xc5, 0xe5, 0x4b, 0x03,
3846
0xaf, 0x76, 0xd5, 0xe1};
39-
47+
*/
48+
//Test2
49+
/*
50+
static char public_key[28] = {0x60, 0x52, 0x77, 0xfe, 0xdc, 0x80, 0xb1, 0x64,
51+
0x4f, 0x9e, 0x16, 0xdf, 0xde, 0x38, 0xeb, 0x4c,
52+
0xd6, 0xaa, 0xf4, 0xee, 0xb3, 0xf6, 0xd5, 0x70,
53+
0x57, 0x3, 0x1, 0x9f};
54+
*/
4055

4156
/**@brief Function for the Timer initialization.
4257
*
@@ -107,7 +122,17 @@ int main(void) {
107122
advertising_init(ADVERTISING_INTERVAL);
108123

109124
// Set advertisement data
110-
setAdvertisementData(raw_data, data_len);
125+
if (public_key[0] == 'O' &&
126+
public_key[1] == 'F' &&
127+
public_key[2] == 'F' &&
128+
public_key[3] == 'L' &&
129+
public_key[4] == 'I' &&
130+
public_key[5] == 'N' &&
131+
public_key[6] == 'E') {
132+
// Leave unconfigured
133+
} else {
134+
setAdvertisementData(raw_data, data_len);
135+
}
111136

112137
// Enable services
113138
services_init();

0 commit comments

Comments
 (0)