

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Device Location MQTT トピックを使用した AWS IoT Core デバイスロケーションの解決
<a name="device-location-reserved-topics"></a>

リザーブド MQTT トピックを使用して、 Device Location 機能を使用して AWS IoT Core デバイスの最新の位置情報を取得できます。

## デバイスの位置情報 MQTT トピックの形式
<a name="device-location-topics-format"></a>

 AWS IoT Core Device Location の予約済みトピックでは、次のプレフィックスを使用します。

`$aws/device_location/{{{customer_device_id}}}/`

完全なトピックを作成するには、まず `{{customer_device_id}}` を、デバイスを識別するために使用する固有の ID に置き換えてください。for LoRaWAN デバイスや Sidewalk デバイス`WirelessDeviceId`などの を指定し、デバイスが AWS IoT モノとして登録されている場合は `{{thingName}}`を指定することをお勧めします。次に、以下のセクションに示すように、`get_position_estimate` または `get_position_estimate/accepted` などのトピックスタブをトピックに追加します。

**注記**  
`{{{customer_device_id}}}` に含むことができるのは、英文字、数字、およびダッシュのみです。デバイス位置トピックに登録する場合、プラス記号 (\+) をワイルドカードとして使用することのみが可能です。例えば、`{{{customer_device_id}}}` に対して `+` ワイルドカードを使用して、デバイスの位置情報を取得できます。トピック `$aws/device_location/{{+}}/get_position_estimate/accepted` にサブスクライブすると、正常に解決された場合、任意のデバイス ID と一致するデバイスの位置情報を含むメッセージが発行されます。

Device AWS IoT Core Location を操作するために使用される予約済みトピックを次に示します。


**デバイス位置 MQTT トピック**  

| Topic | 許可されている操作 | 説明 | 
| --- | --- | --- | 
| $aws/device\_location/{{customer\_device\_id}}/get\_position\_estimate | 発行 | デバイスは、このトピックに発行して、スキャンされた未加工の測定データを AWS IoT Core Device Location で解決します。 | 
| $aws/device\_location/{{customer\_device\_id}}/get\_position\_estimate/accepted | Subscribe | AWS IoT Core Device Location は、デバイスの位置が正常に解決されると、位置情報をこのトピックに発行します。 | 
| $aws/device\_location/{{customer\_device\_id}}/get\_position\_estimate/rejected | Subscribe | AWS IoT Core Device Location は、デバイスの場所の解決に失敗すると、エラー情報をこのトピックに発行します。 | 

## デバイスの位置情報 MQTT トピックのポリシー
<a name="device-location-topics-policy"></a>

デバイスの場所トピックからメッセージを受信するには、デバイスが AWS IoT デバイスゲートウェイに接続し、MQTT トピックをサブスクライブすることを許可するポリシーを使用する必要があります。

以下は、さまざまなトピックのメッセージを受信するために必要なポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iot:Publish"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topic/$aws/device_location/device-123/get_position_estimate"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iot:Receive"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topic/$aws/device_location/device-123/get_position_estimate/accepted",
                "arn:aws:iot:{{us-east-1}}:123456789012:topic/$aws/device_location/device-123/get_position_estimate/rejected"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iot:Subscribe"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topicfilter/$aws/device_location/device-123/get_position_estimate/accepted",
                "arn:aws:iot:{{us-east-1}}:123456789012:topicfilter/$aws/device_location/device-123/get_position_estimate/rejected"
            ]
        }
    ]
}
```

## デバイスの位置情報トピックとペイロード
<a name="device-location-topics-payload"></a>

Device AWS IoT Core Location トピック、メッセージペイロードの形式、各トピックのポリシー例を次に示します。

**Topics**
+ [/get\_position\_estimate](#get-position-estimate)
+ [/get\_position\_estimate/accepted](#get-position-estimate-accepted)
+ [/get\_position\_estimate/rejected](#get-position-estimate-rejected)

### /get\_position\_estimate
<a name="get-position-estimate"></a>

このトピックにメッセージを発行して、デバイスロケーションによって解決される未加工の測定データを AWS IoT Core デバイスから取得します。

```
$aws/device_location/{{customer_device_id}}/get_position_estimate
```

AWS IoT Core Device Location は、 [/get\_position\_estimate/accepted](#get-position-estimate-accepted)または に発行することで応答します[/get\_position\_estimate/rejected](#get-position-estimate-rejected)。

**注記**  
このトピックに発行されるメッセージは、有効な JSON ペイロードでなければなりません。入力メッセージが有効な JSON 形式でない場合、レスポンスは返されません。詳細については、「[メッセージペイロード](#get-position-estimate-payload)」を参照してください。

#### メッセージペイロード
<a name="get-position-estimate-payload"></a>

メッセージペイロード形式は、 AWS IoT Wireless API オペレーションリクエスト本文 と同様の構造に従います[https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetPositionEstimate.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_GetPositionEstimate.html)。以下を含みます。
+ 位置が解決された日時に対応するオプションの `Timestamp` 文字列。`Timestamp` 文字列の最小長は 1、最大長は 10 です。
+ リクエストをレスポンスにマッピングできる、オプションの `MessageId` 文字列。この文字列を指定すると、`get_position_estimate/accepted` または `get_position_estimate/rejected` トピックにパブリッシュされるメッセージにはこの `MessageId` が含まれます。`MessageID` 文字列の最小長は 1、最大長は 256 です。
+ 次の 1 つ以上の測定タイプを含む、デバイスからの測定データ。
  + [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_WiFiAccessPoint.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_WiFiAccessPoint.html)
  + [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CellTowers.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_CellTowers.html)
  + [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_Ip.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_Ip.html)
  + [https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_Gnss.html](https://docs.aws.amazon.com/iot-wireless/latest/apireference/API_Gnss.html)

以下は、メッセージペイロードのサンプルを示しています。

```
{
    "Timestamp": {{"1664313161"}},               
    "MessageId": {{"ABCD1"}},                
    "WiFiAccessPoints":  [                           
        {
            "MacAddress": "{{A0:EC:F9:1E:32:C1}}",                   
            "Rss": {{-66}} 
        }
    ],    
    "Ip":{
        "IpAddress": {{"54.192.168.0"}}                         
    },
    "Gnss":{
      "Payload":{{"8295A614A2029517F4F77C0A7823B161A6FC57E25183D96535E3689783F6CA48"}},
      "CaptureTime":{{1354393948}}
    }
}
```

#### ポリシーの例
<a name="get-position-estimate-policy"></a>

以下に示しているのは、必要なポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iot:Publish"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topic/$aws/device_location/device-123/get_position_estimate"
            ]
        }
    ]
}
```

### /get\_position\_estimate/accepted
<a name="get-position-estimate-accepted"></a>

AWS IoT Core Device Location は、デバイスの解決された位置情報を返すときに、このトピックへのレスポンスを発行します。位置情報は [GeoJSON 形式](https://geojson.org/)で返されます。

```
$aws/device_location/{{customer_device_id}}/get_position_estimate/accepted
```

次は、メッセージペイロードとポリシーの例を示しています。

#### メッセージペイロード
<a name="get-position-estimate-accepted-payload"></a>

次は、GeoJSON 形式のメッセージペイロードの例を示しています。raw 測定データ`MessageId`で を指定し、 AWS IoT Core Device Location が位置情報を正常に解決した場合、メッセージペイロードは同じ`MessageId`情報を返します。

```
{
    "coordinates": [
        13.37704086303711,
        52.51865005493164
    ],
    "type": "Point",
    "properties": {
        "verticalAccuracy": 707,
        "verticalConfidenceLevel": 0.68,
        "horizontalAccuracy": 389,
        "horizontalConfidenceLevel": 0.68,
        "country": "USA",
        "state": "CA",
        "city": "Sunnyvalue",
        "postalCode": "91234",        
        "timestamp": "2022-11-18T14:03:57.391Z",
        "messageId": "ABCD1"
    }
}
```

#### ポリシーの例
<a name="get-position-estimate-accepted-policy"></a>

以下に示しているのは、必要なポリシーの例です。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iot:Subscribe"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topicfilter/$aws/device_location/device-123/get_position_estimate/accepted"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iot:Receive"
            ],
            "Resource": [
                "arn:aws:iot:{{us-east-1}}:123456789012:topic/$aws/device_location/device-123/get_position_estimate/accepted"
            ]
        }
    ]
}
```

### /get\_position\_estimate/rejected
<a name="get-position-estimate-rejected"></a>

AWS IoT Core Device Location は、デバイスの場所の解決に失敗すると、このトピックにエラーレスポンスを発行します。

```
$aws/device_location/{{customer_device_id}}/get_position_estimate/rejected
```

次は、メッセージペイロードとポリシーの例を示しています。これらのエラーの詳細については、「[位置の解決時のトラブルシューティング](device-location-resolve-solvers.md#location-resolve-troubleshoot)」を参照してください。

#### メッセージペイロード
<a name="get-position-estimate-rejected-payload"></a>

以下は、エラーコードとメッセージを提供するメッセージペイロードの例です。これは、 AWS IoT Core Device Location が位置情報の解決に失敗した理由を示しています。raw 測定データを提供する`MessageId`ときに を指定し、 AWS IoT Core Device Location が位置情報を解決できなかった場合、メッセージペイロードに同じ`MessageId`情報が返されます。

```
{
    "errorCode": 500,
    "errorMessage":"Internal server error",
    "messageId": "ABCD1"
}
```

#### ポリシーの例
<a name="get-position-estimate-rejected-policy"></a>

以下に示しているのは、必要なポリシーの例です。

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Subscribe"
      ],
      "Resource": [
        "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/device_location/device-123/get_position_estimate/rejected"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:us-east-1:123456789012:topic/$aws/device_location/device-123/get_position_estimate/rejected"
      ]
    }
  ]
}
```