ios - How to update Battery Level in BLE Device with CoreBluetooth in Swift? -


func peripheral(_ peripheral: cbperipheral, diddiscovercharacteristicsfor service: cbservice, error: error?) {          c in service.characteristics!{             print("---characteristic found uuid: \(c.uuid) \n")              let uuid = cbuuid(string: "2a19")//battery level              if c.uuid == uuid{                 //peripheral.setnotifyvalue(true, for: c)//battery level                 peripheral.readvalue(for: c)             }         }     } } func peripheral(_ peripheral: cbperipheral, didupdatevaluefor characteristic: cbcharacteristic, error: error?) { /* battery level */     if (characteristic.uuid == cbuuid(string: "2a19")) && (characteristic.value != nil){         let value = characteristic.value         let valueuint8 = [uint8](value!)         print("\(valueuint8)")         print("\(valueuint8[0])")         let batterylevel: int32 = int32(bitpattern: uint32(valueuint8[0]))         print("\(batterylevel)")      } } 

i can read battery level value, how update battery level when value changed?

why peripheral.setnotifyvalue(true, for: c) can't update?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -