Go Down

Topic: Sending Data From Arduino 101 to Android App (Read 544 times) previous topic - next topic

momokobele

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.

Code: [Select]
#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?

drmpf

You could use my pfodApp (www.pfod.com.au) which allow you to send data in CSV format for logging or plotting on the app.

See http://www.forward.com.au/pfod/BLE/index.html#Arduino101
for a complete example.

The free pfodDesigner app lets you design your own menus to control the Arduino101 and control the sending of the data from storage and then generates the Arduino101 code for you.

Also check out this graphical interface to the Arduino 101
http://www.forward.com.au/pfod/ArduinoProgramming/starterIndex.html
using the same pfodApp.  



This interface is completely generated by the code in your Arduino 101.  Your Arduino 101 controls everything the app displays and how the user interacts with the app.


momokobele

That sounds like a great App but i'm not just do this Project to have a working system in the End but to learn more about Programming Arduino / Java and the ussage of BLE. :)

Go Up