Using BLE with 1.3. How to set the local name of the device to show in the advertising packet

Actually I meant the sample that comes with the library (without any modifications)

#include "BleSerialPeripheralRK.h"

SerialLogHandler logHandler;

SYSTEM_THREAD(ENABLED);

// First parameter is the transmit buffer size, second parameter is the receive buffer size
BleSerialPeripheralStatic<256, 256> bleSerial;

const unsigned long TRANSMIT_PERIOD_MS = 2000;
unsigned long lastTransmit = 0;
int counter = 0;


void setup() {
	Serial.begin();

	// This must be called from setup()!
	bleSerial.setup();

	// If you don't have any other services to advertise, just call advertise().
	// Otherwise, call getServiceUuid() to get the serial service UUID and add that to your
	// custom advertising data payload and call BLE.advertise() yourself with all of your necessary
	// services added.
	bleSerial.advertise();
}

void loop() {
	// This must be called from loop() on every call to loop.
	bleSerial.loop();

	// Print out anything we receive
	if(bleSerial.available()) {
		String s = bleSerial.readString();

		Log.info("received: %s", s.c_str());
	}

	if (millis() - lastTransmit >= TRANSMIT_PERIOD_MS) {
		lastTransmit = millis();

		// Every two seconds, send something to the other side
		bleSerial.printlnf("testing %d", ++counter);
		Log.info("counter=%d", counter);
	}
}

This is only advertises the UUID: 6e400001-b5a3-f393-e0a9-e50e24dcca9e service but once connected it doesn’t expose it

nRF Connect and Bluefruit app can only see these four services

UUID: 0x1800
UUID: 0x1801
UUID: 6fa90001-5c4e-48a8-94f4-8030546f46fc
UUID: f5720000-13a9-49dd-ac15-f87b7427e37b

but not the expected

UUID: 6e400001-b5a3-f393-e0a9-e50e24dcca9e

(Argon 1.3.0-rc.1)

Yea the code straight from his example worked just fine.

I just increased the TX buffer size and then changed the data that was being sent out over Serial BLE.

Then I turned off Wifi & Mesh to see how low the power consumption was.

Then I started asking about how to change the Local Name for the BLE and here we are now not knowing how to actually make that happen easily.

Is this a bug?

You mean, with that code you can connect via Bluefruit and send data to the device?
This is what I get with that code when I connect to the device

This is how it looks with the BLEPeripheral example

I'd consider this a bug in the library.

Yea, works perfect. I just don’t know how to change the Argon—xxxxx to the My-name like you have it.

I’m using this library: BLESerial library alternatives

That’s what I’m using too :confused:

@ScruffR On IOS or Android?

On android version of Adafruit BLfruit I get hex for the device name.

Show me the code that changed the Name to myName :slight_smile:

Android (Samsung) I’ll try other devices tomorrow.

In the mean time can you share the code that allowed you to change the name to “myName”? :wink:

That was exactly what we discussed earlier

BleAdvertisingData data;                            // prepare a fresh/empty advertising data instance
data.appendLocalName("myName");                     // give the device a name to advertise (can be anywhere in the bundle)
data.appendServiceUUID(bleSerial.getServiceUuid()); // add the UUID that is created by the bleSerial object
// optionally add any additional service UUIDs
// optionally add any custom data you want (if it still fits)
BLE.advertise(&data);        
1 Like

That works.

I opened it on nRF Connect app on my android phone.

The code ended up looking like this:

I changed the name and it does show up in Bluefruit in iOS.

Looks like it’s still using the Cached name.

The nRF app picks up on the new name without any problems.

And on a brand new device and Bluefruit app the new name shows up as we want it to :slight_smile:

Everything is working!

1 Like