Friday 15 July 2011

android - Problems when sending a continuous stream of data over BLE -



android - Problems when sending a continuous stream of data over BLE -

i'm wondering if can help me figure out causing info sending become corrupt.

my setup arduino pro mini hm-10 bluetooth module connected (i have tried hm-11 module too) , android application receive bluetooth data.

module setup: http://letsmakerobots.com/node/38009

if send info big plenty intervals info fine, if send info continuously see messages getting mixed , lost. test send "$0.1,0.2,0.3,0.4,0.5" android application arduino, stream of info appears send fine other times quite scrambled. please see below graphs demonstrate this:

good case:

bad case:

arduino code:

string inputstring = ""; //hold incoming data. boolean stringcomplete = false; //determines if string complete. boolean realtime = false; void setup() { serial.begin(9600); delay(500); serial.print("at+start"); delay(500); } void loop() { if(stringcomplete) { if(inputstring.equals("rstart")) { serial.println("$startack"); realtime = true; } else if(inputstring.equals("stop")) { serial.println("$stopack"); realtime = false; } else{ serial.print(inputstring); } inputstring = ""; stringcomplete = false; } if(realtime) { serial.println("$0.1,0.2,0.3,0.4,0.5,0.6"); delay(10); } } void serialevent() { while (serial.available()) { // new byte: char inchar = (char)serial.read(); if (inchar == '\n') { stringcomplete = true; } else { inputstring += inchar; } } }

the android side receives info , parses in intentservice:

@override protected void onhandleintent(intent intent) { //incoming command. string rawdata = intent.getstringextra(dataprocessingintentservice.request); //append our new info our info helper. log.i(this.getclass().getname(), "previous raw: (" + dataprocessinghelper.getinstance().getdata() + ")"); dataprocessinghelper.getinstance().appenddata(rawdata); log.i(this.getclass().getname(), "new raw: (" + dataprocessinghelper.getinstance().getdata() + ")"); commandstartindex = dataprocessinghelper.getinstance().getdata().indexof("$"); commandendindex = dataprocessinghelper.getinstance().getdata().indexof("\n"); //set info starting point. if(commandstartindex != -1){ dataprocessinghelper.getinstance().offsetdata(commandstartindex); } //ensure command has been found , end index after starting index. if(commandstartindex != -1 && commandendindex > commandstartindex){ //remove command construction command. command = dataprocessinghelper.getinstance().getdata().substring(commandstartindex+1, commandendindex-1); //remove \r\n end command. dataprocessinghelper.getinstance().offsetdata(commandendindex+1); if(command.length() > 1){ //split info out of comand. splitdata = command.split(","); log.i(this.getclass().getname(), "broadcasting processed data. (" + command + ")"); //broadcast data. intent broadcastintent = new intent(); broadcastintent.setaction(dataprocessingintentservice.response); broadcastintent.addcategory(intent.category_default); broadcastintent.putextra(dataprocessingintentservice.response, splitdata); sendbroadcast(broadcastintent); }else{ log.e(this.getclass().getname(), "command less 1 character long!"); } } }

thank help!

i have figured out causing problem. appears ble supports maximum of 20 bytes per transaction. time between these transactions different depending on using. i'm using notifications means can send 20 bytes every 7.5 milliseconds maximum. have opted 10 milliseconds safe. need breaking packets 20 bytes maximum ensure no info corruption.

android arduino bluetooth-lowenergy

No comments:

Post a Comment