Xenon example BLE code

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

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

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:

> 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.

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

How did you created the project?
Have you used the respective task?
image
Your output also suggests you are building for Photon and not Xenon
image
You may want to use
image

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.

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?

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?

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

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

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

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

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 :wink:

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.

No files, API calls :wink:
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

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

Thank you!

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?

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();
}

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.

Yes

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?

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.

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

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

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

Serial.begin();

Serial.println(“Hello World!”);

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

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.