Skip to content

Internal "use application fromatter" couts gps sats wrong on ttnmapper webhook #116

Description

@g6094199

dont know where to put it, so feel free to move the report

Summary

when sending gps data for mapping the sat count is always 198, despite the real count

Environment

  • use preset ttn mapper webhook

Steps to Reproduce

send data like so:

txBuffer[0] = (LatitudeBinary >> 16) & 0xFF;
txBuffer[1] = (LatitudeBinary >> 8) & 0xFF;
txBuffer[2] = LatitudeBinary & 0xFF;

txBuffer[3] = (LongitudeBinary >> 16) & 0xFF;
txBuffer[4] = (LongitudeBinary >> 8) & 0xFF;
txBuffer[5] = LongitudeBinary & 0xFF;

altitudeGps = altitude;
txBuffer[6] = (altitudeGps >> 8) & 0xFF;
txBuffer[7] = altitudeGps & 0xFF;

hdopGps = hdop / 10;
//Serial.println(hdopGps);
txBuffer[8] = hdopGps & 0xFF;
// also sent satellite count
txBuffer[9] = sats & 0xFF;

What do you see now?

"uplink_message": {
  "session_key_id": "AZ/cpTP6NTzNw==",
  "f_port": 1,
  "f_cnt": 3,
  "frm_payload": "xu2AM0hAw==",
  "decoded_payload": {
    "altitude": 205,
    "hdop": 3.3,
    "latitude": 4.7310121,
    "longitude": 9..926,
    "sats": 198
  },

What do you want to see instead?

when i add my custon made decoder :

function decodeUplink(input) {
var bytes = input.bytes;
var errors = [];

// Sicherheits-Check: Hat das Paket wirklich die erwarteten 10 Bytes?
if (bytes.length !== 10) {
return {
errors: ["Ungültige Paketlänge: Erwartet 10 Bytes, erhalten " + bytes.length]
};
}

// 1. Unsigned 24-Bit Integer für Latitude zusammensetzen (Bytes 0, 1, 2)
var latBin = ((bytes[0] << 16) | (bytes[1] << 8) | bytes[2]) >>> 0;
// Rückberechnung laut Arduino-Formel: ((val / 16777215) * 180) - 90
var lat = (latBin / 16777215.0) * 180.0 - 90.0;

// 2. Unsigned 24-Bit Integer für Longitude zusammensetzen (Bytes 3, 4, 5)
var lonBin = ((bytes[3] << 16) | (bytes[4] << 8) | bytes[5]) >>> 0;
// Rückberechnung laut Arduino-Formel: ((val / 16777215) * 360) - 180
var lon = (lonBin / 16777215.0) * 360.0 - 180.0;

// 3. Altitude (Höhe) extrahieren (Bytes 6, 7)
var alt = (bytes[6] << 8) | bytes[7];

// 4. HDOP extrahieren (Byte 8) und zurückskalieren
var hdopValue = bytes[8] / 10.0;

// 5. Satellitenanzahl extrahieren (Byte 9)
var satsCount = bytes[9];

// Plausibilitäts-Check: Koordinaten von genau 0.0000/0.0000 abfangen
if (latBin === 0 && lonBin === 0) {
errors.push("GPS-Modul hat noch keinen gültigen Fix (0.0/0.0 empfangen)");
}

// Berechnete Schätzung für 'accuracy' in Metern (HDOP * 5)
var accuracyMeters = Math.round(hdopValue * 5.0 * 10) / 10;

return {
data: {
latitude: Math.round(lat * 1000000) / 1000000, // Auf 6 Nachkommastellen runden
longitude: Math.round(lon * 1000000) / 1000000, // Auf 6 Nachkommastellen runden
altitude: alt,
hdop: hdopValue,
sats: satsCount,
accuracy: accuracyMeters
},
warnings: errors.length > 0 ? errors : undefined
};
}

its working:

"received_at": "2026-08-07T14:23:21.794469078Z",
"uplink_message": {
  "session_key_id": "AZ/dgsfdgsfdg==",
  "f_port": 1,
  "frm_payload": "sfsgsfdgsfdg==",
  "decoded_payload": {
    "accuracy": 37.5,
    "altitude": 152,
    "hdop": 7.5,
    "latitude": 4.275,
    "longitude": 5.47,
    "sats": 4
  },

How do you propose to implement this?

so there seems to be a bug in the ttn decoder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs/triageWe still need to triage this

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions