print only new sensor data

Hello everyone! Sorry for bothering, I need help: I have GPS and code http://learn.parallax.com/KickStart/28500
But in loop every 5 second same data sent, its little bit messy ,I wanna print only new sensors data not the same with previous . If you have advice or some examples pls share with me
For example result is :
Reading GPS
35.3608, 139.2746
35.3611, 139.2745
35.3610, 139.2745
35.3610, 139.2745
35.3610, 139.2745
35.3610, 139.2745
35.3610, 139.2745
35.3610, 139.2745
35.3610, 139.2745
It will be better if it will be printed like this :
35.3608, 139.2746
35.3611, 139.2745
35.3610, 139.2745

here code:

#include <SoftwareSerial.h>
#include "./TinyGPS.h"                 // Special version for 1.0

TinyGPS gps;
SoftwareSerial nss(6, 255);            // Yellow wire to pin 6

void setup() {
  Serial.begin(115200);
  nss.begin(4800);
  Serial.println("Reading GPS");
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 5000) {  // Update every 5 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);
  }
}

// Get and process GPS data
void gpsdump(TinyGPS &gps) {
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  Serial.print(flat, 4); Serial.print(", "); 
  Serial.println(flon, 4);
}

// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

If you only want to put the data in the database when it has changed, then each time you read it save it in a variable. Next time you read the data compare it with the previous saved data and only put it in your database if it has changed.

Note, however, that the data from the GPS may fluctuate slightly on each read even if the unit has not moved. You might like to consider only putting it in the database if it has changed by a significant amount. Something like this

if abs( (newData - prevData) ) > 10)
  {
    //code to put the data in the database
  }

There is already a newdata variable in your code. What is that doing?

...R

thank you for reply
yes I also think that way...but the problem is I am not a good in C programming :roll_eyes:
How can I save previous data?

Robin2:
There is already a newdata variable in your code. What is that doing?

...R

I think its just new sensor data , it will be the same with previous , only sending time is different

35.3610, 139.2745
35.3610, 139.2745

Backy:
yes I also think that way…but the problem is I am not a good in C programming :roll_eyes:
How can I save previous data?

float prevFlat = flat;
float prevFlon =  flon;
unsigned long prevAge = age;
 
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);