TheThingsArchive / java-app-sdk

The Things Network Application SDK for Java
MIT License
30 stars 25 forks source link

Unrecognized field "app_id" #46

Closed KMax closed 7 years ago

KMax commented 7 years ago

I tried to run the samples-mqtt, it connects to the MQTT broker, but when an uplink message received, it throws an error:

error: Unrecognized field "app_id" (class org.thethingsnetwork.data.common.messages.UplinkMessage), not marked as ignorable (5 known properties: "port", "payload_fields", "counter", "payload_raw", "metadata"])
 at [Source: [B@cf1e768; line: 1, column: 12] (through reference chain: org.thethingsnetwork.data.common.messages.UplinkMessage["app_id"])

As I understand the problem in the mapping of a JSON message in an UplinkMessage instance.

KMax commented 7 years ago

Is there a good reason UplinkMessage doesn't have the app_id, dev_id fields? i can send a pull request with the changes (will add the missing fields), if there is no a good reason to ignore these fields.

@cambierr What do you say?

cambierr commented 7 years ago

I'll do the change now in the 2.1.1 branch ;-) Those fields will be added. The UplinkMessage class was based on a now old version of the MQTT API

cambierr commented 7 years ago

So, i fixed this and added those fields in UplinkMessage. To face eventual new API changes I added some relaxed deserialization to jackson

cambierr commented 7 years ago

@KMax @martinbeentjes I did some testing but feel free to test more stuff before we release 2.1.1 :)

KMax commented 7 years ago

@cambierr Okay, but what about Metadata.Gateway class, it also misses several fields? Did it work in your set up?

cambierr commented 7 years ago

Well, from the tests I just ran, everything is fine.

The java sdk is conform to the API specs at https://www.thethingsnetwork.org/docs/applications/mqtt/api.html

KMax commented 7 years ago

To face eventual new API changes I added some relaxed deserialization to jackson

Ohh, okay. Then it should work even if Metdata.Gateway class doesn't have some fields.

Okay, but what about Metadata.Gateway class, it also misses several fields?

At least the id field in Metadat.Gateway is gtw_id in the message, so @JsonProperty("gtw_id") should be added for the field, I guess.

Here is the message i receive:

{
  "app_id":"testspb",
  "dev_id":"testdevice-aaaaaaaaaaaaaaaa",
  "hardware_serial":"AAAAAAAAAAAAAAAA",
  "port":1,
  "counter":647,
  "payload_raw":"eyJ0IjoiOTkuNSIsImgiOiI5OS41In0AAAAAAAA=",
  "metadata": {
    "time":"2017-02-22T07:59:19.96654609Z",
    "frequency":868.1,
    "modulation":"LORA",
    "data_rate":"SF7BW125",
    "coding_rate":"4/5",
    "gateways": [
      {
        "gtw_id":"eui-b827ebfffeaa9967",
        "timestamp":1391443707,
        "time":"2017-02-22T07:59:19.943604Z",
        "channel":0,
        "rssi":-21,
        "snr":8.5,
        "rf_chain":1,
        "latitude":59.95694,
        "longitude":30.30834,
        "altitude": 69
       }
     ]
   }
}

Looks like the API spec is not up-to-date.

cambierr commented 7 years ago

You are right. I just fixed gtw_id, longitude, altitude, and latitude ! From now on I will more focus on actual data received and less on the API doc :)

KMax commented 7 years ago

The last thing is the is_retry field which you added in the first commit, it doesn't exist in the actual uplink message :)

Everything else looks fine for me and works on my side.

cambierr commented 7 years ago

it's in the API specs. @johanstokking any info about this field ?

johanstokking commented 7 years ago

@cambierr it's here: https://github.com/thethingsnetwork/ttn/tree/master/mqtt. Also note the line just below, saying that fields can be omitted when they're default or empty.

johanstokking commented 7 years ago

Ah, the master seems behind on docs, this is the one: https://github.com/thethingsnetwork/ttn/tree/develop/mqtt

This will be fixed asap