Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deinitialize BLE Not working: Failed with error: 259 #12

Open
chinswain opened this issue Jun 16, 2024 · 0 comments
Open

Deinitialize BLE Not working: Failed with error: 259 #12

chinswain opened this issue Jun 16, 2024 · 0 comments

Comments

@chinswain
Copy link
Contributor

Any idea on this one? I need to switch to WiFi periodically to transmit the data back but can't deinit.
If I call NimBLEDevice::deinit(true); after clearing the scan results I get:

E NimBLEDevice: esp_nimble_hci_and_controller_deinit() failed with error: 259

#include "ATC_MiThermometer.h"

const int scanTime = 5;  // BLE scan time in seconds

// List of known sensors' BLE addresses
std::vector<std::string> knownBLEAddresses = { "A4:C1:38:C5:3E:18" };

ATC_MiThermometer miThermometer(knownBLEAddresses);

void setup() {
  Serial.begin(115200);

  // Initialization
  miThermometer.begin();

}

void loop() {
  miThermometer.begin();

  // Set sensor data invalid
  miThermometer.resetData();

  // Get sensor data - run BLE scan for <scanTime>
  unsigned found = miThermometer.getData(scanTime);

  for (int i = 0; i < miThermometer.data.size(); i++) {
    if (miThermometer.data[i].valid) {
      Serial.println();
      Serial.printf("Sensor %d: %s\n", i, knownBLEAddresses[i].c_str());
      Serial.printf("Name: %s\n", miThermometer.data[i].name.c_str());
      Serial.printf("%.2f°C\n", miThermometer.data[i].temperature / 100.0);
      Serial.printf("%.2f%%\n", miThermometer.data[i].humidity / 100.0);
      Serial.printf("%.3fV\n", miThermometer.data[i].batt_voltage / 1000.0);
      Serial.printf("%d%%\n", miThermometer.data[i].batt_level);
      Serial.printf("%ddBm\n", miThermometer.data[i].rssi);
      Serial.printf("Measurement Count: %d\n", miThermometer.data[i].count);
      // Print boolean flags
      Serial.printf("Reed Switch State: %s\n", miThermometer.data[i].reedSwitchState ? "Open" : "Closed");
      Serial.printf("GPIO TRG Output: %s\n", miThermometer.data[i].gpioTrgOutput ? "High" : "Low");
      Serial.printf("Control Parameters: %s\n", miThermometer.data[i].controlParameters ? "Set" : "Not Set");
      Serial.printf("Temperature Trigger Event: %s\n", miThermometer.data[i].tempTriggerEvent ? "Triggered" : "Not Triggered");
      Serial.printf("Humidity Trigger Event: %s\n", miThermometer.data[i].humiTriggerEvent ? "Triggered" : "Not Triggered");
      Serial.println();
    }
  }
  Serial.println("BLE Devices found (total): " + String(found));

  // Delete results from BLEScan buffer to release memory
  miThermometer.clearScanResults();

  delay(5000);
  NimBLEDevice::deinit(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant