Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
docs/doxydocs
.development

# Editor/IDE (all directories)
.idea/
.vscode/

# PlatformIO build
.pio/
13 changes: 13 additions & 0 deletions examples/BLE_Beacon_Scanner/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "BLE_Beacon_Scanner.ino"
#endif
13 changes: 13 additions & 0 deletions examples/BLE_EddystoneTLM_Beacon/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "BLE_EddystoneTLM_Beacon.ino"
#endif
13 changes: 13 additions & 0 deletions examples/Bluetooth_5/NimBLE_extended_client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_extended_client.ino"
#endif
13 changes: 13 additions & 0 deletions examples/Bluetooth_5/NimBLE_extended_scan/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_extended_scan.ino"
#endif
13 changes: 13 additions & 0 deletions examples/Bluetooth_5/NimBLE_extended_server/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_extended_server.ino"
#endif
13 changes: 13 additions & 0 deletions examples/Bluetooth_5/NimBLE_multi_advertiser/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_multi_advertiser.ino"
#endif
13 changes: 13 additions & 0 deletions examples/L2CAP/L2CAP_Client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "L2CAP_Client.ino"
#endif
13 changes: 13 additions & 0 deletions examples/L2CAP/L2CAP_Server/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "L2CAP_Server.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Async_Client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Async_Client.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Client.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Scan_Continuous/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Scan_Continuous.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Scan_Whitelist/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Scan_whitelist.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Secure_Client/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Secure_Client.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Secure_Server/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Secure_Server.ino"
#endif
65 changes: 65 additions & 0 deletions examples/NimBLE_Server/NimBLE_Server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <Arduino.h>
#include <NimBLEDevice.h>

#include "NimBLE2905.h"

static NimBLEServer* pServer;

/** None of these are required as they will be handled by the library with defaults. **
Expand Down Expand Up @@ -123,7 +125,9 @@ class DescriptorCallbacks : public NimBLEDescriptorCallbacks {

void setup(void) {
Serial.begin(115200);
delay(500);
Serial.printf("Starting NimBLE Server\n");
delay(500);

/** Initialize NimBLE and set the device name */
NimBLEDevice::init("NimBLE");
Expand Down Expand Up @@ -186,9 +190,70 @@ void setup(void) {
pC01Ddsc->setValue("Send it back!");
pC01Ddsc->setCallbacks(&dscCallbacks);

NimBLEService* pCafeService = pServer->createService("CAFE");

NimBLECharacteristic* pBurgerIngredientsCharacteristic =
pCafeService->createCharacteristic("FEED", NIMBLE_PROPERTY::READ);

NimBLE2904* pFormatName = pBurgerIngredientsCharacteristic->create2904();
pFormatName->setFormat(0x19);
pFormatName->setUnit(0x2700);

NimBLE2904* pFormatFatPercent = pBurgerIngredientsCharacteristic->create2904();
pFormatFatPercent->setFormat(0x04);
pFormatFatPercent->setUnit(0x27AD);

NimBLE2904* pFormatWeight = pBurgerIngredientsCharacteristic->create2904();
pFormatWeight->setFormat(0x06);
pFormatWeight->setUnit(0x276F);

/**
* 2905 “Aggregate Format” descriptor is a special case. When create2905() is called,
* it creates an instance of NimBLE2905 with the correct properties and size.
* We must then explicitly add the constituent 2904 descriptors that define the
* aggregate format (e.g., name, fat percent, weight) using add2904Descriptor().
* This ensures the aggregate descriptor correctly references all its component descriptors.
*/
NimBLE2905* pFormatAggregate = pBurgerIngredientsCharacteristic->create2905();
pFormatAggregate->add2904Descriptor(pFormatName);
pFormatAggregate->add2904Descriptor(pFormatFatPercent);
pFormatAggregate->add2904Descriptor(pFormatWeight);


const char* name = "Ground Beef Patty";
const size_t nameLength = strlen(name);
uint8_t fatPercentage = 20;
uint16_t weightGrams = 227;
uint8_t rawValue[nameLength + 1 + sizeof(fatPercentage) + sizeof(weightGrams)];

size_t offset = 0;
// Copy name
memcpy(rawValue + offset, name, nameLength);
offset += nameLength;

// Null terminator
rawValue[offset++] = 0;

// Fat percentage (1 byte)
memcpy(rawValue + offset, &fatPercentage, sizeof(fatPercentage));
offset += sizeof(fatPercentage);
// Weight (2 bytes)
memcpy(rawValue + offset, &weightGrams, sizeof(weightGrams));
offset += sizeof(weightGrams);
pBurgerIngredientsCharacteristic->setValue(rawValue, offset);

const char* description = "UTF-8 Name (null-terminated) + uint8 Fat % + uint16 Weight (grams)";
NimBLEDescriptor* pUserDesc = pBurgerIngredientsCharacteristic->createDescriptor(
BLEUUID((uint16_t)0x2901),
NIMBLE_PROPERTY::READ,
strlen(description)
);
pUserDesc->setValue(description);

/** Start the services when finished creating all Characteristics and Descriptors */
pDeadService->start();
pBaadService->start();
pCafeService->start();

/** Create an advertising instance and add the services to the advertised data */
NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
Expand Down
13 changes: 13 additions & 0 deletions examples/NimBLE_Server/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Server.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_Server_Whitelist/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_Server_Whitelist.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_active_passive_scan/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_active_passive_scan.ino"
#endif
13 changes: 13 additions & 0 deletions examples/NimBLE_iBeacon/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* main.cpp
*
* Purpose: This file exists ONLY to satisfy PlatformIO's build system.
* The NimBLE Server example normally compiles fine in the Arduino IDE
* without needing a separate main.cpp. PlatformIO requires a main entry
* (setup() and loop()) for any build environment, so this file exists
* purely to make PIO happy.
*/

#ifdef PLATFORMIO_BUILD
#include "NimBLE_iBeacon.ino"
#endif
Loading