Seeed Studio XIAO nRF52840 (Sense)的low power,deep sleep,及ble的省電模式及強度功能 如何使用 ✌ How to use the low power consumption, deep sleep, and ble power saving mode and intensity functions of Seeed Studio XIAO nRF52840 (Sense)

  1. XIAO nRF52840 (Sense) 在arduino ide的 low power 及deep sleep都無法使用,請問是否可提供可使用的api 或範例

  2. 在原生的arduinoble.h 中,沒有提供ble 休眠的功能,是否有其它api可以使用?

3 請問 XIAO nRF52840 (Sense)的預設藍牙強度是多少 ? 是否有api 可以調整藍牙強度 ?

謝謝 !

Hi there,
" 1. XIAO nRF52840 (Sense) cannot be used in low power and deep sleep of Arduino IDE. Can you provide usable API or examples?
2. In the native arduinoble.h, the ble sleep function is not provided. Is there any other API that can be used?
3 What is the default Bluetooth strength of XIAO nRF52840 (Sense)? Is there an API to adjust the Bluetooth strength?
Thank you ! "

1: YES
2: Not supported , but radio can be on during light sleep?
3: YES , BLE transmit power can be defined.
" The ESP32 Bluetooth has 8 transmit power levels, corresponding to -12 ~ 9 dBm of transmit power, with a 3 dBm interval. The controller software limits the transmit power and selects the power level according to the corresponding power level declared by the product."

HTH
GL :slight_smile: PJ
:v:

" The ESP32 Bluetooth has 8 transmit power levels, corresponding to -12 ~ 9 dBm of transmit power, with a 3 dBm interval. The controller software limits the transmit power and selects the power level according to the corresponding power level declared by the product."

我該如何設定藍牙強度 ? 我主要都是使用arduino ide,有lib 可以include 嗎 ?
謝謝

“How should I set the Bluetooth strength? I mainly use Arduino IDE, is there a lib that can be included?
Thank you”

不客气,我会使用其中一个示例,对于小ESP32C6来说:就像这样
只需确保您没有“ArduinoBLE”库加载,它会干扰 ESP32 BLE 库。
您可以使用 NRF connect for Desktop 检查功率输出,也可以使用加密狗和wireshark。
华泰
GL :slight_smile: PJ

Bù kèqì, wǒ huì shǐyòng qízhōng yīgè shìlì, duìyú xiǎo ESP32C6 lái shuō: Jiù xiàng zhèyàng
zhǐ xū quèbǎo nínméiyǒu“ArduinoBLE” kù jiāzài, tā huì gānrǎo ESP32 BLE kù.
Nín kěyǐ shǐyòng NRF connect for Desktop jiǎnchá gōnglǜ shūchū, yě kěyǐ shǐyòng jiāmì gǒu hé wireshark.
Huátài
GL:-) PJ

You are welcome, I would use the one of the examples , Say for the Xiao ESP32C6 : like this
Just make sure You DO not have “ArduinoBLE” Library loaded, it interferes with the ESP32 BLE lib.
You can use NRF connect for Desktop to check power output , also a dongle and wireshark can be used as well.
This line specifically;
//BLEDevice::setPower(ESP_PWR_LVL_P9); // latest info on Power boost.
这条线具体; //BLEDevice::setPower(ESP_PWR_LVL_P9); // 有关功率提升的最新信息。 :slight_smile:

Zhè tiáo xiàn jùtǐ; //BLEDevice::SetPower(ESP_PWR_LVL_P9); // yǒuguān gōnglǜ tíshēng de zuìxīn xìnxī. :slight_smile:

HTH
GL :slight_smile: PJ

/**
 * A BLE client example that is rich in capabilities.
 * There is a lot new capabilities implemented.
 * author unknown
 * updated by chegewara
 * added Power BOOOST by PJG
 * // BLEDevice::setPower(ESP_PWR_LVL_P9); // latest info on Power boost.// end of setup
 * https://github.com/nkolban/esp32-snippets/issues/197
 */

#include "BLEDevice.h"
//#include "BLEScan.h"

// The remote service we wish to connect to.
static BLEUUID serviceUUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
// The characteristic of the remote service we are interested in.
static BLEUUID charUUID("beb5483e-36e1-4688-b7f5-ea07361b26a8");

static boolean doConnect = false;
static boolean connected = false;
static boolean doScan = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
static BLEAdvertisedDevice* myDevice;

static void notifyCallback(
  BLERemoteCharacteristic* pBLERemoteCharacteristic,
  uint8_t* pData,
  size_t length,
  bool isNotify) {
    Serial.print("Notify callback for characteristic ");
    Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str());
    Serial.print(" of data length ");
    Serial.println(length);
    Serial.print("data: ");
    Serial.write(pData, length);
    Serial.println();
}

class MyClientCallback : public BLEClientCallbacks {
  void onConnect(BLEClient* pclient) {
  }

  void onDisconnect(BLEClient* pclient) {
    connected = false;
    Serial.println("onDisconnect");
  }
};

bool connectToServer() {
    Serial.print("Forming a connection to ");
    Serial.println(myDevice->getAddress().toString().c_str());
    
    BLEClient*  pClient  = BLEDevice::createClient();
    Serial.println(" - Created client");

    pClient->setClientCallbacks(new MyClientCallback());

    // Connect to the remove BLE Server.
    pClient->connect(myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
    Serial.println(" - Connected to server");
    pClient->setMTU(517); //set client to request maximum MTU from server (default is 23 otherwise)
  
    // Obtain a reference to the service we are after in the remote BLE server.
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService == nullptr) {
      Serial.print("Failed to find our service UUID: ");
      Serial.println(serviceUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our service");


    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic == nullptr) {
      Serial.print("Failed to find our characteristic UUID: ");
      Serial.println(charUUID.toString().c_str());
      pClient->disconnect();
      return false;
    }
    Serial.println(" - Found our characteristic");

    // Read the value of the characteristic.
    if(pRemoteCharacteristic->canRead()) {
      String value = pRemoteCharacteristic->readValue();
      Serial.print("The characteristic value was: ");
      Serial.println(value.c_str());
    }

    if(pRemoteCharacteristic->canNotify())
      pRemoteCharacteristic->registerForNotify(notifyCallback);

    connected = true;
    return true;
}
/**
 * Scan for BLE servers and find the first one that advertises the service we are looking for.
 */
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
 /**
   * Called for each advertising BLE server.
   */
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    Serial.print("BLE Advertised Device found: ");
    Serial.println(advertisedDevice.toString().c_str());

    // We have found a device, let us now see if it contains the service we are looking for.
    if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) {

      BLEDevice::getScan()->stop();
      myDevice = new BLEAdvertisedDevice(advertisedDevice);
      doConnect = true;
      doScan = true;

    } // Found our server
  } // onResult
}; // MyAdvertisedDeviceCallbacks


void setup() {
  Serial.begin(115200);
  Serial.println("Starting Arduino BLE Client application...");
  BLEDevice::init("");

  // Retrieve a Scanner and set the callback we want to use to be informed when we
  // have detected a new device.  Specify that we want active scanning and start the
  // scan to run for 5 seconds.
  BLEScan* pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setInterval(1349);
  pBLEScan->setWindow(449);
  pBLEScan->setActiveScan(true);
  pBLEScan->start(5, false);
  BLEDevice::setPower(ESP_PWR_LVL_P9); // latest info on Power boost. check link in description.
} // End of setup.


// This is the Arduino main loop function.
void loop() {

  // If the flag "doConnect" is true then we have scanned for and found the desired
  // BLE Server with which we wish to connect.  Now we connect to it.  Once we are 
  // connected we set the connected flag to be true.
  if (doConnect == true) {
    if (connectToServer()) {
      Serial.println("We are now connected to the BLE Server.");
    } else {
      Serial.println("We have failed to connect to the server; there is nothin more we will do.");
    }
    doConnect = false;
  }

  // If we are connected to a peer BLE Server, update the characteristic each time we are reached
  // with the current time since boot.
  if (connected) {
    String newValue = "Time since boot: " + String(millis()/1000);
    Serial.println("Setting new characteristic value to \"" + newValue + "\"");
    
    // Set the characteristic's value to be the array of bytes that is actually a string.
    pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
  }else if(doScan){
    BLEDevice::getScan()->start(0);  // this is just example to start scan after disconnect, most likely there is better way to do it in arduino
  }
  
  delay(1000); // Delay a second between loops.
} // End of loop

Compiler output: EDITED for brevity…
编译器输出:为简洁起见,已编辑…
Biānyì qì shūchū: Wèi jiǎnjié qǐjiàn, yǐ biānjí…

FQBN: esp32:esp32:XIAO_ESP32C6
Using board 'XIAO_ESP32C6' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.0-rc1
Using core 'esp32' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.0-rc1
Edit---
Creating esp32c6 image...
Merged 2 ELF sections
Successfully created esp32c6 image.
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.0.0-rc1\\tools\\gen_esp32part.exe" -q "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24/partitions.csv" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24/Client_power_BOOST.ino.partitions.bin"
cmd /c if exist "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24\\libraries\\Insights" "C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.0.0-rc1\\tools\\gen_insights_package.exe" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24" Client_power_BOOST.ino "D:\\Arduino_projects\\Client_power_BOOST"
cmd /c if exist "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24\\libraries\\ESP_SR" if exist "C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-arduino-libs\\idf-release_v5.1-3662303f31/esp32c6\\esp_sr\\srmodels.bin" COPY /y "C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp32-arduino-libs\\idf-release_v5.1-3662303f31/esp32c6\\esp_sr\\srmodels.bin" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24\\srmodels.bin"

Using library BLE at version 2.0.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.0-rc1\libraries\BLE 
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\esp-rv32\\2302/bin/riscv32-esp-elf-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\5B20C91A8DBB923E53790AFFA0298B24/Client_power_BOOST.ino.elf"
Sketch uses 1071906 bytes (81%) of program storage space. Maximum is 1310720 bytes.
Global variables use 33912 bytes (10%) of dynamic memory, leaving 293768 bytes for local variables. Maximum is 327680 bytes.

I read this thread,

:v:
for Nrf52840 , Try NimBle.lib has the same for the Xiao Nrf52840
对于 Nrf52840 ,尝试 NimBle.lib 对于小 Nrf52840 具有相同的内容

Duìyú Nrf52840, chángshì NimBle.Lib duìyú xiǎo Nrf52840 jùyǒu xiāngtóng de nèiróng