Skip to content

Commit 6837dc5

Browse files
committed
Update instructions and add advertised name setting function
1 parent 3ab6981 commit 6837dc5

File tree

4 files changed

+86
-20
lines changed

4 files changed

+86
-20
lines changed

libraries/Examples/examples/Example8_BLE_LED/BLE_example.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ void set_next_wakeup(void);
5757
void button_handler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
5858
extern void AppUiBtnTest(uint8_t btn);
5959

60+
void setAdvName(const char* str);
6061

6162
#endif // _BLE_EXAMPLE_H_

libraries/Examples/examples/Example8_BLE_LED/BLE_example_funcs.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "BLE_example.h"
22

3+
extern "C" void set_adv_name( const char* str );
4+
void setAdvName(const char* str){
5+
set_adv_name( str );
6+
}
37

48
//*****************************************************************************
59
//

libraries/Examples/examples/Example8_BLE_LED/Example8_BLE_LED.ino

+36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1+
/*
2+
Analog to digital conversion
3+
By: Owen Lyke
4+
SparkFun Electronics
5+
Date: Aug 27, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example demonstrates basic BLE server (peripheral) functionality for the Apollo3 boards.
10+
11+
How to use this example:
12+
- Install the nRF Connect app on your mobile device (must support BLE bluetooth)
13+
- Make sure you select the correct board definition from Tools-->Board
14+
(it is used to determine which pin controls the LED)
15+
- Compile and upload the example to your board with the Arduino "Upload" button
16+
- In the nRF Connect app look for the device in the "scan" tab.
17+
(By default it is called "Artemis BLE" but you can change that below)
18+
- Once the device is found click "connect"
19+
- The GATT server will load with 5 services:
20+
- Generic Access
21+
- Generic Attribute
22+
- Link Loss
23+
- Immediate Alert
24+
- Tx Power
25+
- For this example we've hooked into the 'Immediate Alert' service.
26+
You can click on that pane and it will expand to show an "upload" button.
27+
Use the upload button to write one of three values (0x00, 0x01, or 0x02)
28+
- When you send '0x00' (aka 'No alert') the LED will be set to off
29+
- When you send either '0x01' or '0x02' the LED will be set to on
30+
*/
131
#include "BLE_example.h"
232

33+
#define BLE_PERIPHERAL_NAME "Artemis BLE" // Up to 29 characters
34+
335
void setup() {
436

537
#ifdef DEBUG
@@ -11,6 +43,10 @@ void setup() {
1143
pinMode(LED_BUILTIN, OUTPUT);
1244
set_led_low();
1345

46+
//
47+
// Configure the peripheral's advertised name:
48+
setAdvName(BLE_PERIPHERAL_NAME);
49+
1450
//
1551
// Boot the radio.
1652
//

libraries/Examples/examples/Example8_BLE_LED/nus_main.c

+45-20
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727

2828
#include <string.h>
29+
#include <stdbool.h>
2930
#include "wsf_types.h"
3031
#include "bstream.h"
3132
#include "wsf_msg.h"
@@ -156,27 +157,51 @@ static uint8_t localIrk[] =
156157
Advertising Data
157158
**************************************************************************************************/
158159

160+
// /*! advertising data, discoverable mode */
161+
// static const uint8_t tagAdvDataDisc[] =
162+
// {
163+
// /*! flags */
164+
// 2, /*! length */
165+
// DM_ADV_TYPE_FLAGS, /*! AD type */
166+
// DM_FLAG_LE_LIMITED_DISC | /*! flags */
167+
// DM_FLAG_LE_BREDR_NOT_SUP,
168+
169+
// /*! tx power */
170+
// 2, /*! length */
171+
// DM_ADV_TYPE_TX_POWER, /*! AD type */
172+
// 0, /*! tx power */
173+
174+
// /*! device name */
175+
// 4, /*! length */
176+
// DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
177+
// 'T',
178+
// 'a',
179+
// 'g'
180+
// };
181+
159182
/*! advertising data, discoverable mode */
160-
static const uint8_t tagAdvDataDisc[] =
161-
{
162-
/*! flags */
163-
2, /*! length */
164-
DM_ADV_TYPE_FLAGS, /*! AD type */
165-
DM_FLAG_LE_LIMITED_DISC | /*! flags */
166-
DM_FLAG_LE_BREDR_NOT_SUP,
167-
168-
/*! tx power */
169-
2, /*! length */
170-
DM_ADV_TYPE_TX_POWER, /*! AD type */
171-
0, /*! tx power */
172-
173-
/*! device name */
174-
4, /*! length */
175-
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
176-
'T',
177-
'a',
178-
'g'
179-
};
183+
#define MAX_ADV_DATA_LEN 31
184+
uint8_t tagAdvDataDisc[MAX_ADV_DATA_LEN] = {0};
185+
186+
void set_adv_name( const char* str ){
187+
uint8_t indi = 0;
188+
bool done = false;
189+
do{
190+
if( *(str+indi) == 0 ){
191+
done = true;
192+
}else{
193+
tagAdvDataDisc[2+indi] = *(str+indi); // copies characters from str into the data
194+
indi++;
195+
if(indi >= (MAX_ADV_DATA_LEN-2)){
196+
done = true;
197+
}
198+
}
199+
}while(!done);
200+
tagAdvDataDisc[0] = 30; // sets the 'length' field (note: if the sum of 'length' fields does not match the size of the adv data array then there can be problems!)
201+
tagAdvDataDisc[1] = DM_ADV_TYPE_LOCAL_NAME; // sets the 'type' field
202+
203+
// debug_printf("adv data: %s\n", str);
204+
}
180205

181206
/*! scan data */
182207
static const uint8_t tagScanData[] =

0 commit comments

Comments
 (0)