Hey there,
i was creating a Datalogger with the Arduino 101 and a Dataloggershield. This Shield is Saving Events on a SD Card. Thats Working so far. The Data saved on the SD Card should be available over an Android App. The Idea was to use One BLE Service to show the Content of the SD Card and another one to send the chosen Data.
The Basic Idea of the Send Service was to work with 3 Characteristics.
- 1 Bool "Sendrequest" Which is set by the App to start the transmission
- 1 Int "sendstate" which is on 0 per default, on 1 if the Arduino sent data an on 2 if the App is ready to recive data
- 1 Char "txcharacteristic" as soon as the transmission is initiatet the Arduino Loads the desired Data from the SD Card into a Queue and pops this Queue Char by Char. The Android App reads the Char and "confirms". As soon as that happend the Arduino Sends the next char.
At the moment im Stuck at the sending part. You can set the Value of the Sendstate from the App but printing out the Value of Sendstate over Serial will allways show a "1" no matter what number you set.
#include <QueueList.h>
#include <CurieBLE.h>
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)
BLEService sendService("6E400001B5A3F393E0A9E50E24DCCA9E");
BLECharCharacteristic txCharacteristic("6E400003B5A3F393E0A9E50E24DCCA9E",BLERead ) ;
BLECharCharacteristic sendrequest("6E400002B5A3F393E0A9E50E24DCCA9E", BLEWriteWithoutResponse);
BLEIntCharacteristic Sendstate("6E400004B5A3F393E0A9E50E24DCCA9E",BLEWrite | BLERead ); // 0 = keine Information 1 = Arduino hat gesendet 2 = App hat empfangen/ist empfangsbereit
QueueList <char> Buffer;
void setup() {
// put your setup code here, to run once:
// set advertised local name and service UUID
blePeripheral.setLocalName("101 BLE");
blePeripheral.setAdvertisedServiceUuid(sendService.uuid());
// add service and characteristic
blePeripheral.addAttribute(sendService);
blePeripheral.addAttribute(sendrequest);
blePeripheral.addAttribute(txCharacteristic);
blePeripheral.addAttribute(Sendstate);
// assign event handlers for connected, disconnected to peripheral
blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
sendrequest.setEventHandler(BLEWritten, sendrequestWritten);
// assign event handlers for characteristic
sendrequest.setEventHandler(BLEWritten, sendrequestWritten);
sendrequest.setValue(0);
txCharacteristic.setValue(0);
Sendstate.setValue(2);
// begin initialization
blePeripheral.begin();
Serial.begin(9600);
while(!Serial);
Serial.println("Filling queue");
for (int i =0;i<3;i++)
{
Buffer.push(i);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
void transmit(){
Serial.println("transmitting");
Serial.println(Sendstate);
//while(Buffer.count()>0){
if(Sendstate == 2)
{
txCharacteristic.setValue(Buffer.pop());
Sendstate.setValue(1);
Serial.println("Sending");
}
//}
Sendstate.setValue(0);
Serial.println(Sendstate);
return;
}
void sendrequestWritten(BLECentral& central , BLECharacteristic& characteristic){
Serial.println("sendrequest written");
if (sendrequest.value()){
transmit();
}
}
void blePeripheralConnectHandler(BLECentral & central) {
// central connected event handler
Serial.println("connected");
}
void blePeripheralDisconnectHandler(BLECentral & central) {
// central disconnected event handler
Serial.println("disconnected");
}
anybody an Idea why this is not working or a better Idea to send data over BLE?