Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPS] Sent GPS data to LoRaWAN is corrupt when shown on display #1009

Closed
TD-er opened this issue Jun 9, 2024 · 0 comments · Fixed by #1011
Closed

[GPS] Sent GPS data to LoRaWAN is corrupt when shown on display #1009

TD-er opened this issue Jun 9, 2024 · 0 comments · Fixed by #1011

Comments

@TD-er
Copy link
Contributor

TD-er commented Jun 9, 2024

The function gps_storelocation(gpsStatus_t *gps_store) does check for .isUpdated(), but the updated flag is already reset while showing on the display. (push the button a few times to display GPS data)

This causes the gps_store data not to get updated and thus the random data of this struct (because it isn't initialized in the constructor) is sent to LoRa.

Proposal:
Change the function to return a bool:

bool gps_storelocation(gpsStatus_t *gps_store) {
  if (gps.location.isUpdated() && gps.location.isValid() &&
      (gps.location.age() < 1500)) {
    gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
    gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
    gps_store->satellites = (uint8_t)gps.satellites.value();
    gps_store->hdop = (uint16_t)gps.hdop.value();
    gps_store->altitude = (int16_t)gps.altitude.meters();
    return true;
  }
  return false;
}

And make sure to initialize the struct:

typedef struct {
  int32_t latitude{};
  int32_t longitude{};
  uint8_t satellites{};
  uint16_t hdop{};
  int16_t altitude{};
} gpsStatus_t;

Then in the 2 places where this function is called, check for its return value:

#if (HAS_GPS)
      if (GPSPORT == COUNTERPORT) {
        // send GPS position only if we have a fix
        if (gps_hasfix()) {
          if (gps_storelocation(&gps_status))
            payload.addGPS(gps_status);
        } else
          ESP_LOGD(TAG, "No valid GPS position");
      }
#endif
#if (HAS_GPS)
    case GPS_DATA:
      if (GPSPORT != COUNTERPORT) {
        // send GPS position only if we have a fix
        if (gps_hasfix()) {
          if (gps_storelocation(&gps_status)) {
            payload.reset();
            payload.addGPS(gps_status);
            SendPayload(GPSPORT);
          }
        } else
          ESP_LOGD(TAG, "No valid GPS position");
      }
      break;
#endif

This way, at least no bogus data is being sent to LoRa.

Tomorrow I will look into how we can read the GPS data without resetting the updated flag (or keep track of updated state elsewhere outside TinyGPS+)

TD-er added a commit to TD-er/ESP32-Paxcounter that referenced this issue Jun 11, 2024
cyberman54 added a commit that referenced this issue Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant