faulty transmission/retrieval of bluetooth data

      switch (inByte) {
        case ':':
          commandString [input_pos] = '\0';  // terminating null byte
          input_pos = 0;
          parse_the_string ++;
          break;
        default:
          if (input_pos < (MAX_INPUT - 1))
            commandString [input_pos++] = inByte;
          break;
      }

A switch statement is appropriate when you have more than 2 cases.

  static char commandString [MAX_INPUT];
  static char red [MAX_INPUT];
  static char green [MAX_INPUT];
  static char blue [MAX_INPUT];

This set of arrays does not mesh with you sending "45".

45 is the H value is a hls color. On the javascript side on the phone app. it converts 45 to rgb and constructs the string "c:255,191,0;" base64 encodes it, and sends it.
I have

  static char commandString [MAX_INPUT];
  static char red [MAX_INPUT];
  static char green [MAX_INPUT];
  static char blue [MAX_INPUT];

and the switch case statement because it breaks apart the incoming message on : , and ;
using ; as the identifier to send the values off where "c" will eventually be used to identify which function to send the color to.

I am guessing the switch case that parses the data could be refactored but I had found someone elses example for parsing incoming serial data and modified it a bit to handle the format of my data.

I might have taken it too literally when you asked for complete code. Would you like me to make a new sketch containing only the code in question and repost the sketch?

base64 encodes it, and sends it.

So, what is being sent is NOT "c:255,191,0;", but you assume, on the receiver, that it is. I'm not understanding why.

Did I somehow miss the part where you base64 decode the text coming in one serial port and send it out to the serial port you are reading from in the code above?

I am using a third party package with react native to access bluetooth capabilities within the phone app, which if i recall correctly, needed to base64 encode the string before sending it.

Then I am using the hm10 with software serial. I am not super experienced with managing serial data, but I thought was on the right path.
When processing the data with processIncomingByte, despite sending the string as base64 encoded, I am able to parse the characters correctly. It just starts to breakdown when I send data too quickly.

You did not miss any decoding on the arduino side. I'm not clear how, but when I assume I am receiving the string (not base64 encoded) and parse each byte with that assumption, saving in the char arrays, it seems to match the assumption and get parsed as expected.

I am willing to attempt this process in a different manner if you believe I am doing something incorrectly and I can post the results. Should I try everything the same, but send the string without base64 encoding?

Should I try everything the same, but send the string without base64 encoding?

The string being sent, if you can read it, is NOT base64 encoded. Whether that happens because the phone app decodes it before sending, or for some other reason, I do not know.

With all your arrays, how much SRAM are you using? Do the arrays NEED to be that big?

What I would do is comment out all the code that USES the data, and just print the values parsed. Send the data as fast as possible. If that data all gets through, then it is the process of using the data that is causing problems. If not, then it is the process of sending or reading the data that is causing problems.

When we know which problem you are trying to solve, we can solve it faster.

I commented out the

//manuallyChangeBladeColor(redValue, greenValue, blueValue);

so that it only parses the data and prints to the console.

red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 253 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 253 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 64 blue: 255
value ->
red: 0 green: 19000 blue: 64

it seems to mess up about 2-10% of the time.

I supposed the r,g,b would not be more than 3 characters and I could limit the command to no more than 10 characters

I supposed the r,g,b would not be more than 3 characters and I could limit the command to no more than 10 characters

Your string looks, at max, like "c:rrr,ggg,bbb;". Looks more like 14 characters plus a terminating NULL.

Again, you are doing more than just reading the data. Just read, and print the strings. Do NOT convert to integers.

You want to pick up the speed of Serial. It does not have to match the speed of the software serial instance, which is running pretty fast, for the volume of data you are sending.

Using a board with more than one hardware serial port would be a better idea.

Ziayakens:
45 is the H value is a hls color. On the javascript side on the phone app. it converts 45 to rgb and constructs the string "c:255,191,0;" base64 encodes it, and sends it.

Make your Arduino program print out exactly what it receives before it attempts to parse it. Then post some examples of what it receives.

Telling us earlier that you "send the same value (45) many times" was not much help.

...R

sorry >_<
I brought it up to

Serial.begin(115200);

and have

void loop() {
  while (mySerial.available () > 0) {
    Serial.print(mySerial.read());
  }
  Serial.println("");
}

which gives me

995850535344495749444859 
 
995850535344495749444859995850535344495749444859 
995850535344 
49 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
995850 
53995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995859 
995850535344495749444859 
 
 
 
995850535344495749444859995850535344495749444859995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
9958505353444957 
4944 
995850535344495749444859 
 
995850535344495749444859 
 
99495749444859 
99585053534449574944485999585053 
53 
995850535344495749444859 
 
995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
995850 
53 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
995850535344495749444859 
9949444859 
995850535344495749444859 
 
995850535344495749444859 
9958505353444957494448 
59 
995850535344495749444859 
 
995850535344495749444859 
 
9949444859 
995850535344495749444859 
 
995850535344495749444859995850535344495749444859 
 
 
99585053534449 
5750535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
9958505353 
4449 
995850535344495749444859 
 
995850535344495749444859 
 
99535344495749444859 
995850535344495749444859 
995859 
995850535344495749444859 
 
995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
 
99444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859995850535344495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
9958505353444957 
49 
995850535344495749444859 
 
995850535344495749444859 
 
9944495749444859 
995850535344495749444859 
 
995850535344495749444859 
 
995850535344495749444859 
995850535344495749444859

Ziayakens:
which gives me

And is that you are expecting?

That simple program in Reply #14 makes no attempt to identify the start or end of the messages. Without knowing when a message starts and ends how can you parse it properly?

Have you carefully studied the examples in the link I gave you in Reply #2?

...R

    Serial.print(mySerial.read());

The read() method returns an int, not a char. Store the value in a char, and print the char.

I was recently working with an Arduino and HM-10 with a phone app. Characters would intermittently get dropped when sending to the Arduino. I could see that my app was (trying) to write all the characters but every now and then there would be one missing on the receiving end.

I fixed it by having the Arduino echo the characters back to the phone, with the app waiting until it receives characters before writing to the characteristic again.

If your problem is with transmission and not with parsing you might give that a shot.

oh thats unfortunate.. I see to be parsing it incorrectly.

with

void loop() {
  while (mySerial.available () > 0) {
    char d = mySerial.read();
    Serial.print(d);
    if (d == ';') {
      Serial.println("");      
    }
  }
}

It shows

c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;
c:255,191,0;

Robin2, yes I read that, In the main code I was trying to use ; as the indicator of the end of the data. But it seems im not parsing correctly

Ziayakens:
Robin2, yes I read that, In the main code I was trying to use ; as the indicator of the end of the data. But it seems im not parsing correctly

I reckon if you use the second example in my Serial Input Basics and change the end-marker to a semi-colon it will receive the data correctly.

Once you have received a message you can parse it with strtok() using the comma as the separator. The first group will include the c: and it looks like you can just ignore those first 2 characters - just replace them with the 0 character (ASCII 48).

...R

just replace them with the 0 character (ASCII 48).

Or the space character (ASCII 32).

when I use your sketch like

void loop() {
recvWithEndMarker();
showNewData(); 
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = ';';
    char rc;
    
    while (mySerial.available() > 0 && newData == false) {
        rc = mySerial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

I get

This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c,0
This just in ... c:255,191,0
This just in ... c:255,1c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0
This just in ... c:255,191,0

You have not posted the complete program so I have no idea what pins you are using or what baud rate etc etc

I am tempted to say there is a problem with the incoming data, but I would like to see the whole program.

...R

I actually eventually got it to work with this

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8); // RX, TX 

void setup() {
  Serial.begin(115200);
  mySerial.begin(57600); //required when using the hm-10 with an arduino nano
  mySerial.listen();
}
char data[20];
byte indx = 0;
void loop() {
  while (mySerial.available () > 0) {
    char d = mySerial.read();
    data[indx] = d;
    indx ++;
    if (d == ';') {
      Serial.println(data);
      data[0] = (char)0;
      indx = (byte)0;      
    }
  }
}

I still nee to implement strtok() and more but your link sent me in the right direction. Thank you so much.
I apologize if I was difficult to assist, but I greatly appreciate your help.

Ziayakens:
I actually eventually got it to work with this

That does not seem to be functionally different from my tutorial code.

There is a parse example in the tutorial.

...R