Skip to content

M5StickC#

Integrate your ESP32-based device to manage it via Coiote IoT DM.

Prerequisites#

  • An M5StickC device.
  • Installed ESP-IDF and dependencies (installation steps 1-4 from ESP32 official documentation). Supported ESP-IDF version is v4.4.
  • A user with access to the Coiote IoT Device Management platform.

Step 1: Download the Anjay ESP32 client files#

  1. Create a project directory for the integration.
  2. Go to https://github.com/AVSystem/Anjay-esp32-client/releases and download m5stickc-plus.bin and nvs_partition_gen.py to your project directory.

Step 2: Configure the client using an NVS partition#

  1. Create a nvs_config.csv file and save it in your project directory. In the file, provide your credentials in [wifi_ssid], [wifi_password], [endpoint_name], [identity], [psk], [lwm2m_server_uri] (without the [] brackets). Use the following snippet as a template:

    key,type,encoding,value
    config,namespace,,
    wifi_ssid,data,string,[wifi_ssid]
    wifi_pswd,data,string,[wifi_password]
    wifi_inter_en,data,u8,1
    endpoint_name,data,string,[endpoint_name]
    identity,data,string,[identity]
    psk,data,string,[psk]
    uri,data,string,[lwm2m_server_uri]
    writable_wifi,namespace,,
    wifi_ssid,data,string,[wifi_ssid]
    wifi_pswd,data,string,[wifi_password]
    wifi_inter_en,data,u8,0
    

    Note

    The additional parameters under the writable_wifi namespace are used to provide a secondary Wi-Fi configuration (it is not obligatory). This allows for switching between Wi-Fi configurations while the device is running.

    Note

    The nvs_config.csv file can also be downloaded from https://github.com/AVSystem/Anjay-esp32-client/releases

  2. Open a command line interface, go to your project directory, and generate the NVS partition:

pip3 install future cryptography
python3 nvs_partition_gen.py generate nvs_config.csv nvs_config.bin 0x4000
pip3 install future cryptography
python nvs_partition_gen.py generate nvs_config.csv nvs_config.bin 0x4000

Client configuration

Step 3: Add device to Coiote IoT DM#

To connect your M5StickC to the Coiote IoT Device Management platform, use your access to a Coiote IoT DM installation, or register at https://eu.iot.avsystem.cloud/ to get access.

To connect the board:

  1. Log in to Coiote IoT DM and from the left side menu, select Device Inventory.
  2. In Device Inventory, click Add device.
  3. Select the Connect your LwM2M device directly via the Management server tile. Add via Mgmt
  4. In the Device credentials step:
    • In the Device ID field, type the endpoint name provided in the nvs_config.csv, e.g. ESP32_test.
    • In the Security mode section, select the PSK mode.
    • In the Key identity field, type the name provided in the nvs_config.csv, e.g. ESP32_test.
    • In the Key field, type the psk key provided in the nvs_config.csv. Device credentials step
  5. Click the Add device button and Confirm in the confirmation pop-up.
  6. In the Connect your device step, the server is waiting for the board to connect. You can now start connecting the device.

Step 4: Flash the board and run device#

Connect the M5Stick board to a USB port of your machine and open ESP-IDF command line application.

Use pre-built binaries to flash the board and provide credentials by flashing the NVS partition binary.

  1. Install the esptool.py:

    pip install esptool
    

  2. Flash the board:

    Tip

    Before flashing the device you should erase the flash first to make sure you have correct settings:

    esptool.py erase_flash
    
    esptool erase_flash
    

    esptool.py -b 750000 --chip esp32 write_flash 0x0000 m5stickc-plus.bin
    
    esptool -b 750000 --chip esp32 write_flash 0x0000 m5stickc-plus.bin
    
  3. Flash the NVS partition binary:

    esptool.py -b 750000 --chip esp32 write_flash 0x9000 nvs_config.bin
    
    esptool -b 750000 --chip esp32 write_flash 0x9000 nvs_config.bin
    

Once executed, the device will be reset and run with the configuration you provided.

Registered device

M5StickC LwM2M objects#

After successful connection to Coiote IoT DM, you can explore the available device objects.

Target Objects
ESP32 common Security (/0)
Server (/1)
Device (/3)
Firmware Update (/5)
WLAN connectivity (/12)
M5StickC-Plus Push button (/3347)
Light control (/3311)
Temperature sensor (/3303)
Accelerometer (/3313)
Gyroscope (/3343)

Upgrade device firmware over the air#

To perform a FOTA upgrade, you need an established connection between the M5StickC and Coiote IoT DM (see instructions above).

Build new firmware version#

  1. Open a command line interface and run git clone https://github.com/AVSystem/Anjay-esp32-client.
  2. Go to the directory of the cloned repository and run idf.py set-target esp32.
  3. Run git submodule update --recursive --init.
  4. Run idf.py menuconfig, navigate to Component config/anjay-esp32-client, and from the supported boards, select M5StickC. Press s and enter to save.
  5. Run idf.py build.
  6. Once executed, check if the binary file has been built in the following path $PROJECT_DIR/build/anjay-esp32-client/build.

Schedule upgrade in Coiote IoT DM#

  1. In your Coiote IoT DM account, select your device in Device inventory and click the LwM2M Firmware tab.

    LwM2M firmware tab

  2. Click Schedule new firmware upgrade.

  3. Click Upload to select the binary file from your local drive, select COAP in the Image delivery protocol, and click Upgrade.

    Tip

    The COAPS option is also supported. To use it, you may need to additionally provide the Base URI parameter (depending on your server settings).

    Scheduling FOTA

  4. The FOTA upgrade is now scheduled. Note that it might take a few minutes to complete.

  5. Once the upgrade is finished, you can check the new version of the firmware under Current firmware. Current firware


Last update: July 19, 2023