Bjoerns-TB / M5Stack-LoRaWAN-Network-Tester

A LoRaWAN Network Tester based on the M5Stack, compatible with TTN
MIT License
21 stars 6 forks source link

GPS Data : height #5

Closed FrankUlbrich closed 4 years ago

FrankUlbrich commented 4 years ago

{ "altitude": -19436, "hdop": 2.2, "latitude": 11.835103144353809, "longitude": 29.48182400952723 }

Hello Björn, I get false altitude in TTN from the network tester. I will try to dig out the problem.

M5StackFire with GPS Shield (Serial Pins changed) I am using this library: TinyGPSPlus-1.0.2

Bjoerns-TB commented 4 years ago

Hi Frank,

at first i would check with the GPS example sketch if you get the correct readings there. Next i would check what the sketch reads:

insert Serial.println(alt); in thegpsdata() function.

Now you will get the altitude on the serial monitor.

FrankUlbrich commented 4 years ago

I added a print output to the sketch:

//Write GPS-Data into variables
void gpsdata() {
  year = gps.date.year();
  month = gps.date.month();
  day = gps.date.day();
  hour = gps.time.hour();
  minute = gps.time.minute();
  second = gps.time.second();
  latitude = gps.location.lat();
  longitude = gps.location.lng();
  alt = gps.altitude.meters();
  hdop = gps.hdop.value();
  Serial.println(F("---------------"));
  Serial.print(F("GPS altitude: "));
  Serial.println(alt);
  Serial.print(F("GPS latitude: "));
  Serial.println(latitude);
  Serial.print(F("GPS longitude: "));
  Serial.println(longitude);
}

#

And I get the following Output , which looks OK. These are my Coordinates. It is nearly the same data which I have on the SD Card in the json / gpx logging. ----- Serial Output:

16:02:58.978 -> --------------- 16:02:58.978 -> GPS altitude: 39.70 16:02:58.978 -> GPS latitude: 51.34 16:02:58.978 -> GPS longitude: 6.34 16:02:59.215 -> --------------- 16:02:59.215 -> GPS altitude: 39.50 16:02:59.215 -> GPS latitude: 51.34 16:02:59.215 -> GPS longitude: 6.34 16:02:59.250 -> --------------- 16:02:59.250 -> GPS altitude: 39.50 16:02:59.250 -> GPS latitude: 51.34 16:02:59.250 -> GPS longitude: 6.34 16:02:59.453 -> --------------- 16:02:59.453 -> GPS altitude: 39.50 16:02:59.453 -> GPS latitude: 51.34 16:02:59.453 -> GPS longitude: 6.34 16:02:59.487 -> --------------- 16:02:59.487 -> GPS altitude: 39.50 16:02:59.487 -> GPS latitude: 51.34 16:02:59.487 -> GPS longitude: 6.34 16:02:59.725 -> --------------- 16:02:59.725 -> GPS altitude: 39.50 16:02:59.725 -> GPS latitude: 51.34 16:02:59.725 -> GPS longitude: 6.34 16:02:59.725 -> --------------- 16:02:59.725 -> GPS altitude: 39.50 16:02:59.725 -> GPS latitude: 51.34 16:02:59.725 -> GPS longitude: 6.34

FrankUlbrich commented 4 years ago

The data send to the TTN does look different.

{
  "altitude": -29681,
  "hdop": 2.7,
  "latitude": 12.538228186263325,
  "longitude": 32.294324177165294
}

Metadata

{
  "time": "2020-06-28T14:02:51.78422952Z",
  "frequency": 867.5,
  "modulation": "LORA",
  "data_rate": "SF7BW125",
  "coding_rate": "4/5",
  "gateways": [
    {
      "gtw_id": "eui-b827ebfffe164cc5",
      "timestamp": 231041092,
      "time": "2020-06-28T14:02:50.755622Z",
      "channel": 5,
      "rssi": -73,
      "snr": 7.8,
      "latitude": 51.34248,
      "longitude": 6.33836,
      "altitude": 39
    }
  ]
}

I guess the Upload Function may not work properly.

FrankUlbrich commented 4 years ago

Hi maybe my problem is, that I have an TTN Mapper decoder in place.

function Decoder(bytes, port) {
    var decoded = {};

    decoded.latitude = ((bytes[0]<<16)>>>0) + ((bytes[1]<<8)>>>0) + bytes[2];
    decoded.latitude = (decoded.latitude / 16777215.0 * 180) - 90;

    decoded.longitude = ((bytes[3]<<16)>>>0) + ((bytes[4]<<8)>>>0) + bytes[5];
    decoded.longitude = (decoded.longitude / 16777215.0 * 360) - 180;

    var altValue = ((bytes[6]<<8)>>>0) + bytes[7];
    var sign = bytes[6] & (1 << 7);
    if(sign)
    {
        decoded.altitude = 0xFFFF0000 | altValue;
    }
    else
    {
        decoded.altitude = altValue;
    }

    decoded.hdop = bytes[8] / 10.0;

    return decoded;
} 
Bjoerns-TB commented 4 years ago

OMG,

i just realized that i didn‘t attach a propper payload decoder.

Sorry for that. Here is the right one, also compatible with the TTN Mapper:

function Decoder(b, port) {

  var lat = (b[0] | b[1]<<8 | b[2]<<16 | (b[2] & 0x80 ? 0xFF<<24 : 0)) / 10000;
  var lon = (b[3] | b[4]<<8 | b[5]<<16 | (b[5] & 0x80 ? 0xFF<<24 : 0)) / 10000;
  var alt = (b[6] | b[7]<<8 | (b[7] & 0x80 ? 0xFF<<16 : 0)) / 100;
  var hdop = b[8] / 10;

  return {

      latitude: lat,
      longitude: lon,
      altitude: alt,
      hdop: hdop

  };
}
FrankUlbrich commented 4 years ago

Hallo Bjoern, einen Gruß nach Köln. Im moment teste ich gerade die Kodierung , welche Du im https://github.com/Bjoerns-TB/ttn-gps-tracker/blob/master/source/tracker.ino genommen hast. Ich denke, ich werde die Änderungen wieder rückgängig machen und bei Deinem Originalcode bleiben. Jetzt weiß ich ja, wie der zugehörigen Decoder aussieht.

Vielen Dank für die schnelle Antwort.

I found some code in your repository https://github.com/Bjoerns-TB/ttn-gps-tracker/blob/master/source/tracker.ino which is compatible to my TTN T-Beam software and the decoder- I added this to the source code. It works well. So I guess I should close this issue, because it was my fault. Your code is fine.

Next I will undo the changes in my modified code and use your decoder, mentioned above to be complient with your code and development. Thanks a lot for your very quick answer.

FrankUlbrich commented 4 years ago

Thanks a lot for your support.