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

How to subscribe the IoTAgent to the MQTT Broker? #13

Closed diego-gv closed 5 years ago

diego-gv commented 5 years ago

How to subscribe the IoTAgent to the MQTT Broker?

I am searching in configuration files how to subscribe the IoTAgent to the MQTT Broker of LoraServer.io, but I don't found it.

Thank in advance!! :grinning: And I'm sorry for my english.

diego-gv commented 5 years ago

Hello!! Good morning!

I've been seeing that data stored in the MQTT broker, but the IoTA isn't informed.

I'm still waiting for an answer. Thank you!

dcalvoalonso commented 5 years ago

Hi,

Please find below an example of device provisioning for LoraServer.io:

{
  "devices": [
    {
      "device_id": "lora_n_003",
      "entity_name": "LORA-N-003",
      "entity_type": "LoraDevice",
      "timezone": "America/Santiago",
      "attributes": [
        {
          "object_id": "bp0",
          "name": "barometric_pressure_0",
          "type": "hpa"
        },
        {
          "object_id": "di3",
          "name": "digital_in_3",
          "type": "Number"
        },
        {
          "object_id": "do4",
          "name": "digital_out_4",
          "type": "Number"
        },  
        {
          "object_id": "rh2",
          "name": "relative_humidity_2",
          "type": "Number"
        }, 
        {
          "object_id": "t1",
          "name": "temperature_1",
          "type": "Number"
        }       
      ],
      "internal_attributes": {
        "lorawan": {
          "application_server": {
            "host": "localhost",
            "provider": "loraserver.io"
          },
          "dev_eui": "3339343752356A14",
          "app_eui": "70B3D57ED000985F",
          "application_id": "1",
          "application_key": "9BE6B8EF16415B5F6ED4FBEAFE695C49"
        }
      }
    }
  ]
}

As you can see, inside internal_attributes there are fields to specify the details needed to connect to the MQTT broker

diego-gv commented 5 years ago

That's right. I was looking a parameter like mongodb, and I was understanding that application_server referred to loraserver's ip, not the ip of mqtt broker.

Now, I've included the internal_attributes parameter as follows:

types: {
        LoraDevice: {
            service: 'weather',
            subservice: '/mini',
            internalAttributes: {
                lorawan: {
                    application_server: {
                        host: '192.168.1.66',
                        provider: 'loraserver.io'
                    },
                    application_id: '****',
                    app_eui: '*********************',
                    application_key: '*****************************'
                }
            }
        }
    }

But in the iotagent-lora log shows the following message:

iotagent-lora_1  | info: New message in topic application/****/node/***************/rx
iotagent-lora_1  | info: LoRaWAN device unprovisioned
iotagent-lora_1  | error:  name=DUPLICATE_DEVICE_ID, message=A device with the same pair (Service, DeviceId) was found:clon-miniweather, code=409
dcalvoalonso commented 5 years ago

Could you please share the result of doing a GET to /iot/devices and to /iot/services?

diego-gv commented 5 years ago

Of course...

Devices

{
    "count": 1,
    "devices": [
        {
            "device_id": "clon-miniweather",
            "service": "weather",
            "service_path": "/mini",
            "entity_name": "clon-miniweather:LoraDevice",
            "entity_type": "LoraDevice",
            "attributes": [
                {
                    "object_id": "relative_humidity",
                    "name": "relative_humidity",
                    "type": "Number"
                },
                {
                    "object_id": "temperature",
                    "name": "temperature",
                    "type": "Number"
                }
            ],
            "internal_attributes": {
                "lorawan": {
                    "application_server": {
                        "host": "192.168.1.66",
                        "username": "iota_lw",
                        "password": "250802hopu",
                        "provider": "loraserver.io"
                    },
                    "application_id": "****",
                    "app_eui": "*****************",
                    "application_key": "**********************************",
                    "data_model": "cayennelpp",
                    "dev_eui": "*****************"
                }
            }
        }
    ]
}

Services

{
    "name": "DEVICE_GROUP_NOT_FOUND",
    "message": "Couldn\t find device group for fields: weather and values: /mini"
}

This means that I need to create a group for this devices?

I forgot tell you that I'm using the static configuration for declare my types and I supposed it was implicit.

dcalvoalonso commented 5 years ago

I that case, you don't need to the device provisioning. The agent will automatically subscribe to the MQTT broker of the LoRaServer.io following your configuration file and devices will be provisioned automatically the first time data is received.

I suggest you clean your MongoDB DB and to try again.

diego-gv commented 5 years ago

I think I misexplained, I don't use a device provisioning. I use only a static configuration.

The agent will automatically subscribe to the MQTT broker of the LoRaServer.io following your configuration file and devices will be provisioned automatically the first time data is received.

Right, but when the IoTA receives new data, it tries to provision the device once again and fails because the device is already provisioned.

EDIT: I am following the process through Postman and there is no device provided before sending any data. After the first shipment the provisioning is created and after the second shipment fails in duplicate.

Equally I will try what you say.

dcalvoalonso commented 5 years ago

Have you achieved to solve this @garvi-x ?

diego-gv commented 5 years ago

Unfortunately I not achieve that the IoTAgent not to try to add the device every time the broker MQTT sends an update.

dcalvoalonso commented 5 years ago

Ok,I will review the integration with LoRaSever.io and let you know if I find any problem.

diego-gv commented 5 years ago

Ok, thank you Daniel

A little question, I have been thinking to add security through certificates TLS with the MQTT broker, but a code level the IoTAgent only permit configurating basic authentication (user + password). This is correct or exist other method?

EDIT: I have continued to see the implementation and I have seen how it is done to add TLS certificates. Since I need that feature for my job, I can implement it and contribute to it if you see it right.

diego-gv commented 5 years ago

Hello Daniel,

I forged your repository and designed a solution for my problem. If it's okay with you, you can validate (or not) my solution and I will collaborate with it.

Thank you for your help.

dcalvoalonso commented 5 years ago

@garvi-x Contributions are welcome!! :) Could you open a PR?

diego-gv commented 5 years ago

Of course! :))

diego-gv commented 5 years ago

Ok,I will review the integration with LoRaSever.io and let you know if I find any problem.

Any progress?

dcalvoalonso commented 5 years ago

Sorry @garvi-x but I am quite busy at this time. I will try to review the PR as soon as possible (hopefully next week)

diego-gv commented 5 years ago

Ok, no problem. It's not urgent so there's no rush. :))