Bonsoir,
il m'arrive d’utiliser la géniale application FizziQ (https://www.fizziq.org) pour faire des manips de physique (d'où le nom) avec les smartphones (et les capteurs intégrés) de mes élèves. Une de ses fonctionnalités est d’accepter de communiquer via BLE avec des capteurs externes reliés à des arduino, ESP32 ou même micro:bit
J'ai pour un premier test utilisé la doc ici :
et notamment le code minimaliste fourni
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>
// Define the UUIDs for service and characteristic
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_RX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
// Declare the characteristic globally
BLECharacteristic *pCharacteristic;
void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("FizziQ"); // Set your BLE device name
// Create the BLE Server
BLEServer *pServer = BLEDevice::createServer();
// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY
);
pCharacteristic->addDescriptor(new BLE2902());
// BLECharacteristic * pRxCharacteristic = pService->createCharacteristic(
// CHARACTERISTIC_UUID_TX,
// BLECharacteristic::PROPERTY_WRITE
// );
// Start the service
pService->start();
// Start advertising
pServer->getAdvertising()->start();
Serial.println("Waiting for a client connection...");
}
void loop() {
// Send the temperature value every 5 seconds
pCharacteristic->setValue("temperature : 20");
pCharacteristic->notify(); // Send notification if connected
delay(2000);
pCharacteristic->setValue("temperature : 21");
pCharacteristic->notify(); // Send notification if connected
delay(2000);
}
Évidement dans le loop()
on a provisoirement une pseudo lecture de capteur mais là n’est pas le problème.
La compilation ne passe pas :
/home/christian/Arduino/BLE_test/BLE_test.ino:12:1: error: 'BLECharacteristic' does not name a type; did you mean 'Character_h'?
BLECharacteristic *pCharacteristic;
^~~~~~~~~~~~~~~~~
Character_h
/home/christian/Arduino/BLE_test/BLE_test.ino: In function 'void setup()':
/home/christian/Arduino/BLE_test/BLE_test.ino:18:3: error: 'BLEDevice' has not been declared
BLEDevice::init("FizziQ"); // Set your BLE device name
^~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:21:3: error: 'BLEServer' was not declared in this scope
BLEServer *pServer = BLEDevice::createServer();
^~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:21:3: note: suggested alternative: 'Server'
BLEServer *pServer = BLEDevice::createServer();
^~~~~~~~~
Server
/home/christian/Arduino/BLE_test/BLE_test.ino:21:14: error: 'pServer' was not declared in this scope
BLEServer *pServer = BLEDevice::createServer();
^~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:21:14: note: suggested alternative: 'Server'
BLEServer *pServer = BLEDevice::createServer();
^~~~~~~
Server
/home/christian/Arduino/BLE_test/BLE_test.ino:21:24: error: 'BLEDevice' has not been declared
BLEServer *pServer = BLEDevice::createServer();
^~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:24:3: error: 'BLEService' was not declared in this scope
BLEService *pService = pServer->createService(SERVICE_UUID);
^~~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:24:15: error: 'pService' was not declared in this scope
BLEService *pService = pServer->createService(SERVICE_UUID);
^~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:24:15: note: suggested alternative: 'Serial'
BLEService *pService = pServer->createService(SERVICE_UUID);
^~~~~~~~
Serial
/home/christian/Arduino/BLE_test/BLE_test.ino:27:3: error: 'pCharacteristic' was not declared in this scope
pCharacteristic = pService->createCharacteristic(
^~~~~~~~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:27:3: note: suggested alternative: 'Character_h'
pCharacteristic = pService->createCharacteristic(
^~~~~~~~~~~~~~~
Character_h
/home/christian/Arduino/BLE_test/BLE_test.ino:29:21: error: 'BLECharacteristic' has not been declared
BLECharacteristic::PROPERTY_WRITE |
^~~~~~~~~~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:30:22: error: 'BLECharacteristic' has not been declared
BLECharacteristic::PROPERTY_NOTIFY
^~~~~~~~~~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:33:38: error: expected type-specifier before 'BLE2902'
pCharacteristic->addDescriptor(new BLE2902());
^~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino: In function 'void loop()':
/home/christian/Arduino/BLE_test/BLE_test.ino:50:3: error: 'pCharacteristic' was not declared in this scope
pCharacteristic->setValue("temperature : 20");
^~~~~~~~~~~~~~~
/home/christian/Arduino/BLE_test/BLE_test.ino:50:3: note: suggested alternative: 'Character_h'
pCharacteristic->setValue("temperature : 20");
^~~~~~~~~~~~~~~
Character_h
Utilisation de la bibliothèque ESP32 BLE Arduino version 2.0.0 dans le dossier: /home/christian/.arduino15/packages/esp32/hardware/esp32/2.0.14/libraries/BLE
exit status 1
Compilation error: 'BLECharacteristic' does not name a type; did you mean 'Character_h'?
Je ne comprends pas du tout les erreurs de compilation, je suppose (peut-être à tort) que c'est la première qui est la source du reste mais c'est totalement mystérieux pour moi...
Est-ce que qq'un pourrait m'aider ?