0

I am using a BLE device (https://www.adafruit.com/product/1697) that I use to print data to an app. I can successfully connect the BLE to the app and receive the data but the result however gets chopped up.

What I am sending is a lat, lng value (that I gather with a library called TinyGPS++ http://arduiniana.org/libraries/tinygpsplus/) and the code looks like this:

BTLEserial.Print::print(gps.location.lat(), 8);
BTLEserial.print (", ");
BTLEserial.Print::print(gps.location.lng(), 8);

So for example if the latitude is: 32.12345678, it comes like this to the app: 3, new row, 2, new row etc.

So my question is, how can I adjust my code to make sure it does not send the result chopped up but instead sends it's complete value?

asked Jan 7, 2017 at 14:52
5
  • Your app code is invalidly assuming the data will arrive in a single receive API call. You can only fix the issue by fixing the app. Timing related things you do on the arduino mightvstatistically influence the outcome, but the only sound solution is fundamentally correct receiving code. Commented Jan 7, 2017 at 16:09
  • The answer below fixed my issue though by sending it as string Commented Jan 7, 2017 at 16:10
  • No, not really. It may unreliably appear to work more often but it is wrong and based on fundamental misunderstanding. Between your ardunio and your app you have a serial link and a packetized one neither of which respects your original grouping in a more than happenstance way. Commented Jan 7, 2017 at 16:14
  • As far as i can see it sends data my app and i receive it nicely just the way i want it (not chopped). I have tested it like 30 seconds though (as it keeps sending data each 2 seconds) and maybe i could face issues with a longer connection you mean? Or will there be a issue with lat, lng accuracay (value not updating)? Commented Jan 7, 2017 at 16:18
  • Or you could face an issue when the computational load on your phone or the phase of the moon or the local RF environment changes. That is the cost of invalid assumptions in software. The only valid solution is to find the end of a message by an explicit condition. Commented Jan 7, 2017 at 16:21

1 Answer 1

0

how can I adjust my code to make sure it does not send the result chopped up but instead sends it's complete value?

The BLE device uses a package approach and the print member functions only support strings (char vectors and Arduino String). Construct the message as a String:

double lat = gps.location.lat();
double lng = gps.location.lng();
String msg = String(lat, 8) + String(", ") + String(lng, 8);
BTLEserial.print(msg); 

Cheers!

answered Jan 7, 2017 at 15:10
9
  • The first lat value works! But with the lng value a new row is created after 4 decimals has been made, so it look like this when I get it on the app now: 36.02331400, 19.7794(new row)4300 Commented Jan 7, 2017 at 15:18
  • So 4300 in this case gets on a new row Commented Jan 7, 2017 at 15:18
  • Ah, is it because 20 bytes is max to send? Commented Jan 7, 2017 at 15:19
  • With "." and "," and "space" the totalt amount of byte is 24 Commented Jan 7, 2017 at 15:20
  • 2
    Or fix your app so that it reconstructs a line of text, i.e. reads messages until new-line/carriage-return. Commented Jan 7, 2017 at 15:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.