B4R Question ArduinoBLE lib wrapping EMPTY issue

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

working to wrap the ArduinoBLE library to be used with an Arduino GIGA R1.

Getting this error when compiling a test sketch:
B4X:
Basic\B4R\Objects\src\rCore.h:614:40: error: expected unqualified-id before ';' token 614 | static B4RString* EMPTY; | ^ In file included from C:...

I confirmed the issue is caused by a macro named EMPTY coming from the Arduino GIGA (mbed / Zephyr / CMSIS) core.
Undefining EMPTY in B4RDefines.h is not sufficient, because the macro is reintroduced per translation unit by the Arduino core.

The only robust fix is to undefine EMPTY locally in rCore.h:
B4X:
// --- Fix macro collision with Zephyr / mbed ---
#ifdef EMPTY
  #undef EMPTY
#endif
static B4RString* EMPTY;
This keeps API compatibility and avoids renaming core symbols.

Another option would be to rename EMPTY to EMPTYSTR in rCore.h and rCore.cpp:
B4X:
static B4RString* EMPTYSTR;

static B4RString be_empty;
B4RString* B4RString::EMPTYSTR = be_empty.wrap("");

Is there another solution for this instead modifying the B4R rCore?
 
Another option would be to rename EMPTY to EMPTYSTR in rCore.h and rCore.cpp:
This will not work without updating B4R as the compiler emits code referencing this variable. I will change this variable name in the next update. For now you will need to modify rCore.h.
 
Upvote 0
Hello @rwblinn,
I presume that you're creating another excellent library for the community.

I do have a B4R wrap of the ArduinoBLE library I obviously called it rArduinoBLE, if you would be willing to test it for me. I remember wrapping the Peripheral code, I may or may not have wrapped in the Central code. I wrapped this library when I was updating Erel's original the B4A BLE Peripheral library. I think it's working fully, but I didn't really test it that much as what I needed was for Android production hardware and not Arduino/ESP, so I just left it, well until I saw your post, then I quickly tested this.

ESP32 Peripheral - Android screenshot below:
1000089421.png


Let me know, and I'll PM you the code...
 
Last edited:
Upvote 0
Thanks Peter.
In the meantime have created first version of 2 libraries rArduinoBLECentral & Peripheral.
Tested and working OK.
Happy to test yours.
See my PM.
 
Upvote 0
Hello Everyone,
I'll be releasing my rArduinoBLE for B4R, I wasn't going to do so originally, but after @rwblinn tested it and gave me the go ahead, I will be releasing it after all. this library does both Peripheral and Central devices. I will release 2 examples codes with it, the Peripheral code and the newly renamed Device (now Central) code.

Teaser:
rArduinoBLE


Author: Peter Simpson
Version: 1.00
  • BLEDevice
    Represents a remote BLE device discovered during a scan.
    • Functions:
      • Address As String
        Returns the MAC address of the remote device (e.g., "AA:BB:CC:DD:EE:FF").
      • Connect As Bool
        Attempts to connect to the remote device.
        Returns True if the connection was successful.
      • Connected As Bool
        Checks the connection status. Returns True if currently connected.
      • Disconnect
        Terminates the active connection with the remote device.
      • DiscoverAttributes As Bool
        Queries the remote device for its services and characteristics.
        This must be called and return True before attempting to Read or Write.
      • LocalName As String
        Returns the advertised name of the remote device.
        May return an empty string if the device does not broadcast a name.
      • ReadCharacteristic (ServiceUUID As String, CharUUID As String) As Byte()
        Reads data from a remote characteristic.
        ServiceUUID: The Service UUID.
        CharUUID: The Characteristic UUID.
        Returns an ArrayByte containing the data, or Null if the read failed.
      • RSSI As Int
        Returns the Received Signal Strength Indicator.
        Typically ranges from -100 (weak) to -30 (strong).
      • WriteCharacteristic (ServiceUUID As String, CharUUID As String, Data As Byte())
        Writes data to a characteristic on the remote device.
        ServiceUUID: The 128-bit or 16-bit Service UUID.
        CharUUID: The Characteristic UUID to target.
        Data: The ArrayByte containing the payload.
  • BLEMaster
    The main controller for Bluetooth Low Energy.
    Supports both Peripheral mode (broadcasting services) and Central mode (scanning for remote devices).
    • Fields:
      • Appearance As Int
        Sets the 16-bit appearance value for the device.
        --- SOME OF THESE CODES BELOW, MAY NOT BE RECOGNISED ON YOUR DEVICE. ---.
        Unknown (0x0000), Phone (0x0040), Computer (0x0080), Watch (Generic) (0x00C0), Watch: Sports Watch (0x00C1),
        Clock (0x0100), Display (0x0140), Remote Control (0x0180), Eye-glasses (0x01C0), Tag (0x0200), Keyring (0x0240),
        Media Player (0x0280), Barcode Scanner (0x02C0), Thermometer (Generic) (0x0300), Thermometer: Ear (0x0301),
        Heart Rate Sensor (Generic) (0x0340), Heart Rate Sensor: Belt (0x0341), Blood Pressure (Generic) (0x0380),
        Blood Pressure: Arm (0x0381), Blood Pressure: Wrist (0x0382), Human Interface Device (HID) (0x03C0),
        HID: Keyboard (0x03C1), HID: Mouse (0x03C2), HID: Joystick (0x03C3), HID: Gamepad (0x03C4),
        HID: Digitizer Tablet (0x03C5), HID: Card Reader (0x03C6), HID: Digital Pen (0x03C7), HID: Barcode Scanner (0x03C8).
      • DeviceName As String
        Sets or gets the device name (GATT service name) seen after connection.
      • LocalName As String
        Sets or gets the local name that the device will broadcast.
    • Functions:
      • AddService (Service As B4R::B4RLocalService*)
        Adds a local service to the peripheral.
        Service: The LocalService object which must contain at least one characteristic.
      • Advertise
        Starts broadcasting BLE advertisement packets.
        This makes the device visible to other BLE centrals (like smartphones).
      • Available As B4R::B4RBLEDevice*
        Checks for discovered devices during an active scan.
        Returns a BLEDevice object if a device was found, or Null if no new devices are available.
      • Begin As Bool
        Initialises the BLE radio hardware.
        Returns True if the radio was successfully started.
        Ensure your board supports BLE (e.g., ESP32, Arduino Nano 33 BLE).
      • Poll
        Handles underlying BLE stack events.
        In Peripheral mode, this should be called frequently within a loop to maintain connections.
      • Scan
        Starts scanning for nearby BLE peripheral devices.
        Use the Available method to retrieve discovered devices.
      • SetAdvertisedService (Service As B4R::B4RLocalService*)
        Sets the primary service UUID to be broadcast in the advertisement packet.
        Service: The service that scanning central devices will see before connecting.
      • SetAppearance (Value As Int)
        Alternative method to set the appearance value via a function call.
      • StopScan
        Stops the current scanning operation to save power or prepare for connection.
  • LocalCharacteristic
    Represents a data point hosted on your device that centrals can interact with.
    • Functions:
      • GetValue As Byte()
        Returns the most recent value written to this characteristic by a connected central device.
      • Initialize (UUID As String, Properties As Byte, Size As Int)

        Initialises the characteristic.
        UUID: The unique identifier for this data point.
        Properties: Supported bits.
        1 = Read
        2 = Write
        4 = Write Without Response
        8 = Notify
        16 = Indicate
        Combined Properties: Common examples.
        3 = Read + Write (1 + 2)
        6 = Write + Write Without Response (2 + 4)
        7 = Read + Write + Write Without Response (1 + 2 + 4)
        15 = Read + Write + Write Without Response + Notify (1 + 2 + 4 + 8)
        Size: The maximum data size in bytes for the value buffer.
      • SetValue (Data As Byte())
        Updates the value stored in this characteristic.
        Centrals will see this updated value on their next read or notification.
      • Written As Bool
        Checks if a remote central device has written a new value to this characteristic since this method was last checked.
  • LocalService
    Represents a BLE service hosted by your ESP32/Arduino.
    • Functions:
      • AddCharacteristic (Characteristic As B4R::B4RLocalCharacteristic*)
        Adds a characteristic to this service.
        Call this before adding the service to the BLEMaster.
      • Initialize (UUID As String)
        Initialises the service.
        UUID: The unique identifier for this service (e.g., "180F" for Battery Service).

BLE Library Compatibility Table​

Board / FamilyBLE hardwareArduinoBLE compatibleWorks with this libraryNotes
Arduino Nano 33 BLE✔✔✔Fully supported (nRF52840)
Arduino Nano 33 BLE Sense✔✔✔Fully supported
Arduino Nano 33 BLE Sense Rev2✔✔✔Fully supported
Arduino Edge Control✔✔✔Uses same BLE stack
Arduino Portenta H7 (mbed)✔✔✔Works in mbed mode
Arduino Nicla Sense ME✔✔✔Fully supported
Arduino Nicla Vision✔✔✔Fully supported
Arduino Nicla Voice✔✔✔Fully supported
ESP32 DevKit V1 (DOIT)✔✔✔Yes - Already tested by me
ESP32-WROOM-32✔✔✔Yes - Already tested by me
ESP32-WROVER✔✔✔Yes - Already tested by me
ESP32-S3✔✔✔BLE 5.0 capable
ESP32-C3✔✔✔BLE 5.0 capable
ESP32-C6✔✔✔BLE 5.0 capable
Nano RP2040 Connect✔⚠ Partial⚠ Works but slowerBLE via NINA module
Portenta X8✔⚠ Partial⚠ Works in Arduino modeNot recommended for timing‑critical BLE
ESP32-S2❌❌❌No BLE hardware - Add HM‑10
ESP8266❌❌❌No BLE hardware - Add HM‑10
Arduino Uno / Mega / Leonardo❌❌❌No BLE hardware - Add HM‑10
Arduino Due❌❌❌No BLE hardware - Add HM‑10
Teensy 3.x / 4.x✔❌❌Uses different BLE stack
Adafruit nRF52 boards✔❌❌Use Bluefruit, not ArduinoBLE
STM32 boards✔❌❌Use STM32BLE, not ArduinoBLE


Enjoy...
 
Upvote 0
Back
Top