1

What needed?

I need to obtain device/gateway current IP address to determine its location.

How to achieve this?

I found 2 options:

  1. Get a gateway IP address through Bluemix API because I see it in admin panel so decide it's available through API (but is can be not). But can’t find appropriate API call. Please, suggest one if it's implemented.
  2. In API response for device details, I saw additional location parameter, but can't find a full description how to use it. This parameter sends back with a links for logs and error codes. But on any API request, location parameter returns an empty string.

Can anyone help me with any of this options or propose another solution?

P.S. Current workaround is to send an IP address from the gateway directly, but it looks not the best possible option.

ValerieLampkin
  • 2,620
  • 13
  • 27
  • The location parameter in the API is for latitude and longitude, not for IP address. https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Devices/put_device_types_typeId_devices_deviceId_location – ValerieLampkin Nov 03 '16 at 21:10
  • Yes, this also a solution. But for any request here I've got an empty response as I mentioned in question. – Maxim Gordienok Nov 04 '16 at 14:49
  • I doubt that the location parameter gets populated in all the client/gateway code implementations. Maybe this is only working for a subset of the gateways. So going for a manual inclusion of the IP address into a message from the gateway seems to be a feasible solution – Romeo Kienzler Nov 06 '16 at 05:33
  • @RomeoKienzler no need for direct IP inclusion. So far Bluemix information about the gateway (IP address when the gateway appears online) if enough for us. – Maxim Gordienok Mar 25 '18 at 10:49
  • Perfect, thanks for the update – Romeo Kienzler Mar 31 '18 at 12:49

3 Answers3

2

There is no direct "give me the IP address of this device" API, but there are a few different sources of this information:

For the following, assume a device exists with type = "testDeviceType" and id = "testDeviceId" and org = "123456".

  1. The connection logs API

    GET /api/v0002/logs/connection?typeId=testDeviceType&deviceId=testDeviceId

    Response:

    [ { "timestamp": "2016-10-22T05:07:36.064Z", "message": "Closed connection from 127.0.0.1. The connection was closed by the client. Error=Connection timed out(110)" }, { "timestamp": "2016-10-22T03:59:36.182Z", "message": "Token auth succeeded: ClientID='d:123456:testDeviceType:testDeviceId', ClientIP=127.0.0.1" } ]

  2. Subscribing to the monitoring topic with an api key:

    topic = iot-2/type/+/id/+/mon

    Message Payload:

    RCV [iot-2/type/testDeviceType/id/testDeviceId/mon][retained] {"Action":"Connect","Time":"2016-11-01T14:18:36.550Z","ClientAddr":"127.0.0.1","ClientID":"d:123456:testDeviceType:testDeviceId","Port":8883,"Secure":true,"Protocol":"mqtt4","Durable":false }

  3. As mentioned in the question, it could always be specified in message payload but maybe there are some reasons not to trust this information being published by the device?

  4. The DeviceInfo field on devices includes a descriptive location field which is just a string and could technically be set to the IP address of a device... this might be a bit far-fetched though.

  5. Device geolocation can also be set over HTTP or by using the device management MQTT topics.

https://console.ng.bluemix.net/docs/services/IoT/devices/device_mgmt/index.html#update-location

{
    "d": {
        "longitude": number,
        "latitude": number,

        "elevation": number,
        "measuredDateTime": "string in ISO8601 format",
        "updatedDateTime": "string in ISO8601 format",
        "accuracy": number
    },
    "reqId": "string"
}

Another thing to keep in mind, since gateways are mentioned, is that the connection logs and monitoring topic mentioned in (1) and (2) are only relevant for devices which connect directly to the platform.

1

Call the connection logs api ... you'll find the IP address the device/gateway last connected from in there IIRC...

Alternatively, subscribe to the monitor topic over Mqtt and you can get the IP from the message that is available on that topic, for a device currently connected it'll be he current IP, for a device that previously connected it will be the last known IP address,for one that has never connected there will be no information available.

DavidParker
  • 358
  • 1
  • 5
  • I've tried `/diag/logs` API call also, but it sends an empty reply all the time. But another solution to subscribe to monitoring topic seems easier and more convenient for me. Thank you! – Maxim Gordienok Nov 08 '16 at 11:48
0

If your connected device has not published it's location you will not be able to receive anything. It is up to your application or your device's code to update its location. There is no automatic lookup of location based on IP.

For retrieving the IP of the connection you have 2 options:

  • Connection logs

https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Problem_Determination/get_logs_connection

Please bear in mind that messages in /mon/ topics might not be retained indefinitely.

  • Sure, I get. Thank you! Maybe you also have an example how to setup the device to send location information in an appropriate format to the Bluemix IoT? – Maxim Gordienok Nov 08 '16 at 11:52