Open avilmaru opened 4 years ago
Hi @avilmaru ,
I have tried your same scenario with the two sketches below. Everything seems to be working, so you must have a problem in your sketch. Could you try again taking these sketches as references?
Thanks
Central Sketch:
#include "ArduinoBLE.h"
// Value to write into peripheral gesture characteristic
uint8_t gesture = 66;
void setup()
{
Serial.begin(115200);
BLE.begin();
BLE.debug(Serial);
BLE.scanForName("peripheral");
}
void loop()
{
static unsigned long refTime = millis();
BLEDevice peripheral = BLE.available();
if (peripheral) {
BLE.stopScan();
if (peripheral.connect()) {
peripheral.discoverAttributes();
BLECharacteristic gestureCharacteristic = peripheral.characteristic("2A56");
while (peripheral.connected()) {
if (millis() > refTime + 5000) {
refTime = millis();
if (gestureCharacteristic) {
// Update value to write into peripheral characteristic
gesture += 10;
auto ret = gestureCharacteristic.writeValue(gesture);
if (ret) {
Serial.print("gesture written: ");
Serial.println(gesture);
} else {
Serial.println("write failed");
}
}
}
}
}
BLE.scanForName("peripheral");
}
}
Peripheral Sketch:
#include "ArduinoBLE.h"
BLEService gestureService("180A");
BLEUnsignedCharCharacteristic gestureCharacteristic("2A56", BLERead | BLEWrite);
uint8_t gesture = 66;
void setup()
{
Serial.begin(115200);
BLE.begin();
BLE.debug(Serial);
BLE.setLocalName("peripheral");
BLE.setAdvertisedService(gestureService);
gestureService.addCharacteristic(gestureCharacteristic);
BLE.addService(gestureService);
gestureCharacteristic.writeValue(gesture);
BLE.advertise();
}
void loop()
{
static unsigned long refTime = millis();
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
digitalWrite(LED_BUILTIN, HIGH);
while (central.connected()) {
if (gestureCharacteristic.written()) {
auto val = gestureCharacteristic.value();
Serial.print("command value: ");
Serial.println(val);
}
}
}
}
Central Device: Arduino 33 BLE Sense Peripheral device: Arduino MKR WiFi 1010.
Upgrading from version 1.1.0 to version 1.1.2 the peripheral device does not receive values written by the central device. Before everything worked correctly.
Central device code
Peripheral device code
--> Both devices are connected correctly --> in version 1.1.0 it works correctly!!!