hoiberg / HM10-BluetoothSerial-iOS

An iOS 10 app to communicate with a HM10 Bluetooth module
189 stars 74 forks source link

Bluetooth Transfer of .csv file #18

Closed hchheta7 closed 5 years ago

hchheta7 commented 5 years ago

I want to transfer .csv file via bluetooth to Arduino hm-10 ble Bluetooth module from iOS App, so I am creating app so is it compulsory to have Arduino Module with me for testing Actually I dont know frpm where to start So can you help me with I mean can your project help me with same?

Thanks in advance

hoiberg commented 5 years ago

To read the csv file use:

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {    
   let fileURL = dir.appendingPathComponent("yourfile.csv")
   do {
      let text = try String(contentsOf: fileURL, encoding: .utf8)
   } catch {
      print(error.localizedDescription)
   }
}

And then send this string using BluetoothSerial as you would with any other string, using the serial.sendMessageToDevice(_:) function. But be sure to do so in small chunks of say 50 characters, with some time in between so the HM10 is able to catch up. Or a way more efficient method would be to load the file as Data, not String, because in sendMessageToDevice(_:) the string is converted to Data so this saves you an extra step.