

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 取得 OTA 失敗代碼 AWS CLI
<a name="ota-failure-codes"></a>

1. 安裝及設定 [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)。

1. 執行 `aws configure`並輸入下列資訊。

   ```
   $ aws configure
   AWS Access Key ID [None]: {{AccessID}}
   AWS Secret Access Key [None]: {{AccessKey}}
   Default region name [None]: {{Region}}
   Default output format [None]: json
   ```

   如需詳細資訊，請參閱[使用 進行快速組態`aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config)。

1. 執行：

   ```
   aws iot describe-job-execution --job-id {{JobID}} --thing-name {{ThingName}}
   ```

   其中 {{JobID}} 是我們想要取得狀態之任務的完整任務 ID 字串 （它在建立時與 OTA 更新任務相關聯），而 {{ThingName}} 是裝置在 中註冊為 的 AWS IoT 物件名稱 AWS IoT

1. 輸出看起來像這樣：

   ```
   {
       "execution": {
           "jobId": "AFR_OTA-****************",
           "status": "FAILED",
           "statusDetails": {
               "detailsMap": {
                   "reason": "{{0xEEEEEEEE: 0xffffffff}}"
               }
           },
           "thingArn": "arn:aws:iot:{{Region}}:{{AccountID}}:thing/{{ThingName}}",
           "queuedAt": 1569519049.9,
           "startedAt": 1569519052.226,
           "lastUpdatedAt": 1569519052.226,
           "executionNumber": 1,
           "versionNumber": 2
       }
   }
   ```

   在此範例輸出中，「`detailsmap`」中的「`reason`」有兩個欄位：顯示為「0xEEEEEEEE」的欄位包含 OTA 代理程式的一般錯誤碼；顯示為「0xffffffff」的欄位則包含子代碼。一般錯誤碼列在 [https://docs.aws.amazon.com/freertos/latest/lib-ref/html1/aws\_\_ota\_\_agent\_8h.html](https://docs.aws.amazon.com/freertos/latest/lib-ref/html1/aws__ota__agent_8h.html)。請參閱前綴為 "`kOTA_Err_`” 的錯誤代碼。子代碼可以是平台專用代碼，也可以提供一般錯誤的詳細資訊。