Skip to content

Commit

Permalink
Merge pull request #1 from fprwi6labs/dev
Browse files Browse the repository at this point in the history
Add source files
  • Loading branch information
fpistm authored Sep 22, 2017
2 parents 640c07c + b10b533 commit b093da0
Show file tree
Hide file tree
Showing 52 changed files with 15,748 additions and 0 deletions.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,77 @@
# SPBTLE-RF
Arduino library to support the Bluetooth (V4.1 compliant) SPBTLE-RF module

## API

The library provides a basic BLE class to configure and enable the Bluetooth module.
Each profile provides its own class. See Beacon and sensorDemo profiles.

## Examples

The library includes two sketches. They are very similar, one sketch provides a Beacon Service, an other a Sensor Service.

For the Beacon Service sketch, we can see on the monitor window all the initialization phase, and the message
"Beacon service start!" when the bluetooth module is started and ready.
Two mode are supported, UID mode and URL mode. On both mode, user can choose the bluetooth MAC address of the device by
configuring SERVER_BDADDR in the Arduino sketch.
On UID mode, user can choose the Namespace and the Instance. This data are sent to the associated device (for example your smartphone).
On URL mode, user can choose the webURL sended.

You can test this application by connecting it with your smartphone.
On Android, donwload the Beacon Scanner Apps (iBeacon & Eddystone Scanner by flurp laboratories). The Apps can
also be found [here](https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app).
Then start the app, it will ask you to enable the bluetooth on your smartphone. Start scanning and you will see the the device.
If you use it on UID mode, you will the see the Namespace and the instance.
If you use it on URL mode, you will see the URL, you can click on it and you will send the web page.


For the Sensor Service sketch, we can see on the monitor window all the initialization phase, and a message for each service started.
Three services are started : Acc, Environnemental and Time.
For testing the sketch, you can download on the playstore the "BLueNRG" application provided by STMicroelectronics.
Launch the application and enable Bluetooth on your smartphone. Connect it to the BLueNRG device. You will see all the services,
you can click on each one and read the data.


The SPBTLE-RF uses SPI. You need to configure the pin used for spi link.
SPIClass SPI_3(MOSI, MISO, CLK);

Choose the SPI used by the SPBTLE-RF, and the pinout of the device. A cheep select pin, spiIRQ pin, reset PIN and a led (optional) are required.
SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin);
SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin, LED pin);

Start the bluetooth module.
BTLE.begin();

Start the service. For example the BeaconService in UID_TYPE.
BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace);

## BLE stack

Version: 3.0.0
The Bluetooth stack comes from [STM32CubeExpansion_BLE1_V3.0.0](http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software-expansion/x-cube-ble1.html).

The BlueNRG stack is composed of some specific parts:

* **HCI** files provide API for HCI (Host Controller Interface) layer
* **GAP** files provide API for GAP (Generic Access Profile) layer
* **GATT** files provide API for GATT (Generic Attribute Profile) layer
* **L2CAP** files provide API for L2CAP (Logical Link Control and Adaptation Protocol) layer

More information about the different layers:
* https://www.bluetooth.com/specifications/bluetooth-core-specification
* https://www.bluetooth.com/specifications/gatt

## Note

At the compilation time a warning is raised about an IFR configuration not valid.
This is normal because the library proposes an API to update the firmware of the
BLE module but the configuration flag isn't declared. See STM32CubeExpansion_BLE1_V3.0.0
documentation for more information about the IFR updater.

## Documentation

You can find the source files at
https://github.com/stm32duino/SPBTLE-RF

The SPBTLE-RF module datasheet is available at
http://www.st.com/content/st_com/en/products/wireless-connectivity/bluetooth-bluetooth-low-energy/spbtle-rf.html
93 changes: 93 additions & 0 deletions examples/DISCO_IOT_BeaconDemo/DISCO_IOT_BeaconDemo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
DISCO_IOT_BeaconDemo
This sketch provides a default example how to use the BLE module of the
Discovery L475VG IoT board.
For the Beacon Service, two modes are supported:
- UID mode, you can choose the Namespace and the ID. This data are sent
to the associated device (for example your smartphone).
Or
- URL mode, you can choose the webURL sended.
You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR.
You can test this application by connecting it with your smartphone.
On Android, donwload any Beacon Scanner Apps (e.g. iBeacon & Eddystone Scanner
by flurp laboratories https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app).
Then start the app, enable the bluetooth on your smartphone, start scanning and
you will see the device.
If you use UID mode, you will the see the Namespace and the instance.
If you use URL mode, you will see the URL, you can click on it and you will
send to the web page.
*/


#include <SPI.h>
#include <SPBTLE_RF.h>
#include <beacon_service.h>

/* Configure SPI3
MOSI: PC12
MISO: PC11
SCLK: PC10
*/
SPIClass SPI_3(44, 43, 42);

// Configure BTLE pins
SPBTLERFClass BTLE(&SPI_3, 50, 57, 31, LED4);

// Mac address
uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03};

//Comment this line to use URL mode
#define USE_UID_MODE

#ifdef USE_UID_MODE
// Beacon ID, the 6 last bytes are used for NameSpace
uint8_t NameSpace[] = "DISCO_IOT";
uint8_t beaconID[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6};
#else
char url[] = "www.st.com";
#endif

void setup() {
Serial.begin(9600);

if(BTLE.begin())
{
Serial.println("Bluetooth module configuration error!");
while(1);
}

#ifdef USE_UID_MODE
// Enable the beacon service in UID mode
if(BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace))
{
Serial.println("Beacon service configuration error!");
while(1);
}
else
{
Serial.println("Beacon service started!");
}
#else
//Enable the beacon service in URL mode
if(BeaconService.begin(SERVER_BDADDR, url))
{
Serial.println("Beacon service configuration error!");
while(1);
}
else
{
Serial.println("Beacon service started!");
}
#endif
}

void loop() {
// Update the BLE module state
BTLE.update();
}
138 changes: 138 additions & 0 deletions examples/DISCO_IOT_SensorDemo/DISCO_IOT_SensorDemo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
DISCO_IOT_SensorDemo
This sketch provides a default example how to use the BLE module of the
Discovery L475VG IoT board.
For the Sensor Service sketch, 3 services are started : Acc, Environnemental and Time.
For testing the sketch, you can download on the playstore the "BlueNRG"
application provided by STMICROELECTRONICS.
Launch the application and enable Bluetooth on your smartphone. Connect it to
the BLueNRG device. You will see all the services, you can click on each one.
You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR.
Accelerometer values are updated on user action (press user button).
Environnemental values (Temperature, humidity and pressure) are updated each seconds.
Each minute a notification is sent to the user and seconds can be read.
*/

#include <SPI.h>
#include <SPBTLE_RF.h>
#include <sensor_service.h>

/* Configure SPI3
MOSI: PC12
MISO: PC11
SCLK: PC10
*/
SPIClass SPI_3(44, 43, 42);

// Configure BTLE pins
SPBTLERFClass BTLE(&SPI_3, 50, 57, 31, LED4);

const char *name = "BlueNRG";
uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03};

AxesRaw_t axes_data;
uint32_t previousSecond = 0;

void setup() {
int ret;

Serial.begin(9600);

if(BTLE.begin() == SPBTLERF_ERROR)
{
Serial.println("Bluetooth module configuration error!");
while(1);
}

if(SensorService.begin(name, SERVER_BDADDR))
{
Serial.println("Sensor service configuration error!");
while(1);
}

/* Configure the User Button in GPIO Mode */
pinMode(USER_BTN, INPUT);

ret = SensorService.Add_Acc_Service();

if(ret == BLE_STATUS_SUCCESS)
Serial.println("Acc service added successfully.");
else
Serial.println("Error while adding Acc service.");

ret = SensorService.Add_Environmental_Sensor_Service();

if(ret == BLE_STATUS_SUCCESS)
Serial.println("Environmental Sensor service added successfully.");
else
Serial.println("Error while adding Environmental Sensor service.");

randomSeed(analogRead(A0));

/* Instantiate Timer Service with two characteristics:
* - seconds characteristic (Readable only)
* - minutes characteristics (Readable and Notifiable )
*/
ret = SensorService.Add_Time_Service();

if(ret == BLE_STATUS_SUCCESS)
Serial.println("Time service added successfully.");
else
Serial.println("Error while adding Time service.");
}

void loop() {
BTLE.update();

if(SensorService.isConnected() == TRUE)
{
//Update accelerometer values
User_Process(&axes_data);

//Update time
SensorService.Update_Time_Characteristics();

if((millis() - previousSecond) >= 1000)
{
//Update environnemental data
//Data are set with random values but can be replace with data from sensors.
previousSecond = millis();
SensorService.Temp_Update(random(-100,400));
SensorService.Press_Update(random(95000,105000));
SensorService.Humidity_Update(random(0,100));
}
}
else
{
//Keep the Bluetooth module in discoverable mode
SensorService.setConnectable();
}
}

/**
* @brief Process user input (i.e. pressing the USER button on Nucleo board)
* and send the updated acceleration data to the remote client.
*
* @param AxesRaw_t* p_axes
* @retval None
*/
void User_Process(AxesRaw_t* p_axes)
{
/* Check if the user has pushed the button */
if(digitalRead(USER_BTN) == RESET)
{
while (digitalRead(USER_BTN) == RESET);

/* Update acceleration data */
p_axes->AXIS_X += 100;
p_axes->AXIS_Y += 100;
p_axes->AXIS_Z += 100;
SensorService.Acc_Update(p_axes);
}
}
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=SPBTLE-RF
version=1.0.0
author=STMicroelectronics, AMS, Wi6Labs
maintainer=stm32duino
sentence=This library includes drivers for ST's BlueNRG/BlueNRG-MS Bluetooth Low Energy device.
paragraph=This library is built for STM32 microcontrollers and comes with examples of implementation of the BLE drivers.
category=Communication
url=https://github.com/stm32duino/SPBTLE-RF
architectures=stm32
Loading

0 comments on commit b093da0

Please sign in to comment.