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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -