ByteArray to String

I’m running a Gps-Shield and Micro Oled. Getting a byte-Buffer the conversion to String failed using (const char*)ByteBuffer*.*
```
*// initializing oled…
oled.setFontType(0);

int inByte = 0;       
byte pbyGpsBuffer[100];
int byBufferIndex = 0;

void loop()
{

byte byDataByte;
 
  if (Gps_serial.available())
  {
    byDataByte = Gps_serial.read();
   
    Serial.write(byDataByte);
    pbyGpsBuffer[ byBufferIndex++ ] = byDataByte; 
   
    if( byBufferIndex >= 100 )
    {
      byBufferIndex = 0;     
      File dataFile = SD.open(“gps.txt”, FILE_WRITE);
     
      // get Byte-Buffer to String
      for (int i=0; i<=100; i++) {
        str += (const char*)pbyGpsBuffer[i];
    }

 oled.clear(PAGE);     
 oled.setCursor(0, 0); 
 oled.print(str);
 oled.display();           

}
}*
```

Fumbling around in the dark, what happens if you remove the word "const" ?

Hello and welcome,

Why use a String? You already have an useable char array.

if( byBufferIndex == 99 )
{
    pbyGpsBuffer[ byBufferIndex ] = '\0';
    byBufferIndex = 0;
    ...
    oled.print( pbyGpsBuffer );
    ...
}

the matter of conversion is to filter NMEA-data - with strsep() for a convenient output on LCD.

pbyGpsBuffer data:
$GPGSV,3,1,12,01,00,000,,02,00,00

works well,
oled.write(pbyGpsBuffer*);*
but needful are just some tokenized informations, so i do that with strsep() on a String. If there is a direct way with ByteArray.. will be better

strtok()?

If there is a direct way with ByteArray.. will be better

There is the TinyGPS++ library that handles all the tokenizing and conversion to appropriate types for you.

strtok() will be right having a String, therefore convertion is necessary

in TinyGPS++ library aren't get functions

I copied the below from somewhere in the past, which might be of use.

String myString = String((char*)myByteArray);

//or


void setup(void)
{
}

void loop(void)
{
  byte byteArray[5];
  strcpy((char *)byteArray,"0123");
  String myString = String((char *)byteArray);
}

zoomkat:
String myString = String((char*)myByteArray);

That sounds like a song.

“Only trouble is, String string, I’m stringing my bytearray.”

Everly Brothers?

String of Pearls !

Thanks, with TinyGPS++ lib i get marvelous output on Oled.

Also, I find that strtok() works just fine on char arrays. I find using the String class is only useful if you need a crutch.

flexx:
String of Pearls !

Glenn Miller?