Open nladuo opened 7 years ago
Who is sending the data that you receive there, the external device? I would suggest that you look into why it only sends you that data once.
Yes, it is a external device, a Bluetooth 4.0 UART Transceiver Serial Module. When I connected the RxD Pin and the TxD Pin and then sent data to this device, this device would send the data what it had received simultaneously.
Could be that the device doesn't support receiving as big chunks as the iOS device.
It has a objective-c based sample and works well. I want to migrate it to swift-based one.
-(void) writeValue:(int)serviceUUID characteristicUUID:(int)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data {
UInt16 s = [self swap:serviceUUID];
UInt16 c = [self swap:characteristicUUID];
NSData *sd = [[NSData alloc] initWithBytes:(char *)&s length:2];
NSData *cd = [[NSData alloc] initWithBytes:(char *)&c length:2];
CBUUID *su = [CBUUID UUIDWithData:sd];
CBUUID *cu = [CBUUID UUIDWithData:cd];
CBService *service = [self findServiceFromUUIDEx:su p:p];
if (!service) {
printf("Could not find service with UUID %s on peripheral with UUID %s\r\n",[self CBUUIDToString:su],[self UUIDToString:(__bridge CFUUIDRef )p.identifier]);
return;
}
CBCharacteristic *characteristic = [self findCharacteristicFromUUIDEx:cu service:service];
if (!characteristic) {
printf("Could not find characteristic with UUID %s on service with UUID %s on peripheral with UUID %s\r\n",[self CBUUIDToString:cu],[self CBUUIDToString:su],[self UUIDToString:(__bridge CFUUIDRef )p.identifier]);
return;
}
if(characteristic.properties & CBCharacteristicPropertyWriteWithoutResponse)
{
[p writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];
}else
{
[p writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
}
I faced the same problem when try to send photos between two devices.It's 50% failed, and need to wait so long to receive the photo.
@nhatlee BLE isn't made for transferring large files, hence the speed. I haven't encountered these issues, I will try to reproduce.
I am using the BLE CC2541 module to interact with my arduino device.
For testing, I connected the TxD pin and RxD pin directly for that I can get the same data when I send data in iOS App.
Like this:
First, I used the Example of this repository. After I modified the UUID of service and characteristic, I successfully scanned my BLE device. But when I send multiple data, it only received one.
And then I created a simple project, It has a button for sending data, a textfield for what to send and a textview for displaying the received data.
The code is like this:
I filled the TextField with "gghh", after multiple clicking on sendBtn, what it returned like this:
Previously, I used a objective-c library: SerialGATT.h, SerialGATT.m which can receive the data at real time when I tap the button. I am using
pod 'BluetoothKit', '~> 0.4.0'
.