How can I make a BLE communication with swift and arduino device? Now with my code I'm able to send value to my BLE shield but I don't know how to send back a report to my swift application!
I use a HM-10 BLE module and Swift 2.0.
This is my arduino code:
#include<SoftwareSerial.h>
SoftwareSerial Try(1,0);
void setup() {
pinMode(3, OUTPUT);
Try.begin(9600);
}
void loop() {
if(Try.available()){
switch(Try.read()){
case('a') :{
digitalWrite(3, HIGH);
}
}
}
}
This is an easy code that when receive a char 'a' from my application, it switch on a green LED. With that is all ok but i want to send back the report 'Green LED switched on!' to my Swift app.
So this is the Swift code to send the 'a' value to my BLE module.
import UIKit
import CoreBluetooth
class Connection: UIViewController{
var connee: CBCharacteristic!
var per: CBPeripheral!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func SendingVal(sender: AnyObject) {
let Sen = "a"
let Value: NSData = Sen.dataUsingEncoding(NSUTF8StringEncoding)!
sendDataToCentral(per, characteristic: connee, data: Value)
}
private func sendDataToCentral(peripheral: CBPeripheral, characteristic: CBCharacteristic, data: NSData) {
peripheral.writeValue(data, forCharacteristic: characteristic, type: CBCharacteristicWriteType.WithoutResponse) }
}
So, how can I send back a report from BLE module to my swift app?