I want to connect to ohaus scale using ohaus bluetooth interface:
https://dmx.ohaus.com/WorkArea/showcontent.aspx?id=4294974224
I succeeded to connect and receive the CBCharacteristic with uuid 2456e1b9-26e2-8f83-e744-f34f01e9d703.
I want to get the weight of the scale. Here is what I do:
//send command to the scale
let data = "IP"
let valueString = (data as NSString).data(using: String.Encoding.utf8.rawValue)
self.scalePeripheral.writeValue(valueString!, for: scaleCharchteristic, type: CBCharacteristicWriteType.withResponse)
I should expect to receive the scale weight with the delegate function:
func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic,error: Error?){
guard
let characteristicValue = characteristic.value,
let characteristicASCIIValue = NSString(data: characteristicValue, encoding: String.Encoding.utf8.rawValue)
else {
return
}
print("\((characteristicASCIIValue as String))")
}
But I receive empty value.
Also I don't receive any data to peripheralDidUpdateValueForCharacteristic.
What may be the problem?
Here is the reference of the bluetooth commands:

You can't just access
characteristic.valueyou need to either:Perform a
readValue(for:)of the characteristic and wait for a callback toperipheral(_:didUpdateValueFor:error)orEnable characteristic notifications via
setNotifyValue(for:)Not all characteristics support notifications, but if it is supported, it is the best approach to use, rather than polling.
Since it appears that your device is emulating a serial port over GATT, it is quite likely that notifications are supported (Check the
propertiesof your characteristic fornotifyorindicatesupport).