Author Topic: RFduino to Android BLE communication weird behavior  (Read 2111 times)

yasser304

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
RFduino to Android BLE communication weird behavior
« on: October 18, 2014, 08:40:41 AM »
We are working on app which sends a stream of characters from RFduino to an Android app. We have used a Processing sketch to write a 20 character array onto a Serial port on char at a time. The first character is a sample counter value (0-55) and the other 19 chars are letters A through S. The RFduino stores this char array onto a buffer and sends it to the Android app over a BLE channel for each stream of 20 characters. There is a certain delay introduced between each character array in the processing code. We have noticed some weird behavior in the data being received on the Android depending on this delay.

When the delay is set to a value of 64ms or 99ms or 101ms, all seems fine on the Android side and we receive the correct stream of characters on LogCat as below.

Code: [Select]
10-18 11:02:18.239: I/MainActivity(2696): RFDuino Data: 42: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.330: I/MainActivity(2696): RFDuino Data: 43: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.440: I/MainActivity(2696): RFDuino Data: 44: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.520: I/MainActivity(2696): RFDuino Data: 45: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.670: I/MainActivity(2696): RFDuino Data: 46: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.770: I/MainActivity(2696): RFDuino Data: 47: ABCDEFGHIJKLMNOPQRS
10-18 11:02:18.870: I/MainActivity(2696): RFDuino Data: 48: ABCDEFGHIJKLMNOPQRS


The issue arises when the delay is set to 100ms or a very small delay such as 32ms. This leads to packets being received with a certain "offset" as below.

Code: [Select]
10-18 11:06:10.426: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS'ABCDEFGHIJK
10-18 11:06:10.526: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS(ABCDEFGHIJK
10-18 11:06:10.666: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS)ABCDEFGHIJK
10-18 11:06:10.766: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS*ABCDEFGHIJK
10-18 11:06:10.866: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS+ABCDEFGHIJK
10-18 11:06:10.966: I/MainActivity(2696): RFDuino Data: 76: MNOPQRS,ABCDEFGHIJK

The processing and arduino sketches are below.

Processing:
Code: [Select]
import processing.serial.*;
Serial port;
char ch = 'A';
char buf[] = new char[20];
int count = 0;

void setup() {
  println(Serial.list());
  port = new Serial(this, Serial.list()[5], 9600);
  for(int i=1;i<20;i++){
   buf[i] = ch;
   ch++;
}
}
void draw() {
    buf[0] = (char)count;
    for(int j=0; j<20; j++){
      print(buf[j]);
      port.write(buf[j]);
    }
    println();
    count++;
    if(count>55){
      count = 0;
    }
    delay(100);
}

Arduino:
Code: [Select]
#include "RFduinoBLE.h"

char buf[20];
bool toggle = true;
int count = 0;
void setup() {
  override_uart_limit = true;
  pinMode(2,OUTPUT);
  Serial.begin(9600);
  RFduinoBLE.advertisementData = "OBCISerial";
  RFduinoBLE.begin();
 
}

void loop() {
  if( Serial.available() )       // if data is available to read
  {
    buf[count] = Serial.read();
    count++;
   
    if(buf[0] % 2 == 0){
      digitalWrite(2,HIGH);
    }else{
      digitalWrite(2,LOW);
    }
  }
  if(count == 20){
      while (! RFduinoBLE.send(buf, 20));
     count = 0;
  }
}

Has anyone faced such an issue before or have an explanation for such behavior ?
Thanks in advance for you inputs!
« Last Edit: October 18, 2014, 05:27:47 PM by yasser304 »

Chuchaki

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: RFduino to Android BLE communication weird behavior
« Reply #1 on: August 02, 2016, 07:16:16 AM »
Hey,

I'm sorry nobody answered!
 I wanted to ask, if you found out what was wrong. I might have a similar issue myself.


Greetings

 

anything