File tree 1 file changed +51
-0
lines changed
libraries/Apollo3/examples/Example11_BLEAdvertise
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ BLEAdvertise
3
+
4
+ This example creates a BLE peripheral which advertises itself as Artemis.
5
+ Central devices may connect with it, but there are no services or
6
+ characteristics to interact with.
7
+
8
+ Based on a stripped down version of the LED example from the ArduinoBLE examples
9
+ */
10
+
11
+ #include < ArduinoBLE.h> // http://librarymanager/All#ArduinoBLE_IoT
12
+
13
+ void setup () {
14
+ Serial.begin (115200 );
15
+ while (!Serial);
16
+
17
+ // begin initialization
18
+ if (!BLE.begin ()) {
19
+ Serial.println (" Starting BLE failed!" );
20
+ while (1 );
21
+ }
22
+
23
+ // set advertised local name and service UUID:
24
+ BLE.setLocalName (" Artemis" );
25
+
26
+ // start advertising
27
+ BLE.advertise ();
28
+
29
+ Serial.println (" BLE advertising as 'Artemis'" );
30
+ }
31
+
32
+ void loop () {
33
+ // listen for BLE peripherals to connect:
34
+ BLEDevice central = BLE.central ();
35
+
36
+ // if a central is connected to peripheral:
37
+ if (central) {
38
+ Serial.print (" Connected to central: " );
39
+ // print the central's MAC address:
40
+ Serial.println (central.address ());
41
+
42
+ // while the central is still connected to peripheral...
43
+ while (central.connected ()) {
44
+ // Nothing to do here
45
+ }
46
+
47
+ // when the central disconnects, print it out:
48
+ Serial.print (F (" Disconnected from central: " ));
49
+ Serial.println (central.address ());
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments