Atos-Research-and-Innovation / IoTagent-LoRaWAN

FIWARE IoT Agent for LoRaWAN protocol (with CayenneLpp and CBOR data models)
https://fiware-lorawan.readthedocs.io/en/latest/
Other
34 stars 40 forks source link

LoraServer.io + cayennelpp flow, empty measure on Orion #70

Closed filgiuff closed 5 years ago

filgiuff commented 5 years ago

I installed the loraserver.io architecture and registered a real device, it sends measures and I see them subscribing to all topics of the MQTT broker.

Considering an application with name hCfjWFtMwX8l38x and loraServer id = 4 and a device with a DevEUI 17446f057c1054a1, I have these measures on this topic application/4/device/17446f057c1054a1/rx

{
  "applicationID" : "4",
  "applicationName" : "hCfjWFtMwX8l38x",
  "deviceName" : "17446f057c1054a1",
  "devEUI" : "17446f057c1054a1",
  "txInfo" : {
    "frequency" : 868100000,
    "dr" : 0
  },
  "adr" : true,
  "fCnt" : 0,
  "fPort" : 3,
  "data" : "AWcBEAJzKewEZQP6A4gH/dgAvuEAAMg=",
  "object" : {
    "illuminanceSensor" : {
      "4" : 1018
    },
    "temperatureSensor" : {
      "1" : 27.2
    },
    "barometer" : {
      "2" : 1073.2
    },
    "gpsLocation" : {
      "3" : {
        "latitude" : 52.3736,
        "longitude" : 4.8865,
        "altitude" : 2
      }
    }
  }
}

I've tried to do the provisioning of this device on the IoTagent-LoRaWAN:

{
    "devices": [
        {
            "device_id": "17446f057c1054a1",
            "service": "test",
            "service_path": "/test_issues",
            "entity_name": "17446f057c1054a1",
            "entity_type": "Device",
            "transport": "LORA",
            "attributes": [
                {
                    "object_id": "barometer",
                    "name": "barometer",
                    "type": "number"
                },
                {
                    "object_id": "barometer_2",
                    "name": "barometer_2",
                    "type": "number"
                }
            ],
            "lazy": [],
            "commands": [],
            "static_attributes": [
                {
                    "name": "location",
                    "type": "geo:point",
                    "value": "13.265,37.499444"
                },
                {
                    "name": "transport_protocol",
                    "type": "Text",
                    "value": "LORA"
                },
                {
                    "name": "dataformat_protocol",
                    "type": "Text",
                    "value": "CAYENNELPP"
                },
                {
                    "name": "opType",
                    "type": "Text",
                    "value": "pending"
                },
                {
                    "name": "organization",
                    "type": "Text",
                    "value": "8129657f-2bfb-46c9-a211-060816f514de"
                },
                {
                    "name": "device_owner",
                    "type": "Text",
                    "value": "7da190b8-6373-45a3-b95a-d3601ac8a2c9"
                },
                {
                    "name": "screenId",
                    "type": "Text",
                    "value": "17446f057c1054a1"
                },
                {
                    "name": "mobile_device",
                    "type": "Text",
                    "value": "false"
                },
                {
                    "name": "retrieve_data_mode",
                    "type": "Text",
                    "value": "push"
                },
                {
                    "name": "loraStack",
                    "type": "Text",
                    "value": "LORASERVER"
                },
                {
                    "name": "dateModified",
                    "type": "DateTime",
                    "value": "2019-06-07T10:19:35.00Z"
                },
                {
                    "name": "loraDeviceProfileId",
                    "type": "Text",
                    "value": "cbe12593-d29a-4fa2-ba46-4b993b9cad26"
                }
            ],
            "internal_attributes": {
                "lorawan": {
                    "application_server": {
                        "host": "XXX.XXX.XXX.XXX:8090",
                        "provider": "TTN"
                    },
                    "app_eui": "0000000000000000",
                    "application_id": "4",
                    "application_key": "2a65089d5c205645be0d6f17299dbae6",
                    "data_model": "cayennelpp",
                    "dev_eui": "17446f057c1054a1"
                }
            },
            "protocol": "CAYENNELPP"
        }
    ]
}

it creates the entity on Orion and these messages about Mqtt topic subscription appears on the agent log:

iotstack_iotagent-lora.1.7i4vzdne2sjd@xerus-1    | {"timestamp":"2019-06-07T13:53:00.179Z","level":"info","message":"Subscribing to MQTT topic:4/devices/17446f057c1054a1/up"}
iotstack_iotagent-lora.1.7i4vzdne2sjd@xerus-1    | {"timestamp":"2019-06-07T13:53:00.179Z","level":"info","message":"Mqtt topic subscribed:4/devices/17446f057c1054a1/up"}

after other logs:

iotstack_iotagent-lora.1.7i4vzdne2sjd@xerus-1    | time=2019-06-07T13:53:00.219Z | lvl=DEBUG | corr=d81623db-55ef-4976-858c-9f81634aadbb | trans=d81623db-55ef-4976-858c-9f81634aadbb | op=IoTAgentNGSI.DeviceProvisioning | srv=n/a | subsrv=n/a | msg=Device provisioning request succeeded | comp=IoTAgent

The entity on Orion is created correctly, but the value of the measure is empty

{
    "id": "17446f057c1054a1",
    "type": "Device",
    "TimeInstant": {
        "type": "ISO8601",
        "value": " ",
        "metadata": {}
    },
    "barometer": {
        "type": "number",
        "value": " ",
        "metadata": {}
    },
    "barometer_2": {
        "type": "number",
        "value": " ",
        "metadata": {}
    },
    "dataformat_protocol": {
        "type": "Text",
        "value": "CAYENNELPP",
        "metadata": {}
    },
    "dateModified": {
        "type": "DateTime",
        "value": "2019-06-07T10:19:35.00Z",
        "metadata": {}
    },
    "device_owner": {
        "type": "Text",
        "value": "7da190b8-6373-45a3-b95a-d3601ac8a2c9",
        "metadata": {}
    },
    "location": {
        "type": "geo:point",
        "value": "13.265,37.499444",
        "metadata": {}
    },
    "loraDeviceProfileId": {
        "type": "Text",
        "value": "cbe12593-d29a-4fa2-ba46-4b993b9cad26",
        "metadata": {}
    },
    "loraStack": {
        "type": "Text",
        "value": "LORASERVER",
        "metadata": {}
    },
    "mobile_device": {
        "type": "Text",
        "value": "false",
        "metadata": {}
    },
    "opType": {
        "type": "Text",
        "value": "pending",
        "metadata": {}
    },
    "organization": {
        "type": "Text",
        "value": "8129657f-2bfb-46c9-a211-060816f514de",
        "metadata": {}
    },
    "retrieve_data_mode": {
        "type": "Text",
        "value": "push",
        "metadata": {}
    },
    "screenId": {
        "type": "Text",
        "value": "17446f057c1054a1",
        "metadata": {}
    },
    "transport_protocol": {
        "type": "Text",
        "value": "LORA",
        "metadata": {}
    }
}

As you can see I've tried both barometer and barometer_2 as parameters.

Note that the topic where the measures arrive application/4/device/17446f057c1054a1/rx is different than the subscribed topic shown on the log message 4/devices/17446f057c1054a1/up

I also tried to change

but in any cases the result was always the same.

Did I any mistake or is there any issue on the agent ?

Full log attached

dcalvoalonso commented 5 years ago

Could you please include the log of the LoRaServer.io application server where the messages published in the MQTT topics can be seen? Please check https://www.loraserver.io/guides/troubleshooting/application-server/ in order to see what we expect, something like:

INFO[0186] handler/mqtt: publishing message              qos=0 topic=application/1/device/0101010101010101/rx
INFO[0186] finished unary call with code OK              grpc.code=OK grpc.method=HandleUplinkData grpc.request.deadline="2018-09-24T10:54:37+02:00" grpc.service=as.ApplicationServerService grpc.start_time="2018-09-24T10:54:36+02:00" grpc.time_ms=6.989 peer.address="[::1]:63536" span.kind=server system=grpc
dcalvoalonso commented 5 years ago

We would need also to know which version of LoRaServer.io you are using.

filgiuff commented 5 years ago

Attached a piece of docker-compose logs about Lora components, including the LoRaServer.io application server.

I found some messages similar to the info you wrote (note "integration/mqtt" instead of "handler/mqtt")

... appserver_1 | time="2019-06-03T15:47:00Z" level=info msg="device-activation created" dev_eui=17446f057c1054a1 id=47 appserver_1 | time="2019-06-03T15:47:00Z" level=info msg="integration/mqtt: publishing message" qos=0 topic=application/4/device/17446f057c1054a1/join appserver_1 | time="2019-06-03T15:47:00Z" level=info msg="finished unary call with code OK" grpc.code=OK grpc.method=HandleUplinkData grpc.request.deadline="2019-06-03T15:47:01Z" grpc.service=as.ApplicationServerService grpc.start_time="2019-06-03T15:47:00Z" grpc.time_ms=214.142 peer.address="172.19.0.8:51134" span.kind=server system=grpc appserver_1 | time="2019-06-03T15:47:00Z" level=info msg="integration/mqtt: publishing message" qos=0 topic=application/4/device/17446f057c1054a1/rx ...

We are using version 2.8.1.

LoraDockerComposeLog.zip

dcalvoalonso commented 5 years ago

Hi,

There are several problems in your setup:

  1. It seems that LoRaServer has changed the MQTT topics after release v1.0.0 as you can see in https://www.loraserver.io/lora-app-server/integrate/sending-receiving/. The LoRaWAN IoT Agent was developed before this change and therefore was not compatible with newer versions.
  2. In the device provisioning, you must include the application server you are using. By default, the agent considers TTN:
    {
    "devices": [{
        "device_id": "17446f057c1054a1",
        "service": "test",
        "service_path": "/test_issues",
        "entity_name": "17446f057c1054a1",
        "entity_type": "Device",
        "transport": "LORA",
        "attributes": [{
                "object_id": "barometric_pressure_2",
                "name": "barometric_pressure_2",
                "type": "number"
            }
        ],
        "lazy": [],
        "commands": [],
        "static_attributes": [{
                "name": "location",
                "type": "geo:point",
                "value": "13.265,37.499444"
            },
            {
                "name": "transport_protocol",
                "type": "Text",
                "value": "LORA"
            },
            {
                "name": "dataformat_protocol",
                "type": "Text",
                "value": "CAYENNELPP"
            },
            {
                "name": "opType",
                "type": "Text",
                "value": "pending"
            },
            {
                "name": "organization",
                "type": "Text",
                "value": "8129657f-2bfb-46c9-a211-060816f514de"
            },
            {
                "name": "device_owner",
                "type": "Text",
                "value": "7da190b8-6373-45a3-b95a-d3601ac8a2c9"
            },
            {
                "name": "screenId",
                "type": "Text",
                "value": "17446f057c1054a1"
            },
            {
                "name": "mobile_device",
                "type": "Text",
                "value": "false"
            },
            {
                "name": "retrieve_data_mode",
                "type": "Text",
                "value": "push"
            },
            {
                "name": "loraStack",
                "type": "Text",
                "value": "LORASERVER"
            },
            {
                "name": "dateModified",
                "type": "DateTime",
                "value": "2019-06-07T10:19:35.00Z"
            },
            {
                "name": "loraDeviceProfileId",
                "type": "Text",
                "value": "cbe12593-d29a-4fa2-ba46-4b993b9cad26"
            }
        ],
        "internal_attributes": {
            "lorawan": {
                "application_server": {
                                        "host": "XXX.XXX.XXX.XXX:8090",
                    "provider": "loraserver.io"
                },
                "app_eui": "0000000000000000",
                "application_id": "4",
                "application_key": "2a65089d5c205645be0d6f17299dbae6",
                "data_model": "cayennelpp",
                "dev_eui": "17446f057c1054a1"
            }
        }
    }]
    }
  3. In the device provisioning, the attributes must have a name following a specific convention. I have created a new doc to reflect this: https://github.com/Atos-Research-and-Innovation/IoTagent-LoRaWAN/blob/master/docs/data_models.md

All these changes have been merged. In order to try again, please clean all the previously registered devices in the IoT Agent.

filgiuff commented 5 years ago

I've tested this new version and it works fine. About your points:

  1. Good! It was a big bug.
  2. I've noticed that if I use "provider": "loraserver.io" or "provider": "TTN" it works the same
  3. Including this on the documentation is very useful. Now it would be important to have a similar documentation about CBOR. Thank you for your support!
filgiuff commented 5 years ago

About that I wrote in the previous post at 2). I've just noticed that it just works in an old instance, if I create a new instance of the agent it needs "provider": "loraserver.io" for LoRaServer and "provider": "TTN" for The Things Network.

In the first instance, something probably got dirty in the db.

dcalvoalonso commented 5 years ago

Great! Then we can close this issue. :)