Skip to content

Commit b093da0

Browse files
authored
Merge pull request #1 from fprwi6labs/dev
Add source files
2 parents 640c07c + b10b533 commit b093da0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+15748
-0
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
11
# SPBTLE-RF
22
Arduino library to support the Bluetooth (V4.1 compliant) SPBTLE-RF module
3+
4+
## API
5+
6+
The library provides a basic BLE class to configure and enable the Bluetooth module.
7+
Each profile provides its own class. See Beacon and sensorDemo profiles.
8+
9+
## Examples
10+
11+
The library includes two sketches. They are very similar, one sketch provides a Beacon Service, an other a Sensor Service.
12+
13+
For the Beacon Service sketch, we can see on the monitor window all the initialization phase, and the message
14+
"Beacon service start!" when the bluetooth module is started and ready.
15+
Two mode are supported, UID mode and URL mode. On both mode, user can choose the bluetooth MAC address of the device by
16+
configuring SERVER_BDADDR in the Arduino sketch.
17+
On UID mode, user can choose the Namespace and the Instance. This data are sent to the associated device (for example your smartphone).
18+
On URL mode, user can choose the webURL sended.
19+
20+
You can test this application by connecting it with your smartphone.
21+
On Android, donwload the Beacon Scanner Apps (iBeacon & Eddystone Scanner by flurp laboratories). The Apps can
22+
also be found [here](https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app).
23+
Then start the app, it will ask you to enable the bluetooth on your smartphone. Start scanning and you will see the the device.
24+
If you use it on UID mode, you will the see the Namespace and the instance.
25+
If you use it on URL mode, you will see the URL, you can click on it and you will send the web page.
26+
27+
28+
For the Sensor Service sketch, we can see on the monitor window all the initialization phase, and a message for each service started.
29+
Three services are started : Acc, Environnemental and Time.
30+
For testing the sketch, you can download on the playstore the "BLueNRG" application provided by STMicroelectronics.
31+
Launch the application and enable Bluetooth on your smartphone. Connect it to the BLueNRG device. You will see all the services,
32+
you can click on each one and read the data.
33+
34+
35+
The SPBTLE-RF uses SPI. You need to configure the pin used for spi link.
36+
SPIClass SPI_3(MOSI, MISO, CLK);
37+
38+
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.
39+
SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin);
40+
SPBTLERFClass BTLE(SPI_X, CS pin, IRQ pin, reset pin, LED pin);
41+
42+
Start the bluetooth module.
43+
BTLE.begin();
44+
45+
Start the service. For example the BeaconService in UID_TYPE.
46+
BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace);
47+
48+
## BLE stack
49+
50+
Version: 3.0.0
51+
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).
52+
53+
The BlueNRG stack is composed of some specific parts:
54+
55+
* **HCI** files provide API for HCI (Host Controller Interface) layer
56+
* **GAP** files provide API for GAP (Generic Access Profile) layer
57+
* **GATT** files provide API for GATT (Generic Attribute Profile) layer
58+
* **L2CAP** files provide API for L2CAP (Logical Link Control and Adaptation Protocol) layer
59+
60+
More information about the different layers:
61+
* https://www.bluetooth.com/specifications/bluetooth-core-specification
62+
* https://www.bluetooth.com/specifications/gatt
63+
64+
## Note
65+
66+
At the compilation time a warning is raised about an IFR configuration not valid.
67+
This is normal because the library proposes an API to update the firmware of the
68+
BLE module but the configuration flag isn't declared. See STM32CubeExpansion_BLE1_V3.0.0
69+
documentation for more information about the IFR updater.
70+
71+
## Documentation
72+
73+
You can find the source files at
74+
https://github.com/stm32duino/SPBTLE-RF
75+
76+
The SPBTLE-RF module datasheet is available at
77+
http://www.st.com/content/st_com/en/products/wireless-connectivity/bluetooth-bluetooth-low-energy/spbtle-rf.html
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
3+
DISCO_IOT_BeaconDemo
4+
5+
This sketch provides a default example how to use the BLE module of the
6+
Discovery L475VG IoT board.
7+
8+
For the Beacon Service, two modes are supported:
9+
- UID mode, you can choose the Namespace and the ID. This data are sent
10+
to the associated device (for example your smartphone).
11+
Or
12+
- URL mode, you can choose the webURL sended.
13+
14+
You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR.
15+
16+
You can test this application by connecting it with your smartphone.
17+
On Android, donwload any Beacon Scanner Apps (e.g. iBeacon & Eddystone Scanner
18+
by flurp laboratories https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app).
19+
Then start the app, enable the bluetooth on your smartphone, start scanning and
20+
you will see the device.
21+
If you use UID mode, you will the see the Namespace and the instance.
22+
If you use URL mode, you will see the URL, you can click on it and you will
23+
send to the web page.
24+
25+
*/
26+
27+
28+
#include <SPI.h>
29+
#include <SPBTLE_RF.h>
30+
#include <beacon_service.h>
31+
32+
/* Configure SPI3
33+
MOSI: PC12
34+
MISO: PC11
35+
SCLK: PC10
36+
*/
37+
SPIClass SPI_3(44, 43, 42);
38+
39+
// Configure BTLE pins
40+
SPBTLERFClass BTLE(&SPI_3, 50, 57, 31, LED4);
41+
42+
// Mac address
43+
uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03};
44+
45+
//Comment this line to use URL mode
46+
#define USE_UID_MODE
47+
48+
#ifdef USE_UID_MODE
49+
// Beacon ID, the 6 last bytes are used for NameSpace
50+
uint8_t NameSpace[] = "DISCO_IOT";
51+
uint8_t beaconID[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6};
52+
#else
53+
char url[] = "www.st.com";
54+
#endif
55+
56+
void setup() {
57+
Serial.begin(9600);
58+
59+
if(BTLE.begin())
60+
{
61+
Serial.println("Bluetooth module configuration error!");
62+
while(1);
63+
}
64+
65+
#ifdef USE_UID_MODE
66+
// Enable the beacon service in UID mode
67+
if(BeaconService.begin(SERVER_BDADDR, beaconID, NameSpace))
68+
{
69+
Serial.println("Beacon service configuration error!");
70+
while(1);
71+
}
72+
else
73+
{
74+
Serial.println("Beacon service started!");
75+
}
76+
#else
77+
//Enable the beacon service in URL mode
78+
if(BeaconService.begin(SERVER_BDADDR, url))
79+
{
80+
Serial.println("Beacon service configuration error!");
81+
while(1);
82+
}
83+
else
84+
{
85+
Serial.println("Beacon service started!");
86+
}
87+
#endif
88+
}
89+
90+
void loop() {
91+
// Update the BLE module state
92+
BTLE.update();
93+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
3+
DISCO_IOT_SensorDemo
4+
5+
This sketch provides a default example how to use the BLE module of the
6+
Discovery L475VG IoT board.
7+
8+
For the Sensor Service sketch, 3 services are started : Acc, Environnemental and Time.
9+
For testing the sketch, you can download on the playstore the "BlueNRG"
10+
application provided by STMICROELECTRONICS.
11+
Launch the application and enable Bluetooth on your smartphone. Connect it to
12+
the BLueNRG device. You will see all the services, you can click on each one.
13+
14+
You can choose the bluetooth MAC address of the device by configuring SERVER_BDADDR.
15+
16+
Accelerometer values are updated on user action (press user button).
17+
Environnemental values (Temperature, humidity and pressure) are updated each seconds.
18+
Each minute a notification is sent to the user and seconds can be read.
19+
20+
*/
21+
22+
#include <SPI.h>
23+
#include <SPBTLE_RF.h>
24+
#include <sensor_service.h>
25+
26+
/* Configure SPI3
27+
MOSI: PC12
28+
MISO: PC11
29+
SCLK: PC10
30+
*/
31+
SPIClass SPI_3(44, 43, 42);
32+
33+
// Configure BTLE pins
34+
SPBTLERFClass BTLE(&SPI_3, 50, 57, 31, LED4);
35+
36+
const char *name = "BlueNRG";
37+
uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x03};
38+
39+
AxesRaw_t axes_data;
40+
uint32_t previousSecond = 0;
41+
42+
void setup() {
43+
int ret;
44+
45+
Serial.begin(9600);
46+
47+
if(BTLE.begin() == SPBTLERF_ERROR)
48+
{
49+
Serial.println("Bluetooth module configuration error!");
50+
while(1);
51+
}
52+
53+
if(SensorService.begin(name, SERVER_BDADDR))
54+
{
55+
Serial.println("Sensor service configuration error!");
56+
while(1);
57+
}
58+
59+
/* Configure the User Button in GPIO Mode */
60+
pinMode(USER_BTN, INPUT);
61+
62+
ret = SensorService.Add_Acc_Service();
63+
64+
if(ret == BLE_STATUS_SUCCESS)
65+
Serial.println("Acc service added successfully.");
66+
else
67+
Serial.println("Error while adding Acc service.");
68+
69+
ret = SensorService.Add_Environmental_Sensor_Service();
70+
71+
if(ret == BLE_STATUS_SUCCESS)
72+
Serial.println("Environmental Sensor service added successfully.");
73+
else
74+
Serial.println("Error while adding Environmental Sensor service.");
75+
76+
randomSeed(analogRead(A0));
77+
78+
/* Instantiate Timer Service with two characteristics:
79+
* - seconds characteristic (Readable only)
80+
* - minutes characteristics (Readable and Notifiable )
81+
*/
82+
ret = SensorService.Add_Time_Service();
83+
84+
if(ret == BLE_STATUS_SUCCESS)
85+
Serial.println("Time service added successfully.");
86+
else
87+
Serial.println("Error while adding Time service.");
88+
}
89+
90+
void loop() {
91+
BTLE.update();
92+
93+
if(SensorService.isConnected() == TRUE)
94+
{
95+
//Update accelerometer values
96+
User_Process(&axes_data);
97+
98+
//Update time
99+
SensorService.Update_Time_Characteristics();
100+
101+
if((millis() - previousSecond) >= 1000)
102+
{
103+
//Update environnemental data
104+
//Data are set with random values but can be replace with data from sensors.
105+
previousSecond = millis();
106+
SensorService.Temp_Update(random(-100,400));
107+
SensorService.Press_Update(random(95000,105000));
108+
SensorService.Humidity_Update(random(0,100));
109+
}
110+
}
111+
else
112+
{
113+
//Keep the Bluetooth module in discoverable mode
114+
SensorService.setConnectable();
115+
}
116+
}
117+
118+
/**
119+
* @brief Process user input (i.e. pressing the USER button on Nucleo board)
120+
* and send the updated acceleration data to the remote client.
121+
*
122+
* @param AxesRaw_t* p_axes
123+
* @retval None
124+
*/
125+
void User_Process(AxesRaw_t* p_axes)
126+
{
127+
/* Check if the user has pushed the button */
128+
if(digitalRead(USER_BTN) == RESET)
129+
{
130+
while (digitalRead(USER_BTN) == RESET);
131+
132+
/* Update acceleration data */
133+
p_axes->AXIS_X += 100;
134+
p_axes->AXIS_Y += 100;
135+
p_axes->AXIS_Z += 100;
136+
SensorService.Acc_Update(p_axes);
137+
}
138+
}

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=SPBTLE-RF
2+
version=1.0.0
3+
author=STMicroelectronics, AMS, Wi6Labs
4+
maintainer=stm32duino
5+
sentence=This library includes drivers for ST's BlueNRG/BlueNRG-MS Bluetooth Low Energy device.
6+
paragraph=This library is built for STM32 microcontrollers and comes with examples of implementation of the BLE drivers.
7+
category=Communication
8+
url=https://github.com/stm32duino/SPBTLE-RF
9+
architectures=stm32

0 commit comments

Comments
 (0)