This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:iot_6 [2024/05/03 18:02] – [Steps] ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_6 [2024/05/04 08:10] (current) – ktokarz | ||
---|---|---|---|
Line 48: | Line 48: | ||
While none of the standard UUIDs fits your device you need to define your own UUID. It must be 128-bit long and can be randomly generated with the tool available on the website https:// | While none of the standard UUIDs fits your device you need to define your own UUID. It must be 128-bit long and can be randomly generated with the tool available on the website https:// | ||
The service UUID and characteristic UUID must differ. Although they can be completely different in many implementations the UUIDs of characteristics grouped under one service differ on one digit. | The service UUID and characteristic UUID must differ. Although they can be completely different in many implementations the UUIDs of characteristics grouped under one service differ on one digit. | ||
- | < | + | < |
#define SERVICE_UUID | #define SERVICE_UUID | ||
#define CHARACTERISTIC_UUID " | #define CHARACTERISTIC_UUID " | ||
Line 63: | Line 63: | ||
The function creates and initialises the BLE device instance named "SUT STM BLE". It creates a service with the characteristic, | The function creates and initialises the BLE device instance named "SUT STM BLE". It creates a service with the characteristic, | ||
- | < | + | < |
void setup() { | void setup() { | ||
| | ||
Line 90: | Line 90: | ||
</ | </ | ||
- | In the loop function, we need to call a function waiting for the connection of the client. | + | In the loop function, we need to call a function waiting for the connection of the client |
- | < | + | < |
void loop() { | void loop() { | ||
- | // listen for BLE peripherals | + | // listen for BLE central device |
BLE.central(); | BLE.central(); | ||
} | } | ||
Line 105: | Line 105: | ||
While we have analysed the client' | While we have analysed the client' | ||
Add the libraries to the platformio.ini. | Add the libraries to the platformio.ini. | ||
- | < | + | < |
lib_deps = | lib_deps = | ||
stm32duino/ | stm32duino/ | ||
Line 111: | Line 111: | ||
</ | </ | ||
And import libraries into the cpp file. | And import libraries into the cpp file. | ||
- | < | + | < |
#include " | #include " | ||
#include " | #include " | ||
Line 117: | Line 117: | ||
</ | </ | ||
Next, we define the UUIDs for remote service and a characteristic. Notice they must match the ones defined in the server. | Next, we define the UUIDs for remote service and a characteristic. Notice they must match the ones defined in the server. | ||
- | < | + | < |
// The remote service we wish to connect to. | // The remote service we wish to connect to. | ||
#define REMOTE_SERVICE_UUID " | #define REMOTE_SERVICE_UUID " | ||
Line 127: | Line 127: | ||
</ | </ | ||
Some global class objects and variables will be needed for our software. | Some global class objects and variables will be needed for our software. | ||
- | < | + | < |
// Variables | // Variables | ||
HCISharedMemTransportClass HCISharedMemTransport; | HCISharedMemTransportClass HCISharedMemTransport; | ||
Line 143: | Line 143: | ||
In the setup() function we initialise LCD and Bluetooth and start scanning for the device having the service UUID we want to connect. | In the setup() function we initialise LCD and Bluetooth and start scanning for the device having the service UUID we want to connect. | ||
- | < | + | < |
void setup() { | void setup() { | ||
// initialise LCD | // initialise LCD | ||
Line 174: | Line 174: | ||
if (peripheral) { | if (peripheral) { | ||
- | if (peripheral.localName() = "SUT STM BLE") { | + | if (peripheral.localName() |
// display remote name | // display remote name | ||
Line 220: | Line 220: | ||
- Disconnects from the remote server. | - Disconnects from the remote server. | ||
- | < | + | < |
void display_characteristic(BLEDevice peripheral) { | void display_characteristic(BLEDevice peripheral) { | ||
| |