ArduinoBLE library for Arduino

Related tags

Arduino ArduinoBLE
Overview

ArduinoBLE

Compile Examples Status Spell Check Status

Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE.

This library supports creating a BLE peripheral and BLE central mode.

For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running Arduino NINA-W102 firmware v1.2.0 or later.

For more information about this library please visit us at: https://www.arduino.cc/en/Reference/ArduinoBLE

License

Copyright (c) 2019 Arduino SA. 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
Issues
  • Encryption at connection level?

    Encryption at connection level?

    I know ble works by broadcasting and that methods like ccm are available.

    In cryptography, a cipher block chaining message authentication code (CBC-MAC) is a technique for constructing a message authentication code from a block cipher. The message is encrypted with some block cipher algorithm in CBC mode to create a chain of blocks such that each block depends on the proper encryption of the previous block. This interdependence ensures that a change to any of the plaintext bits will cause the final encrypted block to change in a way that cannot be predicted or counteracted without knowing the key to the block cipher.

    The trouble with that is that anyone could publish a message and it would mess up the next block process of decryption, effectively rendering the encryption and communication useless and still be legal as defined by fcc part 15.

    Doesn’t this practically make ble useless as a protocol if there is no connection state tracking and layered encryption?

    type: enhancement conclusion: resolved topic: code 
    opened by andrewhodel 56
  • BLE Pairing and Encryption

    BLE Pairing and Encryption

    This pull request is for an implementation of the BLE Security Manager which allows arduino devices to pair & encrypt connections using the HCI specification. Specifically, it implements Secure Connect / Numeric comparison.

    The branch appears stable but I'm aware it may need some refactoring. An example sketch is included to show how to pair devices.

    The branch supports encryption instigated by the central when the arduino is the peripheral.

    type: enhancement topic: code 
    opened by unknownconstant 25
  • cordio: lower power polling with timeout

    cordio: lower power polling with timeout

    I've been testing this with the Examples -> Peripheral -> LEDCallback example, with two changes:

    1. Removing: while (!Serial); from setup()
    2. Changing BLE.poll(); in loop() to BLE.poll(60000);

    Unfortunately, in my brief testing it doesn't seem to be lower power (using a USB supply input).

    @facchinm any thoughts on this?

    opened by sandeepmistry 19
  • BLE nano 33 does not report or disconnect from centra

    BLE nano 33 does not report or disconnect from centra

    When using for example the button peripheral and central examples in the arduinoBLE library If for example the central is a MKR1010 powered by usb and the peripheral is a nanoBLE 33 then if I remove the power from the central the peripheral still reports it as connected.

    If instead of a Nano BLE 33 I use a Nano IOT33 then when the central is de powered the peripheral reports it as being disconnected.

    there are several issues regarding disconnection & this library when using the Nana BLe 33.

    Arduino support said the following

    ================================================================

    Hello Russell,

    Thank you for reporting us this issue,

    We request you to open an issue on Github here and our developers will provide you further guidance.

    Have a nice day!

    Best Regards, Sravya Amirisetti

    type: imperfection 
    opened by Russell108 17
  • What is the correct approach to transmit rapidly changing real-time data?

    What is the correct approach to transmit rapidly changing real-time data?

    I have modified the BatteryMonitor example to send the accelerometer data instead - by removing the map function and the 200ms timer. It seems to work. And when I write the float values of accelerometer values to the characteristic using writeValue(x); I don't get any errors HOWEVER the value received on the other side i.e a central device like my App or WebBluetooth is always integer and positive. Any idea why that is happening?

    More importantly is this the correct way to send float values?

    I am also thinking if modifying the BatteryMonitor example is the correct approach to transmit rapidly changing real-time data. If it isn't then could you please guide me/point me to some resources so that I can contribute an example for the official library?

    opened by armsp 16
  • add esp32 support

    add esp32 support

    Added support for the esp32 chip using the virtual HCI. This has been tested on real hardware with "Arduino core for the ESP32" version 2.0.0.

    type: enhancement topic: code 
    opened by dominsch 15
  • begin() doesn't work after end() on Nano BLE 33, have to power cycle

    begin() doesn't work after end() on Nano BLE 33, have to power cycle

    Hi,

    The begin() function does not behave as expected following an end() and instead I have to power cycle. This is similar to #33

    I've created two minimal examples for people to try below:

    Example 1:

    1. Initialise BLE
    2. Call BLE.disconnect() 10 seconds after connected to central
    3. Re-advertise 15 seconds later to allow reconnection

    Expected behaviour - disconnect from central and allow reconnection after re-advertising Actual behaviour - works as expected

    #include <ArduinoBLE.h>
    
    BLEService TestService("DEAD");
    BLECharacteristic TestData("BEEF", BLEIndicate | BLENotify, 2, true);
    BLEDescriptor TestDescriptor("BEEF", "Test");
    
    uint32_t genericTimer = 0;
    bool wasConnected = false;
    
    void setup(){
        initBLE();
    }
    
    void loop(){
        BLEDevice central = BLE.central(); // begin listening for centrals to connect
    
        if(central){
            genericTimer = millis();
            while(central.connected()){
                if(millis() - genericTimer >= 10000){ // Wait 10 seconds after connect
                    BLE.disconnect(); // Disconnect BLE
                    wasConnected = true;
                }
            }
        }
    
        if(wasConnected){
            genericTimer = millis();
            while(millis() - genericTimer <= 15000){} // Wait 15 seconds after disconnect
            wasConnected = false;
            BLE.advertise();
        }
    }
    
    void initBLE(void){
        BLE.begin();
        BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
        BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
        BLE.setLocalName("TestName");
        BLE.setDeviceName("Test Device Name");
        TestService.addCharacteristic(TestData);
        TestData.addDescriptor(TestDescriptor);
        BLE.addService(TestService);
        BLE.setAdvertisedService(TestService);
        BLE.advertise();
    }
    

    Example 2:

    1. Initialise BLE
    2. Disconnect and end() after 10 seconds of connection to central
    3. Wait 15 seconds and try to re-start BLE system again

    Expected behaviour - system disconnects, then ends BLE service, and restarts it correctly Actual behaviour - unable to restart BLE with begin() after calling end()

    #include <ArduinoBLE.h>
    
    BLEService TestService("DEAD");
    BLECharacteristic TestData("BEEF", BLEIndicate | BLENotify, 2, true);
    BLEDescriptor TestDescriptor("BEEF", "Test");
    
    uint32_t genericTimer = 0;
    bool wasConnected = false;
    
    void setup(){
        initBLE();
    }
    
    void loop(){
        BLEDevice central = BLE.central(); // begin listening for centrals to connect
    
        if(central){
            genericTimer = millis();
            while(central.connected()){
                if(millis() - genericTimer >= 10000){ // Wait 10 seconds after connect
                    BLE.disconnect(); // Disconnect BLE
                    BLE.end(); // End BLE service
                    wasConnected = true;
                }
            }
        }
    
        if(wasConnected){
            genericTimer = millis();
            while(millis() - genericTimer <= 15000){} // Wait 15 seconds after disconnect
            wasConnected = false;
            initBLE();
        }
    }
    
    void initBLE(void){
        BLE.begin();
        BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
        BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
        BLE.setLocalName("TestName");
        BLE.setDeviceName("Test Device Name");
        TestService.addCharacteristic(TestData);
        TestData.addDescriptor(TestDescriptor);
        BLE.addService(TestService);
        BLE.setAdvertisedService(TestService);
        BLE.advertise();
    }
    
    type: imperfection conclusion: resolved topic: code 
    opened by rmlearney-digicatapult 14
  • Communication of One  Central Device and More than One  Peripheral Device

    Communication of One Central Device and More than One Peripheral Device

    Does the library support connection and communication between one central device and more than one peripheral device? And how could it be implemented?

    status: waiting for information 
    opened by vyohai 13
  • ArduinoBLE crashes when BLE.begin BLE.end is called multiple times (possible solution included)

    ArduinoBLE crashes when BLE.begin BLE.end is called multiple times (possible solution included)

    The issue was reported by a user in the Arduino forum, who wants to switch between BLE and WiFi on a regular basis.

    https://forum.arduino.cc/t/repeated-ble-begin-end-crashes-board/885009

    I wrote the following sketch for testing and it crashes after 50 loops.

    #include <ArduinoBLE.h>
    
    void setup()
    {
      Serial.begin( 9600 );
      while ( !Serial );
      Serial.println( "ArduinoBLE memory leak test" );
    }
    
    void loop()
    {
      static uint32_t counter = 0;
    
      BLE.begin();
      counter++;
      Serial.print( "C: " );
      Serial.println( counter );
      BLE.end();
    }
    
    

    With my limited C++ knowledge I found in void GATTClass::begin() a couple of objects are created with new. They are not deleted in void GATTClass::end().

    Adding the 5 deletes to GATTClass::end seems to fix the issue. Can you confirm this is the right way to fix this and implement this in the next version of the library?

    void GATTClass::end()
    {
      delete( _genericAccessService );
      delete( _deviceNameCharacteristic );
      delete( _appearanceCharacteristic );
      delete( _genericAttributeService );
      delete( _servicesChangedCharacteristic );
     _attributes.clear();
    }
    
    type: imperfection conclusion: resolved topic: code 
    opened by Klaus-KK 12
  • Nano 33 BLE in bootmode after disconnect

    Nano 33 BLE in bootmode after disconnect

    Hi, I have successfully paired an AcgamR1 clone remote control with the nano 33 ble. But after 45 seconds the remote control disconnects. Probably to save energy. Now the nano hangs up and does nothing more. No serial monitor and the Builtin LED is blinking 5 quick, 3 slow, 5 quick, 3 slow... I think the nano is in bootmode. (https://forum.arduino.cc/index.php?topic=630834.0)

    Code is from here: https://github.com/bitbank2/Nano_33_Gamepad

    Does anyone have a solution for this?

    Software: Arduino IDE 1.8.13 <ArduinoBLE.h> 1.2.0 Arduino mbed -enabled Boards V2.0.0 and same issue with 1.3.2 Hardware: Nano 33 BLE Original not a clone BLE Remote: https://www.amazon.de/magicsee-R1-Bluetooth-Wireless-Controller-Joystick/dp/B01MDM48W9

    type: imperfection status: waiting for information 
    opened by cansimkp 11
  • nano33ble boards seem to ignore scan() without duplicates

    nano33ble boards seem to ignore scan() without duplicates

    I'm porting a code already working on a Arduino MKR WiFi 1010 board to a new Arduino Nano 33 BLE board and noticed BLE.scan() seem to be working 'withDuplicates' and it goes crazy returning multiple times the same devices. The I went to the samples/Central/Scan/Scan.ino and the sample code as is is also ignoring the default no duplites option. I've also tried BLE.scan(false) w/o success. I'm using board mbed 1.3.0 (tried 1.1.6 too) and ArduinoBLE 1.1.3. BTW I've tried two different Nano33ble boards with the same issues. Any idea on what may be wrong here? Many thanks!

    status: waiting for information 
    opened by iactiva 10
  • Very high power consumption on Nano 33 IoT

    Very high power consumption on Nano 33 IoT

    Using a blank sketch with just the following on my Nano 33 IoT:

    void setup() {
      BLE.begin();
    }
    void loop() {
      // no-op
    }
    

    Is drawing 90mA. Without BLE.begin() it's 21mA, so the NINA chip requires 69mA to just be active (no scanning or advertising, although there wasn't a significant change in power consumption doing either). That means using ArduinoBLE will give the following life expectancies:

    • Large cr2032 coin battery: 2 hours
    • Standard 4.8v battery pack: 22 hours
    • Battery of flagship Samsung s22: 1.7 days
    • Battery of 2021 16-in Macbook pro: 4 days

    With this in mind, many users of this library are seeking a way to just power down the NINA module for a set period of time without changing anything about the currently configured GATT.

    1. I have tried calling BLE.end(), however this resets the GATT and the program crashes when trying to add the services back with BLE.addService(myService) after a subsequent BLE.begin(). The event handlers fail to register with BLE.setEventHandler(BLEConnected, onBLEConnected) as well
    2. I have tried calling digitalWrite(NINA_RESETN, LOW) and HIGH directly and this actually works nearly perfect, except the scan is unable to find anything after turning the module back on. But it can advertise and call event handlers without problems, and the GATT is populated how it was before shutting down.

    I'm having a hard time finding a work around, since the ArduinoLowPower sleep function only shaves off 13mA. Do you have any insight how to turn on/off the module without breaking things?

    type: imperfection 
    opened by baconcheese113 1
  • ATT_OP_FIND_INFO_RESP incorrect processing during ATTClass::discoverDescriptors causes crashing

    ATT_OP_FIND_INFO_RESP incorrect processing during ATTClass::discoverDescriptors causes crashing

    Symptoms:

    Connecting as Central to 'other' BLE device which responds with ATT_OP_FIND_INFO_RESP using 128-bit UUIDs causes crash!

    Location of Issue:

    FILE = ArduinoBLE\src\utility\ATT.cpp FUNC = bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* device) LINE = 1728-1730 (ish)

    Explanation:

    responseBuf[1] of ATT_OP_FIND_INFO_RESP is the format of the response as follows: 0x01 = 2 octets of handle, 2 octets of UUID [total 4 octets/bytes] 0x02 = 2 octets of handle, 16 octets of UUID [total 18 octets/bytes]

    Current:

    uint16_t lengthPerDescriptor = responseBuffer[1] * 4;
    uint8_t uuidLen = 2;
    

    Possible Fix:

    uint16_t lengthPerDescriptor = responseBuffer[1] * 14 - 10;
    uint8_t uuidLen = lengthPerDescriptor - 2;
    

    THANKS GUYS!!!!

    type: imperfection 
    opened by carterd 0
  • Compiler error `no return statement in function returning non-void`

    Compiler error `no return statement in function returning non-void`

    I want to use this library in my PlatformIO/Arduino project unsing an Arduino Nano RP2040 Connect. Unfortunately, I get this compiler error because there are no return statements in these four functions:

    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp: In member function 'virtual int HCIClass::saveNewAddress(uint8_t, uint8_t*, uint8_t*, uint8_t*)':
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp:469:1: error: no return statement in function returning non-void [-Werror=return-type]
      469 | }
          | ^
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp: In member function 'virtual int HCIClass::leAddResolvingAddress(uint8_t, uint8_t*, uint8_t*, uint8_t*)':
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp:496:1: error: no return statement in function returning non-void [-Werror=return-type]
      496 | }
          | ^
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp: In member function 'virtual int HCIClass::writeLK(uint8_t*, uint8_t*)':
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp:540:1: error: no return statement in function returning non-void [-Werror=return-type]
      540 | }
          | ^
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp: In member function 'virtual int HCIClass::readStoredLKs()':
    .pio/libdeps/rp2040dev-unix-release/ArduinoBLE/src/utility/HCI.cpp:544:1: error: no return statement in function returning non-void [-Werror=return-type]
      544 | }
          | ^
    

    Am I missing something here or how is this supposed to compile?

    type: imperfection topic: code 
    opened by ln-12 0
  • BLE.begin() -> BLE.end() -> BLE.begin() [again]

    BLE.begin() -> BLE.end() -> BLE.begin() [again]

    Hi guys,

    I am wondering if it is possible to turn off BLE when I do not need to send some data, and turn it on again when data is ready to be sent? I am trying to enable that part, but every time when BLE.end() function is called seems that I am not able to start the BLE again after some sleep time. In my case, I want to send the simple message from Arduino to my PC, and it works when BLE is constantly ON, but I want to turn it off in order to keep my device in a sleep state, and in that case, decrease the current consumption. Is this implementation possible with the Arduino BLE library?

    P.S. In my case, the BLE service, characteristics, advertising,... are defined in the setup function. Thanks in advance. Cheers! :)

    type: imperfection topic: code 
    opened by ASabovic 26
  • Pairing Started and Disconnected in Arduino Nano BLE Sense, But Why???

    Pairing Started and Disconnected in Arduino Nano BLE Sense, But Why???

    Recently Arduino team also added this Lib in their Page as V 1.3.1 and 1.3.0 . I uploaded the Encrypted Battery Monitor Example in my Arduino Nano 33 BLE Sense nrf52840. First, the Numeric Comparison was done and 6 Digit Pin is passed to the mobile phone. By clicking Pair Button, it got disconnected. I also Checked the Scripts, am i missing something?? . Kindly someone help me here. Does Arduino BLE Sense Supports Pairing Process???

    Also Adafruit BLE lib (BlueFruit52) also Contains Pairing Examples. https://github.com/adafruit/Adafruit_nRF52_Arduino/tree/master/libraries/Bluefruit52Lib/examples/Peripheral/pairing_passkey

    But Why Arduino is lagging to give a pairing Example but Adafruit already gave Pairing Examples in their Lib.

    type: imperfection 
    opened by laviator98 8
  • BLEFieldCompleteAdvertisedService128 / BLEFieldIncompleteAdvertisedService128

    BLEFieldCompleteAdvertisedService128 / BLEFieldIncompleteAdvertisedService128

    Hello,

    On this line:

    https://github.com/arduino-libraries/ArduinoBLE/blob/4c149a206c3e36c909cbb6a9c6032940fc806a88/src/BLEAdvertisingData.cpp#L286

    Why is it BLEFieldIncompleteAdvertisedService128 and not BLEFieldCompleteAdvertisedService128 ?

    Thanks,

    Nicolas

    topic: code 
    opened by 3sigma 0
Releases(1.3.1)
Owner
Arduino Libraries
This org contains the official Arduino Libraries. See @arduino for the tools (IDE, Pro IDE, CLI...)
Arduino Libraries
Arduino library for making an IHC in or output module using an Arduino

Introduction This is an Arduino library for making an IHC in or output module using an Arduino. (IHC controller is a home automation controller made b

Jens Østergaard Nielsen 2 Mar 26, 2020
ArduinoIoTCloud library is the central element of the firmware enabling certain Arduino boards to connect to the Arduino IoT Cloud

ArduinoIoTCloud What? The ArduinoIoTCloud library is the central element of the firmware enabling certain Arduino boards to connect to the Arduino IoT

Arduino Libraries 60 Jul 20, 2022
The Approximate Library is a WiFi Arduino library for building proximate interactions between your Internet of Things and the ESP8266 or ESP32

The Approximate Library The Approximate library is a WiFi Arduino Library for building proximate interactions between your Internet of Things and the

David Chatting 101 Jul 29, 2022
Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames.

107-Arduino-MCP2515 Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames. This library is prepared to interface easily

107-Systems 46 Aug 3, 2022
Arduino library for interfacing with any GPS, GLONASS, Galileo or GNSS module and interpreting its NMEA messages.

107-Arduino-NMEA-Parser Arduino library for interfacing with any GPS, GLONASS, Galileo or GNSS module and interpreting its NMEA messages. This library

107-Systems 12 May 16, 2022
Arduino library for providing a convenient C++ interface for accessing UAVCAN.

107-Arduino-UAVCAN Arduino library for providing a convenient C++ interface for accessing UAVCAN (v1.0-beta) utilizing libcanard. This library works f

107-Systems 49 Jul 24, 2022
Arduino web server library.

aWOT Arduino web server library. Documentation 1. Getting started Hello World Basic routing Application generator Serving static files 2. Guide Routin

Lasse Lukkari 235 Jul 21, 2022
Arduino, esp32 and esp8266 library for ABB (ex PowerOne) Aurora Inverter, implement a full methods to retrieve data from the Inverter via RS-485

ABB Aurora protocol You can refer the complete documentation on my site ABB Aurora PV inverter library for Arduino, esp8266 and esp32 I create this li

Renzo Mischianti 20 May 30, 2022
Arduino library for the MCP2515 CAN Controller

MCP2515 CAN Controller Library for Arduino Compatibility with the ACAN library This library is fully compatible with the Teensy 3.x ACAN library https

Pierre Molinaro 3 Oct 1, 2021
CAN / CANFD Arduino Library for Teensy 4.0

CAN Library for Teensy 4.0 / 4.1 It handles Controller Area Network (CAN) for CAN1, CAN2 and CAN3, and Controller Area Network with Flexible Data (CAN

Pierre Molinaro 9 Jul 6, 2022
Analog Devices Analog Digital Converter AD7173 Arduino library

AD7173-Arduino Analog Devices AD7173 analog digital converter Arduino library Mostly tested setup for this library: 1007 data rate external crystal co

brain-duino 8 Jan 13, 2022
Arduino library for nRF51822-based Adafruit Bluefruit LE modules

This library is for all nRF51 based Adafruit Bluefruit LE modules that use SPI or UART. Current nRF51 based Bluefruit LE products include: Bluefruit L

Adafruit Industries 181 Jun 15, 2022
Arduino library for the Adafruit FONA

Adafruit FONA Library This library requires Arduino v1.0.6 or higher This is a library for the Adafruit FONA Cellular GSM Breakouts etc Designed speci

Adafruit Industries 199 Jul 1, 2022
Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.

Adafruit IO Arduino Library This library provides a simple device independent interface for interacting with Adafruit IO using Arduino. It allows you

Adafruit Industries 162 Jul 21, 2022
Arduino library for MQTT support

Adafruit MQTT Library Arduino library for MQTT support, including access to Adafruit IO. Works with the Adafruit FONA, Arduino Yun, ESP8266 Arduino pl

Adafruit Industries 505 Jul 21, 2022
Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip

Adafruit-PN532 This is a library for the Adafruit PN532 NFC/RFID breakout boards This library works with the Adafruit NFC breakout https://www.adafrui

Adafruit Industries 343 Jul 25, 2022
Arduino library for the Si4714 FM+RDS Transmitter in the Adafruit shop

Adafruit-Si4713-Library This is the Adafruit FM Transmitter with RDS/RBDS Breakout - Si4713 library Tested and works great with the Adafruit Si4713 Br

Adafruit Industries 19 May 25, 2022
An Arduino library with additions to vanilla Serial.print(). Chainable methods and verbosity levels. Suitable for debug messages.

advancedSerial This library provides some additions to vanilla Serial.print(): 1. Chainable print() and println() methods: // you can chain print() a

Vasily Klenov 15 Dec 8, 2021
Arduino library for AIS 4G Board

AIS 4G Board Library for Arduino AIS 4G Board คือบอร์ดพัฒนาที่สามารถเชื่อมต่ออินเตอร์เน็ตผ่าน 4G มาพร้อมกับไมโครคอนโทรลเลอร์ ESP32-WROOM-32 และโมดูลสื

null 9 May 27, 2022