aanon4 / BlueBasic

BASIC interpreter for CC2540 and CC2541 Bluetooth LE chips
https://gitlab.com/timwilkinson/BlueBasic
97 stars 55 forks source link

Advertising interval #2

Closed gregwinn closed 9 years ago

gregwinn commented 9 years ago

Hello again! I have been using BlueBasic for a few days now and love it so thank you for making it!!

I am looking to set the Advertising interval on the iBeacon example but i am not 100% sure how to change that... Is this something you have built in? Any examples would be much appreciated!

aanon4 commented 9 years ago

There are a bunch of constants you can change as follows:

BTSET ,

For advertising you want to mess with the following properties:

LIM_DISC_ADV_INT_MIN LIM_DISC_ADV_INT_MAX GEN_DISC_ADV_INT_MIN GEN_DISC_ADV_INT_MAX GEN_DISC_ADV_MIN LIM_ADV_TIMEOUT

The values are all in milliseconds (I think ... the CC254X has some odd choices for these values). You can find descriptions of each of these in the TI BLE Vendor Specific HCI Guide. They usually prefix these with TGAP_ (if you're searching the PDF).

gregwinn commented 9 years ago

Thank you!

gregwinn commented 9 years ago

@aanon4 Can you give me an example using "BTSET" to set "LIM_DISC_ADV_INT_MIN"? I am getting bad expression back but my BASIC skills are a bit rusty :)

gregwinn commented 9 years ago

@aanon4 Nevermind! I took a look though the code i found i was using it wrong!

Below is the way i was trying

BTSET LIM_DISC_ADV_INT_MIN = 250

The correct way.

BTSET LIM_DISC_ADV_INT_MIN, 250
aanon4 commented 9 years ago

Looking back at my original reply to you, I see the command format got eaten (I used angled brackets which I guess it didnt like so much). Sorry about that.

gregwinn commented 9 years ago

Sorry to reopen this Issue also but after review it looks like I am not setting the Intervals correctly... Here is what i am doing:

// Stop Autorun
AUTORUN OFF
OK
BTSET LIM_DISC_ADV_INT_MIN, 350
OK
BTSET GEN_DISC_ADV_INT_MIN, 350
OK
BTSET LIM_DISC_ADV_INT_MAX, 350
OK
BTSET GEN_DISC_ADV_INT_MAX, 350
OK
AUTORUN ON
OK

Now to check the values I: 1) Restart BB Console 2) Reconnect to the beacon and run:

PRINT LIM_DISC_ADV_INT_MIN
6
OK

As you see I get "6" back and not the 350 I am looking for. I must be missing something, any ideas? :(

gregwinn commented 9 years ago

Using the App on my phone, I show if i set:

// ADVERT INTERVAL
// 1600 * 625us = 1second
BTSET LIM_DISC_ADV_INT_MIN, 1600 
BTSET GEN_DISC_ADV_INT_MIN, 1600
BTSET LIM_DISC_ADV_INT_MAX, 1600
BTSET GEN_DISC_ADV_INT_MAX, 1600

Updates every second or so...

To test making sure i was not going crazy i then changed it back to all 350:

// ADVERT INTERVAL
// 1600 * 625us = 1second
BTSET LIM_DISC_ADV_INT_MIN, 350 
BTSET GEN_DISC_ADV_INT_MIN, 350
BTSET LIM_DISC_ADV_INT_MAX, 350
BTSET GEN_DISC_ADV_INT_MAX, 350

And updates where flying in faster than 1 second... So it seems to be doing the correct thing but I just can not PRINT the constant out after I had set it... Or I am just going crazy!

aanon4 commented 9 years ago

Think about the bluetooth parameters as an array of values, each with a key referencing them. So to set one you use:

BTSET <key>,<value>

To read one back you do:

PRINT BTGET(<key>)

aanon4 commented 9 years ago

And yes, the bluetooth spec uses some very random units for various values. So far I've not tried to scale them into something sensible at the BASIC level, but maybe that'd be more sensible.

gregwinn commented 9 years ago

Love it, Thank you!

PRINT BTGET(LIM_DISC_ADV_INT_MIN)
1600
OK
gregwinn commented 9 years ago

Getting "Error" when setting:

BTSET GEN_DISC_ADV_INT_MAX, 1600

Using latest hex file and BBConsole.

Any Idea?

gregwinn commented 9 years ago

Sorry here is the full view:

PRINT BTGET(LIM_DISC_ADV_INT_MIN)
Bad expression
BTSET LIM_DISC_ADV_INT_MIN, 1600 
Error
aanon4 commented 9 years ago

A little command renaming to be more BASIC-like:

BTSET -> BTPOKE BTGET -> BTPEEK

gregwinn commented 9 years ago

Very good, thanks!