linksmart / device-gateway

Process orchestrator and gateway between the low-level hardware access and HTTP/MQTT protocols.
Apache License 2.0
2 stars 0 forks source link

Registering Devices via REST #40

Open agtzdimi opened 5 years ago

agtzdimi commented 5 years ago

Hello,

Thank you for your work and the projects :) I have a question regarding the device-gateway.

My requirement is to register devices and keep them alive through the device-gateway on the fly. In this way while the service-catalog and device-gateway are running I can create separate MQTT topics to subscribe and publish.

For example: Currently it is possible to configure having an array of resources:

{
  "name": "MQTTSwitch",
  "description": "MQTT test switch service",
  "meta": {},
  "ttl": 120,
  "resources": [
    {
      "type": "Resource",
      "name": "Switch",
      "agent": {
        "type": "service",
        "dir": null,
        "exec": "agent-examples/mqtt-switch/switch.sh"
      },
      "representation": {},
      "protocols": [
        {
          "type": "MQTT",
          "methods": [
            "PUB",
            "SUB"
          ],
          "content-types": [
            "text/plain"
          ],
          "pub_topic": "/test/switch/pub",
          "sub_topic": "/test/switch/sub"
        },
        {
          "type": "REST",
          "methods": [
            "GET",
            "POST",
            "PUT"
          ],
          "content-types": [
            "text/plain"
          ]
        }
      ]
    },
    {
      "type": "Resource",
      "name": "Switch2",
      "agent": {
        "type": "service",
        "dir": null,
        "exec": "agent-examples/mqtt-switch/switch.sh"
      },
      "representation": {},
      "protocols": [
        {
          "type": "MQTT",
          "methods": [
            "PUB",
            "SUB"
          ],
          "content-types": [
            "text/plain"
          ],
          "pub_topic": "/test/switch/pub2",
          "sub_topic": "/test/switch/sub2"
        },
        {
          "type": "REST",
          "methods": [
            "GET",
            "POST",
            "PUT"
          ],
          "content-types": [
            "text/plain"
          ]
        }
      ]
    }
  ]
}

Is it possible to add multiple other resources entries after the start of the device-gateway?

farshidtz commented 5 years ago

Hi there,

I'm glad that you find this project interesting.

Resource configuration is currently possible only using config files. Dynamic configuration of devices has been a long lasting feature request (#34) but hasn't been added yet. We'll prioritize this issue and implement it in the following weeks.

For the time being, you can update the configuration file and restart device-gateway. It restarts very quickly and you won't lose MQTT messages because the QoS is set to 1.

agtzdimi commented 5 years ago

Thank you for your quick reply.

Another thing I would like to ask is about the publish topic. Is it feasible to publish the message to another IP rather than localhost?

Of course I can overcome this one by subscribing to the topic from the remote machine, but just in case I missed it in the config file

farshidtz commented 5 years ago

Yes of course, this is set in the main configuration file or retrieved from the Service Catalog.

agtzdimi commented 5 years ago

Well, my point is to have for example multiple resources, subscribing to 'localhost' and the first publish to 'IP1', the second one to 'IP2' etc. If I am correct the main config file is referring to one global MQTT broker right?

farshidtz commented 5 years ago

No, that's currently not possible but I can imagine the usefulness. Could you make a separate issue / feature request for that?

agtzdimi commented 5 years ago

Of course I will do it :)

Thank you