6.1.7.1 Building and Running the OTA Demo

Building the Application

To build this application, open the project file (wireless_apps_rnwf\apps\ota_demo\firmware\azure_ota_demo_sam_e54_xpro_wincs02.X) in MPLAB X IDE. For more details on opening the project file in MPLAB X IDE, refer to the Opening the Project File. The following table provides details on the project file

Table 6-7. Table 6-9. Project File
Project NameDescription
azure_ota_demo_sam_e54_xpro_wincs02.X
  • MPLAB X project for SAM E54 Xplained Pro evaluation kit and WINCS02 Add On Board
  • This application demonstrates three key device functionalities.
    • Provisioning
    • Cloud Connectivity
    • OTA update

Running the Application

  1. Mount the WINCS02 Add On Board on SAM E54 Xplained Pro evaluation kit at respective header. For more details about the boards placement in the SAM E54 Xplained host board, see Figure
  2. Connect the debugger USB port on the SAM E54 Xplained Pro evaluation kit to computer using a micro-USB cable.
  3. Open the project and launch MCC Harmony3.
  4. Configure the WINCS02 Wi-Fi® ProvisionMode credentials, using the WINCS02 Wi-Fi configuration options. For more details about the Wi-Fi settings configuration, See Wi-Fi Settings: ProvisionMode
  5. Please follow the procedures provided in the Azure Cloud demo and MQTT service documentation for configuring settings, generating Azure-related certificates, and uploading these certificates to the Azure portal.
  6. Configure the OTA Server Socket, File Name and OTA Time Out in OTA System service.
  7. Please follow the procedures mentioned in the Ota cert create to create OTA-related certificates.
  8. Generate the code as illustrated below.
    Figure 6-32. Generating the code
  9. Build and program the code to the hardware using MPLABX IDE.
    Figure 6-33. Programming the board
  10. Open the Terminal application (for example, Tera Term or PuTTY) on the PC
  11. Connect to the "EDBG Virtual COM Port" and configure the serial settings as follows:
    1. Baud: 115200
    2. Data: 8 Bits
    3. Parity: None
    4. Stop: 1 Bit
    5. Flow Control: None

Device Functionalities

  1. Provisioning
  2. Cloud Connectivity
  3. OTA Update

  1. Provisioning

    When the provision mode command is issued, the device enters Provision Mode, enabling users to connect via the mobile app and provide home Wi-Fi credentials. Upon successful provisioning, the device switches to Station Mode and connects to the home network.

    Note: You may also connect to the home access point directly using the specified command below.

    Steps to Provision the device:

    1. Install the WiFiProv Mobile application in Android Mobile from the playstore.
    2. Command: prov <REGDOMAIN> start
      1. REGDOMAIN: GEN, USA, EMEA
        Figure 6-34. OTA_prov_mode
    3. Connect Mobile WiFi to AP shown in the logs :
      1. SSID: DEMO_AP_SOFTAP
      2. Password: password
    4. Turn ON the location on the Mobile.
    5. After establishing a successful connection between mobile phone and the device. Open WiFIProv Mobile Application and select Unsecured Socket. Provide below details and Click on Connect:
      1. Server IP Address : 192.168.1.1
      2. Server Port Number : 80

    6. On the next page, Select the AP to which the WINCS02 should be connected.

    7. Provide password of the AP and Click on Send.

      Image

    8. After successful provisioning, the board will connect to the AP and get an IP address. This IP address is displayed on the serial console as illustrated below.
      Figure 6-35. OTA_prov_complete
  2. Cloud Connectivity:

    By issuing the azure demo command, the WINCS02 board operates as an MQTT client, facilitating communication with Azure IoT applications. It utilizes built-in X.509 certificates to ensure secure TLS handshakes. Users simply need to enroll the device on Azure establish the connection.

    Steps to Connect to Azure Cloud:

    1. After successful provisioning, the device will be connected to WiFi.
    2. The access point (AP) must have internet access to connect to the Azure cloud.
    3. If the device is not provisioned and the user wants the device to connect to the AP directly without provisioning steps, please follow the instructions in Annexure A(STA mode Commands : Link pending).
    4. If the device is connected to AP and has valid IP, follow below commands.
      1. Command: azure connect
    5. Sending the data to cloud:
      1. Once the device is connected to Azure, press SW0 to transmit the button press data to the Azure cloud
        Figure 6-36. Azure logs
  3. OTA Update:

    When ota commands are issued, the example application performs an OTA firmware update for WINCS02. The update is executed by downloading the firmware image from a user-defined OTA HTTPS server.

    1. Non-TLS OTA FW Download:
      1. Download the latest WINCS02 firmware from: here.
      2. Unzip the downloaded firmware package, then navigate to the “NC_release_x.x.x\bin” directory. Copy the file named wincs02_ota.bin and replace/paste it into the “wireless_apps_rnwf\apps\ota_demo\tools” folder.
      3. Open the command prompt and navigate to “wireless_apps_rnwf\apps\ota_demo\tools” folder.
        Figure 6-37. Command Prompt
      4. Connect the PC to the same AP as WINCS02 is connected and give command ipconfig (in windows) and copy IP address of the PC.

      5. Start the server by giving command : python -m http.server
        Figure 6-38. http server
      6. The device is now booted up with firmware present at "600f0000" address, as you can see in the following logs.

      7. Give the command to configure OTA credentials. Copy the IP address of the PC where the server is running to following command to configure non-TLS OTA .
        1. Syntax: ota config http://<IP_address>:<PORT>/ota_file_name 0
        2. Command Ex: ota config http://192.168.11.36:8000/wincs02_ota.bin 0
          Figure 6-39. OTA configurations
      8. Give command : ota start to start downloading of FW image and boot the WINCS02 with the new FW. Wait for OTA download completion.

      9. Reboot the device.The device boots up with the newly downloaded firmware (present at "60000000). As you can see in the logs below, the address has been updated.

    2. TLS OTA FW Download:
      1. Download the latest WINCS02 firmware from: here.(If you have already downloaded the firmware and placed it in the specified folder, you may skip steps 1 and 2).
      2. Unzip the downloaded firmware package, then navigate to the “NC_release_x.x.x\bin” directory. Copy the file named wincs02_ota.bin and replace/paste it into the “wireless_apps_rnwf\apps\ota_demo\tools” folder.
      3. Open the command prompt and navigate to “wireless_apps_rnwf\apps\ota_demo\tools” folder.

      4. Connect the PC to the same AP as WINCS02 is connected and give command ipconfig (in windows) and copy IP address of the PC.

      5. Start the server by giving command: python3 mutual_auth_server.py
        Figure 6-40. https server
      6. The device is now booted up with firmware present at "60000000" address, as you can see in the following logs.

      7. Give the command to configure TLS OTA credentials. Copy the IP address of the PC where the server is running to device to configure OTA Credentials.
        1. Syntax: ota config https://<IP_address>:<PORT>/ota_file_name 1
        2. Command Ex: ota config https://192.168.199.67:443/wincs02_ota.bin 1
          Figure 6-41. ota https configurations
      8. Give command : ota start to start downloading of FW image and boot the WINCS02 with the new FW. Wait for OTA download completion.(The following image also includes server logs)

      9. Reboot the device.The device boots up with the newly downloaded firmware (present at "600f0000). As you can see in the logs below, the address has been updated.

ANNEXTURE A: (STA mode Commands)

To connect Device to AP :

  • To configure AP Credentials :
    • OPEN mode security:
      • sta config <REG_DOMAIN> <SSID> <SECURITY>
        • REG_DOMAIN : GEN, USA, EMEA
        • SECURITY : 0-Open
    • Other WPA2/WPA3 security:
      • sta config <REG_DOMAIN> <SSID> <SECURITY> <PASSWORD>
        • <REG_DOMAIN> : GEN, USA, EMEA
      • <SECURITY> : 2-WPA2 Mixed, 3-WPA2, 4-WPA3 Trans, 5-WPA3
  • To connect to AP with configured Credentials :
    • sta connect
  • To disconnect from AP :
    • sta disconnect
  • To get help :
    • sta help