Very long string formating

ok thanks

Sorry, I accidently hit post and had go back and edit it. :unamused:

Perhaps we can be a bit more precise in the description. You have a "stream" of data. IT is neither a String nor a string. And you need to process it as a stream.
However, you need to decide if the stream will ever have and ending so you can complete a program to process it, or will you just turn off the power to the Arduino?

  if (rxValue.length() > 0)
  {
    value = "\"";
    int count = 0;
    for (int i = 0; i < rxValue.length(); i++)
    {
      char c = rxValue[i];
      value += c;
      count++;
      if (count == 36 || c == '.' || c = '_' || c == '-')
      {
        value += "\"\n\"";
        count = 0;
      }
    }
    value += "\"";
    value_return = value_return + value;
  }
  Serial.println(value);

Looks more like it....i'll get on it asap and give a feedback...thanks a lot

I'm getting this error for the line below; lvalue required as left operand of assignment

if (count == 36 || c == '.' || c = '_' || c == '-')

Nevermind, figured it out....an equal to sign was missing

1 Like

Hello @johnwasser so your code does the formatting just fine, however when i parsed it to base64 decode, i still got garbage. At this point, am lost. I also realized that storing the string as a constant i.e in the code, works just fine with base64 decode. But when i receive it via BLE, the base64 decoding prints garbage. Do you know where the problem could be coming from?

Can you print out the raw base64 message being received via BLE.

Hopefully it doesn't look like the sample data you gave us back in post #1 as that isn't base64 encoded. If it was meant to be base64 encoded, then the encoding has gone wrong, or the transmission has messed up the data.

Yes i am able to print it out with no issues but i think because its too long, it takes a few seconds before it gets completed. I think thats where the issue is. i need to receive it and save it somehow such that it looks like a constant in code.

That way, it would have cooled down before i parse into base64 decoding. If you know what i mean

Ah, I should have worded that differently!

Can you upload a sample of your received base64 datastream so we can see it.

Its sensitive data so i dont feel comfortable posting it.

Ok. Understood. In that case have you tried to save the received base64 data - copy & paste into notepad and decode using a base64 decoder just to make sure that it is valid base64 encoded data.

With base64, the number of characters received is usually a multiple of 4 bytes. So if you are receiving a number of bytes not divisible by 4, then something has gone wrong.

Yes, infact to be sure, i have decoded on several websites and it worked just fine by copy and paste. So its a valid base64 encoded data. copy and paste even works fine in the sketch too. But receiving it via BLE and attempting base64 decode just prints garbage.

Ok. I think we can rule out encoding and transmission errors.

I'm curious to understand those specific delimiters. In base64, there isn't such a thing. A packet of data is received and then decoded. Are those delimiters associated with the decoded data rather than the encoded data?

The delimiters work both ways. But at this point, i doubt its a delimiters issue as they get successfully transmitted and received too. Its just so tiring at this point.

Was the data originally ASCII? You can't take binary data, encode it Base64 into ASCII, decode it Base64 back into binary, and expect it to print out as readable ASCII. Binary data tends to look like garbage when printed.

Can you try with fake (not sensitive) data that is the same format as your sensitive data?

Exactly, i have createda fake token and i'll upload here, You can try sending it over BLE and receive with an ESP32 or similar, then try decode into base64.

ew0KICAiYXRfaGFzaCI6ICJiMHZBdXR3dDdsQVhyY2c2UkZPZXVRIiwNCiAgInN1YiI6ICI1MmJmOTBzYS03NjIwLTkwNDItNjM5MC0yNGM5ZTI5YnlkODkiLA0KICBdLA0KICAiZW1haWxfdmVyaWZpZWQiOiBmYWxzZSwNCiAgIm5vbmNlIjoNCiAgImlkZW50aXRpZXMiOiBbDQogICAgew0KICAgICAgImlzc3VlciI6IG51bGwsDQogICAgICAicHJpbWFyeSI6ICJ0cnVlIiwNCiAgICAgICJkYXRlQ3JlYXRlZCI6ICIxNjU4MTY5MDU1ODc1Ig0KICAgIH0NCiAgXSwNCiAgInRva2VuX3VzZSI6ICJpZCIsDQogICJhdXRoX3RpbWUiOiAxNjgyNDEyMzQ2LA0KICAibmFtZSI6ICJBbnRpcXVlcyIsDQogICJleHAiOiAxNjgyNDE1OTQ2LA0KICAiaWF0IjogMTY4MjQxMjM0NiwNCiAgImVtYWlsIjogImFudGlxdWl0aWVzQGdtYWlsLmNvbSINCn0=

Hello, ive attached a sample token which can be decoded with any base64..thanks

So the correct decode is:

{
  "at_hash": "b0vAutwt7lAXrcg6RFOeuQ",
  "sub": "52bf90sa-7620-9042-6390-24c9e29byd89",
  ],
  "email_verified": false,
  "nonce":
  "identities": [
    {
      "issuer": null,
      "primary": "true",
      "dateCreated": "1658169055875"
    }
  ],
  "token_use": "id",
  "auth_time": 1682412346,
  "name": "Antiques",
  "exp": 1682415946,
  "iat": 1682412346,
  "email": "antiquities@gmail.com"
}