Open shaneinak opened 4 hours ago
Well... I rebooted again and the readings are correct again. I guess this is just one of those quirky issues that gets fixed with the magic ON/OFF button. if anyone knows what may be causing this odd behavior I'd appreciate any tips. At one point I had three characteristics, the third being the battery level of the sensor. I was getting many combinations of crisscrossed values. I ended up removing the battery since the battery life was to short, I decided to just hardwire the sensor power for reliable power. The values getting crossed up is a strange one and I am a total armature and most likely don't have the most efficient coding.
The problem
I have a BLE sensor with two characteristics. One is for the amount of oil in my tank in gallons, the other is the percent full . It was all working as expected and displaying in my home assistant dashboard as expected. This setup is still in a lab environment and I wanted to ensure it could survive a reboot. After the reboot the readings appear but the percentage reading shows up as the gallons and the gallons show up as the percentage. It is a 300 gallon tank that has 262.8 gallons that comes out to 87.6% full. How did a reboot of the ble_sensor and the BLE proxy device flip these readings?
Which version of ESPHome has the issue?
ESPHome 2024.10.3
What type of installation are you using?
Home Assistant Add-on
Which version of Home Assistant has the issue?
2024.11.1
What platform are you using?
ESP32
Board
ESP-WROOM-32 ESP32 ESP-32S
Component causing the issue
No response
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
Here is a snip of the BLE specific Arduino code on the sensor device:
bool deviceConnected = false; bool oldDeviceConnected = false;
define SERVICE_UUID "5624c4a0-a813-48d1-84f8-39aadcf45b76"
define CHARACTERISTIC_GALLON_UUID "bc7f5493-977c-40a9-8546-9b987ff71586"
define CHARACTERISTIC_PERCENT_UUID "efb623c7-1297-4ca5-bf35-cfcaa1949ce7"
// makes the chracteristic globlal static BLECharacteristic pCharacteristicGallon; static BLECharacteristic pCharacteristicPercent;
class MyServerCallbacks : public BLEServerCallbacks { void onConnect(BLEServer *pServer) { deviceConnected = true; };
void onDisconnect(BLEServer *pServer) { deviceConnected = false; } };
void setup() {
BLEDevice::init("Tank Level Sensor"); BLEServer pServer = BLEDevice::createServer(); pServer->setCallbacks(new MyServerCallbacks()); BLEService pService = pServer->createService(SERVICE_UUID); pCharacteristicGallon = pService->createCharacteristic( CHARACTERISTIC_GALLON_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE ); pCharacteristicPercent = pService->createCharacteristic( CHARACTERISTIC_PERCENT_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE ); pService->start(); BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(SERVICE_UUID); //pAdvertising->addManufacturerSpecificData(MANUFACTURER_ID); pAdvertising->setScanResponse(true); pAdvertising->setMinPreferred(0x06);
pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); }
void loop() { if (!deviceConnected && oldDeviceConnected) { delay(500); // give the bluetooth stack the chance to get things ready BLEDevice::startAdvertising(); // restart advertising oldDeviceConnected = deviceConnected; } // connecting if (deviceConnected && !oldDeviceConnected) { // do stuff here on connecting oldDeviceConnected = deviceConnected; }
}