Skip to content

Instantly share code, notes, and snippets.

@HeinPauwelyn
Created December 2, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeinPauwelyn/abda9c038413adaed60030afe485200e to your computer and use it in GitHub Desktop.
Save HeinPauwelyn/abda9c038413adaed60030afe485200e to your computer and use it in GitHub Desktop.
GPS data
void loop() {
bool gotGPGGA = false;
int teller = 0;
String text = "";
String json = "";
if (SoftSerial.available())
{
while (SoftSerial.available())
{
char read = SoftSerial.read();
buffer[count++] = read;
if (String(read) == ",") {
if (text == "$GPGGA") {
gotGPGGA = true;
}
if (gotGPGGA) {
switch (teller) {
case 1:
json += "{ \"uur\": \"" + text.substring(0, 2) + ":" + text.substring(2, 4) + ":" + text.substring(4, 6) + "\", ";
break;
case 2:
json += "\"lat\": \"" + text + "\", ";
break;
case 3:
json += "\"latChar\": \"" + text + "\", ";
break;
case 4:
json += "\"lon\": \"" + text + "\", ";
break;
case 5:
json += "\"lonChar\": \"" + text + "\" }";
break;
}
teller += 1;
}
text = "";
}
else {
text += read;
}
if (count == 64) {
if (json != "") {
Serial.println(json);
}
break;
}
}
delay(2000);
clearBufferArray();
count = 0;
}
}
void clearBufferArray()
{
for (int i = 0; i < count; i++)
{
buffer[i] = NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment