SJ cartoon avatar

Embedded BGScript, BGLib, and BGAPI Explained

During much of my time playing around with BlueGiga’s BLE112 and some of their other products, one thing that always managed to confuse me was the difference between BGScript, BGLib, and BGAPI.

It’s not that they are particularly tough topics to understand, it’s just that it is somewhat difficult to find information on their differences and applications. The documentation is okay, but then I read so-and-so’s blog and I see implications which make me think differently. Then, I use and implement them myself, and get a completely different interpretation.

Lucky for me, Jeff at Bluegiga sent over a knowledge-base article that cleared everything up. The annoying part is that these knowledge base articles are hidden behind the Tech Forum and Zendesk logins, thus extremely difficult (if not impossible) to find by Googling.

I’m not going to re-post his KB article, which I think should be required reading for anyone playing around with both BGScript and BGAPI (like me), but I’ll post a small selection.

I’m doing throughput testing of the BLE112, and have some interesting results in a BGScript environment. Now, I need to do the same test with an external MCU, using BGAPI. I will post the results of my findings (as well as the associated code) once I finish, as I’ve seen a lot of BLE throughput claims, but none come with code - so they aren’t reproducible.

Jeff’s summary of BGScript, BGLib, and BGAPI

BGScript is our custom scripting language used for on-module applications. BGScript only runs on Bluegiga modules and dongles.

BGAPI is a custom binary protocol used to externally control our modules and dongles. BGAPI is a protocol specification only.

BGLib is an ANSI C reference implementation of the BGAPI binary protocol. BGLib only runs outside of our modules and dongles

BGScript is primarily useful to take advantage of the reasonably powerful CC2540 microcontroller used in our BLE112/BLED112, while at the same time avoiding the need for custom C programming or the need for an IAR compiler license. BGScript is a very simple scripting language which takes care of the Bluetooth Smart stack internally, exposing only what is necessary in the form of easy commands and events.

The difference between BGScript and BGLib (or your own implementation of the BGAPI) is that BGScript allows you to run an application right on the module of dongle, whereas BGLib uses the binary API to send commands and receive events from an external device–typically a microcontroller, but anything that can communicate over UART directly or a USB CDC virtual serial port. In short, BGScript is for stand-alone applications that run directly on the module or dongle, and BGLib/BGAPI is for external control.

This quote was pulled directly from this KB article. The article also has some visual explanations of the differences, and a very good side-by-side of a simple BGScript snippet against it’s equivalent BGAPI snippet.