arduino / arduino/ArduinoCore-arc32

Jira 916 BLE.connected() always return false.

Open
#507 17 comments 0 reactions 0 assignees View on GitHub
enhancement Under Review
Dominant language
C
Stars
330
Forks
281
PR merge metrics
No merged PRs in 30d

Description

Here is the code. It always return false, even BLE is connected.

corelib Version: 2.0.1-RC2

```
/*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* See the bottom of this file for the license terms.
*/

#include

const int ledPin = 13; // set ledPin to on-board LED
const int buttonPin = 4; // set buttonPin to digital pin 4

BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service

// create switch characteristic and allow remote device to read and write
BLECharCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// create button characteristic and allow remote device to get notifications
BLECharCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // allows remote device to get notifications

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output
pinMode(buttonPin, INPUT); // use button pin 4 as an input

// begin initialization
BLE.begin();

// set the local name peripheral advertises
BLE.setLocalName("BtnLED");
// set the UUID for the service this peripheral advertises:
BLE.setAdvertisedService(ledService);

// add the characteristics to the service
ledService.addCharacteristic(ledCharacteristic);
ledService.addCharacteristic(buttonCharacteristic);

// add the service
BLE.addService(ledService);

ledCharacteristic.setValue(0);
buttonCharacteristic.setValue(0);

// start advertising
BLE.advertise();

Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {

//////////////////////////
static unsigned long BLEWriteTimer = millis();
if (millis() - BLEWriteTimer >= 1000) {
BLEWriteTimer = millis();
Serial.println(BLE.connected());
}
//////////////////////////

// poll for BLE events
BLE.poll();

// read the current button pin state
char buttonValue = digitalRead(buttonPin);

// has the value changed since the last read
boolean buttonChanged = (buttonCharacteristic.value() != buttonValue);

if (buttonChanged) {
// button state changed, update characteristics
ledCharacteristic.setValue(buttonValue);
buttonCharacteristic.setValue(buttonValue);
}

if (ledCharacteristic.written() || buttonChanged) {
// update LED, either central has written to characteristic or button state has changed
if (ledCharacteristic.value()) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
digitalWrite(ledPin, LOW);
}
}
}

/*
Copyright (c) 2016 Intel Corporation. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-
1301 USA
*/

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied CurieBLE sketch and trace the BLE.connected() call alongside BLE.poll() in loop(). Reproduce the report with a BLE central connected and disconnected, then inspect the BLE connection-state implementation; done means connected() reports the actual link state consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.