Can't print full data from Bluetooth!

hi.
I have programed with HM-10 Bluetooth BLE 4.0
Via AT command and find beacon information.

I want to program printing return values of "AT+DISI?" in real time.

this is my code.

void loop() {
  if (cnt == 0) {
    bluetooth.print("AT+DISI?");
    delay(1000);
  }
  delay(50);
  cnt++;

  Serial.print(char(bluetooth.read()));
  if (cnt == 100) {
    Serial.println("*"); //line end
    cnt = 0; //clear cnt
  }
}

normally, "AT+DISI?"s answers are "OK+DISISOK+DISC:4C000215:E2C56DB5DFFB48D2B060D0F5A71096E0:00000001C5:20C38FC2C26F:-052OK+DISCE"

But this code checked in Serial monitor,
printed :
"OK+DISISOK+DISC:4C000215:E2C56DB5DFFB48D2B060D0F5A71096E0:00000001C5:20COK+DISCE

lost end of some characters red colored!

their common ground, printed count of charaters are almost 70~71.

I dont know why this happend.

i hope to someone help this problem.

Thanks for patience to read my short english.

Please post all your code.

Also, post it inside code tags so it looks like this:

...code here
#include <SoftwareSerial.h>

SoftwareSerial bluetooth(8, 9);
int cnt=0;
void setup(){
  bluetooth.begin(9600);
  Serial.begin(9600);
  
}

void loop() {
  if (cnt == 0) {
    bluetooth.print("AT+DISI?");
    delay(2000);
  }
  delay(30);
  cnt++;

  Serial.print(char(bluetooth.read()));
  if (cnt == 100) {
    Serial.println("*"); //end line
    cnt = 0; //clear cnt
  }
}

here is full code thank you!

But, based on the code you have posted, it should probably look more like this (untested):

byte started = 0;
const char endTag[] = "DISCE";

void loop() 
{
  if (started == 0) 
  {
    bluetooth.print("AT+DISI?");
    started = 1;
  }

  if (bluetooth.available())
  {
      char charIn = bluetooth.read();

      Serial.print(charIn));

      // look for the endTag while we are processing
      if (charIn = endTag[index])
      {
          index++;
      }
      else
      {
          // it didn't match. Start the search for the end tag again.
          index = 0;
      }

      // have we found the endTag?
      if (index == 5) 
      {
         Serial.println("*"); //line end
         started = 0;
         index = 0;
      }
  }
}

hongym:
here is full code thank you!

So yeah, you need to use bluetooth.available(), and not use delay(). See my previous post.

this is my result.

OK+DI*
K�OK+*
K-�OK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*
#miOK*

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(8, 9);
int cnt = 0;
int started = 0;
int index = 0;
const char endTag[] = "DISCE";

void setup() {
  bluetooth.begin(9600);
  Serial.begin(9600);

}

void loop() {
  if (started == 0)
  {
    bluetooth.print("AT+DISI?");
    started = 1;
  }

  if (bluetooth.available())
  {
    char charIn = bluetooth.read();

    Serial.print(charIn);

    // look for the endTag while we are processing
    if (charIn = endTag[index])
    {
      index++;
    }
    else
    {
      index = 0;
    }

    // have we found the endTag?
    if (index == 5)
    {
      Serial.println("*"); //line end
      started = 0;
      index = 0;
    }
  }
}

i cant figure out this result :frowning:

woops. Sorry.

Change to this:

    if (charIn == endTag[index])

it works! thank you!!

hongym:
it works! thank you!!

Cool. Hopefully you understand why it works.

I just realised, this:

  if (bluetooth.available())

should be changed to this:

  if (started == 1 && bluetooth.available())