Hi everyone!
I am having an issue with my new Arduino101: I want to send a command (e.g. a string) from the iPhone (Obj-C) via BLE to the Arduino. When the Arduino receives the command, it should send back another string to the iPhone.
The problem is: Sending (without receiving) with the following code works. Receiving data (without sending) works too - but not both together.
Does anybody have a working objective-c and arduino source code / example / tutorial which describes how to send and receive data??
I appreciate for feedback
M
#include <CurieBLE.h>
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you’re programming)
BLEService bleService(“180D”);
BLECharCharacteristic bleReadWriteCharCharacteristics(“2A37”, BLERead | BLEWrite);
int oldHeartRate = 0; // last heart rate reading from analog input
long previousMillis = 0; // last time the heart rate was checked, in msvoid setup() {
Serial.begin(9600); // initialize serial communication
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connectedblePeripheral.setLocalName(“HeartRateSketch”);
blePeripheral.setAdvertisedServiceUuid(bleService.uuid()); // add the service UUID
blePeripheral.addAttribute(bleService); // Add the BLE Heart Rate service
blePeripheral.addAttribute(bleReadWriteCharCharacteristics); //send/receive datablePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);bleReadWriteCharCharacteristics.setEventHandler(BLEWritten, charactersReceived);
Serial.println(“Bluetooth device active, waiting for connections…”);
}void loop() {
blePeripheral.begin();if (blePeripheral.central()) {
Serial.print("Connected to central: ");
// print the central’s MAC address:
Serial.println(blePeripheral.central().address());
// turn on the LED to indicate the connection:
digitalWrite(13, HIGH);
}
}void blePeripheralConnectHandler(BLECentral& central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}void blePeripheralDisconnectHandler(BLECentral& central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}void charactersReceived(BLECentral& central, BLECharacteristic& characteristic) {
Serial.println(“sth received2”);if (bleReadWriteCharCharacteristics.value()) {
Serial.println(*characteristic.value());
if ((String)*characteristic.value() == “49”) { //Batteriestatus
Serial.println(“received Data”);String FileMeasure=“Hello!”;
int TempNumOne=sizeof(FileMeasure);
char Filename[10];
for (int a = 0; a<=TempNumOne;a++) {
Filename[a]=FileMeasure[a];
}bleReadWriteCharCharacteristics.setValue(*Filename);
//bleWriteCharacteristics.setValue(Filename,40);}
}
}