# Xenon example BLE code

**URL:** <https://community.particle.io/t/xenon-example-ble-code/54192>\
**Category:** Getting Started\
**Created:** [January 13, 2020, 6:15pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192 "2020-01-13T18:15:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 6:15pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/1 "2020-01-13T18:15:25Z")

</div>

Hi,

is there a Xenon example BLE code that I can use to start my BLE development ? I would like to use it as a BLE only product and not use it in a mesh network.

Thanks

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 13, 2020, 6:16pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/2 "2020-01-13T18:16:27Z")

</div>

Have you tried it with these?  
[https://docs.particle.io/tutorials/device-os/bluetooth-le/#examples](https://docs.particle.io/tutorials/device-os/bluetooth-le/#examples)

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 6:26pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/3 "2020-01-13T18:26:00Z")

</div>

I have hard time compiling an empty project. It fails to compile when there’s one file with an empty setup and empty loop. I was hoping there is a good starting project with Xenon. Is there such a thing?

Here’s me terminal output:

```nohighlight
> Executing task: make -f 'C:\Users\301312\.particle\toolchains\buildscripts\1.8.0\Makefile' compile-all -s <

:::: COMPILING APPLICATION & DEVICE OS

  /cygdrive/c/Users/301312/.particle/toolchains/deviceOS/1.4.4/firmware-1.4.4/modules/photon/system-part1/makefile /cygdrive/c/Users/301312/.particle/toolchains/deviceOS/1.4.4/firmware-1.4.4/modules/photon/system-part2/makefile /cygdrive/c/Users/301312/.particle/toolchains/deviceOS/1.4.4/firmware-1.4.4/modules/photon/user-part/makefile
../../../build/target/system-part1/platform-6-m/./src/module_system_part1.o:(.rodata.system_part1_module+0xc): undefined reference to `dynalib_services'
../../../build/target/system-part1/platform-6-m/./src/newlib.o: In function `__cxa_pure_virtual':
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\modules\photon\system-part1/src/../../../../hal/src/stm32/newlib.cpp:64: undefined reference to `panic_'
../../../build/target/system-part1/platform-6-m/./src/newlib.o: In function `__assert_func':
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\modules\photon\system-part1/src/../../../../hal/src/stm32/newlib.cpp:85: undefined reference to `log_message'
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\modules\photon\system-part1/src/../../../../hal/src/stm32/newlib.cpp:86: undefined reference to `panic_'
../../../build/target/communication/platform-6-m-prod-6/\libcommunication.a(lightssl_protocol.o): In function `particle::protocol::LightSSLProtocol::get_status(protocol_status*) const':
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\communication/src/lightssl_protocol.h:84: undefined reference to `panic_'
../../../build/target/communication/platform-6-m-prod-6/\libcommunication.a(protocol.o): In function `particle::protocol::Protocol::generate_and_send_description(particle::protocol::MessageChannel&, particle::protocol::Message&, unsigned int, int)':
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\communication/src/protocol.cpp:541: undefined reference to `panic_'
../../../build/target/communication/platform-6-m-prod-6/\libcommunication.a(communication_diagnostic.o): In function `particle::AbstractDiagnosticData::AbstractDiagnosticData(unsigned short, char const*, diag_type)':
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\communication/../wiring/inc/spark_wiring_diagnostics.h:483: undefined reference to `diag_register_source'
C:\Users\301312\.particle\toolchains\deviceOS\1.4.4\firmware-1.4.4\communication/../wiring/inc/spark_wiring_diagnostics.h:483: undefined reference to `diag_register_source'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [../../../build/module.mk:235: ../../../build/target/system-part1/platform-6-m/system-part1.elf] Error 1
make[1]: *** [makefile:86: /cygdrive/c/Users/301312/.particle/toolchains/deviceOS/1.4.4/firmware-1.4.4/modules/photon/system-part1/makefile] Error 2
make: *** [C:\Users\301312\.particle\toolchains\buildscripts\1.8.0\Makefile:60: compile-all] Error 2
The terminal process terminated with exit code: 2

Press any key to close the terminal.

```

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 6:30pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/4 "2020-01-13T18:30:39Z")

</div>

I should add that I am using VS Code and I want to do local compile and flash.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 13, 2020, 6:33pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/5 "2020-01-13T18:33:32Z")

</div>

How did you created the project?  
Have you used the respective task?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/7/4/747a72fee503223dabb082c39deefebfadae7a6d.png)  
Your output also suggests you are building for Photon and not Xenon  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/5/8/584a744a96158c4fcc170d2fb89c66fb4429e435.png)  
You may want to use  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/c/8/c86bec839396f357827dc2665f0727f53f269869.png)

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 6:35pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/6 "2020-01-13T18:35:31Z")

</div>

I started with Create new project by using Particle Workbench button.  
I will try Particle: Configure Project for Device now and let you know if that fixes it.

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 6:59pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/7 "2020-01-13T18:59:09Z")

</div>

I ran configure and it changed my project settings to Xenon.  
Then I ran compile and it looks like it’s compiling but it never ends the task. I closed VS code, I re created the project and it’s still stuck. You can see on the bottom left it’s still “building…”  
Is there any other step I’m missing?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/5/3/53e4673167d0d9bed76b59008ca4ede1fbe833c3.png)

Edit:  
When I created my project it asked me for a Device ID or name and I hit ENTER without entering that box. Is that a problem?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 13, 2020, 7:07pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/8 "2020-01-13T19:07:21Z")

</div>

The first time you build device OS plus application this will take reaaaally long (especially on Windows).

You can enable verbose output to see what’s going on  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/e/8ecb5295945475c9da8bdfe6e6b753c4ded8c486.png)

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 7:10pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/9 "2020-01-13T19:10:35Z")

</div>

What is a really long time? an hour or longer?

I don’t have Enable Verbose Local Compiler Logging option in my list of commands

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 13, 2020, 7:13pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/10 "2020-01-13T19:13:55Z")

</div>

It’s not a command it’s a setting  
File menu

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/6/66009736b0ff43e587d171ce2b7ba8875d1c85c3.png)

I’ve had it take just short half an hour.

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 13, 2020, 8:18pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/11 "2020-01-13T20:18:28Z")

</div>

It took longer than half an hour, maybe close to an hour but it finally compiled. That was very long, I’m not used to having to wait that long. I wish that was somewhere in the documentation 😉

I got it to flash successfully also. Now I can move to writing code for BLE.  
I copied the code from your link and it advertises my Xenon device. However I couldn’t see it with nRF Toolbox app that the BLT tutorial suggests I use. I used NRF Connect app to find the device. I don’t know why NRF toolbox can’t see it.

I would like to changes BLE advertising and advertising packet contents. How do I get access to those files?

I’m new to how Particle source files work.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 13, 2020, 9:03pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/12 "2020-01-13T21:03:17Z")

</div>

> [@grassclippings](#):
>
> I would like to changes BLE advertising and advertising packet contents. How do I get access to those files?

No files, API calls 😉  
There are several example in the tutorials section I linked above.  
And there also is this  
[https://docs.particle.io/reference/device-os/firmware/argon/#bleadvertisingdata](https://docs.particle.io/reference/device-os/firmware/argon/#bleadvertisingdata)

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 14, 2020, 11:09pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/13 "2020-01-14T23:09:14Z")

</div>

API calls will make it easier I hope, I will play around and try to make it work 🙂

Thank you!

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 15, 2020, 10:19pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/14 "2020-01-15T22:19:20Z")

</div>

I tried changing the advertising name and it didn’t work.  
Then I removed all code in setup() my device was still advertising. Nothing works.  
I used iOS and Android apps.  
What the heck going on? Has anyone been able to get Xenon to work? Is this an issue with Xenon?

```cpp
void setup() {
    //(void)logHandler; // Does nothing, just to eliminate the unused variable warning
    // BLE.addCharacteristic(temperatureMeasurementCharacteristic);
    // BLE.addCharacteristic(batteryLevelCharacteristic);
    // batteryLevelCharacteristic.setValue(&lastBattery, 1);
    // BleAdvertisingData advData;
    // advData.appendLocalName(“my name”);
    // While we support both the health thermometer service and the battery service, we
    // only advertise the health thermometer. The battery service will be found after
    // connecting.
    // advData.appendServiceUUID(healthThermometerService);
    // Continuously advertise when not connected
    //BLE.advertise(&advData);
    //BLE.stopAdvertising();
}

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 16, 2020, 5:59am UTC](https://community.particle.io/t/xenon-example-ble-code/54192/15 "2020-01-16T05:59:24Z")

</div>

Your update does probably not stick?  
In such circumstances you'd typically add some _different active_ behaviour that can be observed from the outside to check whether your new code actually stuck.

> [@grassclippings](#):
>
> Has anyone been able to get Xenon to work?

Yes

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 16, 2020, 3:45pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/16 "2020-01-16T15:45:44Z")

</div>

What do you mean by different active behavior? BLE related or non BLE related?

And why wouldn’t it stick? If I compiled and flashed some code then this new code should be flashed to the flash memory. How can it not execute this new code?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 16, 2020, 3:55pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/17 "2020-01-16T15:55:33Z")

</div>

> [@grassclippings](#):
>
> What do you mean by different active behavior?

e.g. some LED blinking in one code and then _another_ blink pattern for the next code. Or some `Serial.println()` message for one version and then some other message for the next.

> [@grassclippings](#):
>
> BLE related or non BLE related?

Since this BLE is what you wonder whether it's working or not I would _ **not** _ be using _it_ for confirming itself.

> [@grassclippings](#):
>
> And why wouldn’t it stick?

First confirm whether this _is_ the case, once that's confirmed you could investigate the possible reasons - of which are multiple.

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 16, 2020, 5:33pm UTC](https://community.particle.io/t/xenon-example-ble-code/54192/18 "2020-01-16T17:33:11Z")

</div>

I used Serial.println() and nothing was printed. This is my code in setup():

Serial.begin();

Serial.println(“Hello&nbsp;World!”);

---

<div class="post-metadata">

**Author:** ![grassclippings](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@grassclippings](https://community.particle.io/u/grassclippings)\
**Post date:** [January 17, 2020, 1:38am UTC](https://community.particle.io/t/xenon-example-ble-code/54192/19 "2020-01-17T01:38:00Z")

</div>

@ScruffR What are my other options? You mentioned multiple reasons in an earlier post.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 17, 2020, 5:56am UTC](https://community.particle.io/t/xenon-example-ble-code/54192/20 "2020-01-17T05:56:07Z")

</div>

A single `Serial.println("Hello World!")` in `setup()` may easily be missed as it may be happening _before_ the USB enumeration process has been completed.  
I’d put that either into `loop()` or hook it up to the MODE button via `System.on()` to trigger on demand.

Also a D7 LED blink pattern can provide continous feedback.  
Another option may be taking over the RGB LED via `RGB.control(true)` to set a custom colour.

You can also run `particle binary inspect <yourFirmware.bin>` file to ensure it’s actually built for the correct platform.  
You may also try `particle flash --usb <yourFirmware.bin> -v` to get a more verbose output regarding the flashing process.

[Next page](https://community.particle.io/t/xenon-example-ble-code/54192.md?page=2)
