Example: Update MicroPython from Remote Manager using XML

You can use the API Explorer in Remote Manager to create a schedule that enables you to update the MicroPython application. In this example, you want to add FTP client capability to the MicroPython application. You will need to add the library uftp.py and then update the main.py application.

This example is done following these steps: upload the MicroPython files to Remote Manager, create an XML file with the tasks that you want to perform, upload the XML file, and then schedule an operation to upload the files onto your device.

Note You must upgrade your device to the latest firmware for all features to be available. See Update the firmware.

Step 1: Upload the MicroPython files

  1. Log into Remote Manager.
  2. Click the arrow next to you your user name, and click Open Classic Remote Manager.
  3. Click Data Services > Data Files.
  4. Upload the MicroPython application main.py file.
    1. Click New Folder. The New Folder dialog displays.
    2. In the Folder name field, enter a descriptive name, such as "MicroPython."
    3. Click Create. The new file is added to the list of files.
    4. Find the "MicroPython" folder in the folder list.
    5. Click Upload Files. The Upload Files dialog displays.
    6. Browse for the main.py file. Check with your system administrator for the location of the application file.
    7. Click OK.
  5. Upload the MicroPython library uftp.py file.
    1. Find the "MicroPython" folder in the folder list.
    2. Click Upload Files. The Upload Files dialog displays.
    3. Browse for the uftp.py file. The library uftp.py file is found on the GitHub repository: https://github.com/digidotcom/xbee-micropython
    4. Click OK.

Step 2: Create an XML file with the tasks that you want to perform

This XML file will contain a list of commands for the operation that you will schedule in Step 3.

Note The RCI commands to set_settings in the task may fail to execute because of disconnects after changing the value for MO.

  1. Open the editor of your choice.
  2. Create a new file named updatemicropython.xml.
  3. Copy the XML below and paste it into the new file.
  4. Save the file.
<task>
<description>Update MicroPython</description>
<command>
<name>SM/UDP Request Connect</name> <event>
<on_error>
<end_task/>
</on_error>
</event>
<sci>
<send_message reply="none" >
<sm_udp>
<request_connect/>
</sm_udp>
</send_message>
</sci>
</command>
<command>
<name>RCI Command</name>
<event>
<on_error>
<continue/>
</on_error>
</event> <sci>
<send_message cache="false" allowOffline="true" >
<!-- Disable Python Auto-start and enable TCP connection for remainder of commands-->
<rci_request>
<set_setting>
<micropython>
<PS>0</PS>
</micropython> <remote_manager> <MO>7</MO> </remote_manager>
</set_setting>
</rci_request>
</send_message>
</sci>
</command>
<command> <!-- Reboot to stop MicroPython --> <name>Reboot</name> <event> <on_error> <continue/> </on_error> </event> <sci> <reboot allowOffline="true" waitForReconnect="true"/> </sci> </command>
<!-- Update MicroPython application--> <command>
<name>Upload Files</name>
<event>
<on_error>
<continue/>
</on_error>
</event>
<sci>
<file_system allowOffline="true" >
<commands>
<put_file path="/flash/main.py">
<file>~/MicroPython/main.py</file>
</put_file>
</commands>
</file_system>
</sci>
</command>
<command>
<name>Upload Files</name>
<event>
<on_error>
<continue/>
</on_error>
</event>
<sci>
<file_system allowOffline="true" >
<commands>
<put_file path="/flash/lib/uftp.py">
<file>~/MicroPython/uftp.py</file>
</put_file>
</commands>
</file_system>
</sci>
</command>
<command>
<name>RCI Command</name>
<event>
<on_error>
<continue/>
</on_error>
</event>
<sci>
<send_message cache="false" allowOffline="true">
<!-- Enable Python Auto-start -->
<rci_request>
<set_setting>
<micropython>
<PS>1</PS>
</micropython> <remote_manager> <MO>6</MO> </remote_manager>
</set_setting>
</rci_request>
</send_message>
</sci>
</command>
<!-- Reboot to start the program -->
<command>
<name>Reboot</name>
<event>
<on_error>
<end_task/>
</on_error>
</event>
<sci>
<reboot allowOffline="true" waitForReconnect="false"/>
</sci>
</command> </task>

 

Step 3: Upload the XML to Remote Manager

In this step you will upload the file you just created (updatemicropython.xml) to Remote Manager.

  1. Log into Remote Manager.
  2. Click Data Services > Data Files.
  3. Upload the XML file you just created: updatemicropython.xml
    1. Find the "~/my_tasks" folder in the folder list.
    2. Click Upload Files. The Upload Files dialog displays.
    3. Browse for the updatemicropython.xml file.
    4. Click OK.

Step 4: Schedule an operation to upload the files

  1. Log into Remote Manager.
  2. Click Documentation > API Explorer.
  3. Click SCI Targets. The Select devices to be used in examples dialog appears.
    1. From the Add Targets list box, search for the IMEI (device ID) of the device that you want to update.
    2. Click Add. The device is added to the device list.
    3. Click OK.
  4. Click the Examples drop-down list button.
  5. Click Scheduled Operation > Create immediate running schedule.
  6. Update the XML to refer to the updatemicropython.xml file you created previously.

    Note For additional examples of how you can deploy this code to multiple devices, such as a group of devices or devices with a specific tag, see SCI targets in the Digi Remote Manager Programmer Guide.

     

    <!-- Runs immediately -->
    <Schedule on="IMMEDIATE">
    <targets>
    <device id="00010000-00000000-03588320-70372440"/>
    </targets> <task path="~/my_tasks/updatemicropython.xml"/> </Schedule>
  7. Click Send to schedule the task.
  8. Click Device Management > Operations to view information about the operation. See Operations in the Digi Remote Manager® User Guide for more information about this page.