沒有直接「給我這個設備的IP地址」的API,但也有此信息的幾個不同的來源:
對於以下,假設設備與type = "testDeviceType"
和id = "testDeviceId"
和org = "123456"
存在。
連接日誌API
GET /api/v0002/logs/connection?typeId=testDeviceType&deviceId=testDeviceId
響應:
[ { "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" } ]
訂閱監測話題API密鑰:
topic = iot-2/type/+/id/+/mon
消息有效負荷:
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 }
正如在問題中提到,它總是可以在消息負載規定,但也許有一些理由不相信這個信息通過設備的問世?
設備上的DeviceInfo字段包含一個descriptive location
字段,它只是一個字符串,可以在技術上設置爲設備的IP地址......這可能有點牽強。
設備的地理定位,也可設置通過HTTP或通過使用設備管理MQTT主題。
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"
}
另一件事要記住,因爲網關被提及,是中提到的連接日誌和監視主題(1)和(2)僅適用於設備相關的這直接連接到平臺。
API中的location參數是緯度和經度,而不是IP地址。 https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Devices/put_device_types_typeId_devices_deviceId_location – ValerieLampkin
是的,這也是一個解決方案。但是,對於這裏的任何要求,我已經得到了空談,正如我提到的那樣。 –
我懷疑位置參數在所有的客戶端/網關代碼實現中被填充。也許這隻適用於網關的一個子集。因此,從網關手動包含IP地址到消息似乎是一個可行的解決方案 –