Develop with non-certified modules

更新时间:
复制 MD 格式

This topic describes how to use the IoT Platform SDK (excluding AliOS Things) to develop standalone Wi-Fi devices that connect to IoT Platform if you are not using certified modules.

Define a product in the IoT Platform

  1. Create a project.
    For more information, see Create a project.
  2. Create a product.

    For more information, see Create a product. Set Network Connection Method to Wi-Fi. This setting allows the public version of the IoT Platform app to add devices through local discovery.

    Note

    If you use the public version of the IoT Platform app to manage the device, the app starts the Alibaba Wi-Fi provisioning process when you add a Wi-Fi device. Therefore, the device must integrate the Alibaba Wi-Fi provisioning feature.

    If your device does not integrate the Alibaba Wi-Fi provisioning feature and instead uses another method, such as a touch screen to enter the Wi-Fi hot spot SSID and password, set the Network Connection Method to Ethernet. This prevents the public IoT Platform app from using the Alibaba provisioning flow to add the device. However, you can still add the device using local discovery.

  3. Define product features.

    For more information about how to define product features, see Feature overview.

  4. Add a test device.
    For more information about how to add a test device and set the device binding policy, see Device debugging overview.

Device-side development

Download the SDK without AliOS Things (based on Link Kit v2.3.0). For instructions, see Obtain the SDK.

  • Recommended SDK configuration

    To understand the SDK configuration and the meaning of each option, read the "SDK Cropping" section in Compilation instructions.

    You can configure the required features by modifying the make.settings file or by running make menuconfig in Linux.

    Feature

    Description

    FEATURE_MQTT_COMM_ENABLED

    y: Use MQTT to connect to Alibaba Cloud IoT Platform.

    FEATURE_MQTT_DIRECT

    • y: Connect to servers in mainland China.

    • n: Connect to servers outside China.

    FEATURE_Device_MODEL_ENABLED

    y: Enable the Thing Specification Language model.

    FEATURE_ALCS_ENABLED

    y: Enable the local control feature.

    FEATURE_ALCS_SERVER_ENABLED

    y: Enable the local control feature for the controlled device.

    FEATURE_DEV_BIND_ENABLED

    y: Enable user attachment features.

    FEATURE_SUPPORT_TLS

    y: Enable Transport Layer Security (TLS) encryption.

    FEATURE_OTA_ENABLED

    y: Enable over-the-air (OTA) updates.

    FEATURE_WIFI_PROVISION_ENABLED

    y: Enable Wi-Fi provisioning.

    FEATURE_AWSS_SUPPORT_DEV_AP

    y/n: Enable or disable device hot spot provisioning as needed.

    FEATURE_AWSS_SUPPORT_SMARTCONFIG

    y/n: Enable or disable one-click provisioning as needed.

    FEATURE_AWSS_SUPPORT_PHONEASAP

    y/n: Enable or disable mobile phone hot spot provisioning as needed.

    FEATURE_AWSS_SUPPORT_ROUTER

    y/n: Enable or disable router provisioning as needed.

    FEATURE_AWSS_SUPPORT_ZEROCONFIG

    y/n: Enable or disable zero-configuration provisioning as needed.

    To connect a device to a server outside China, see Develop devices for Alibaba Cloud International Website (www.alibabacloud.com).

  • HAL adaptation

    To implement HAL, see the following document:

  • Device identity authentication mode

    When a device connects to the Alibaba Cloud IoT Platform, it can perform identity authentication using a pre-burned device certificate. Alternatively, the device can use dynamic registration to obtain a device certificate for authentication. For more information, see Device authentication.

  • Product feature implementation

    Implement the product features on the device according to the features that are defined in the cloud. For more information, see Thing Specification Language model programming.

  • Wi-Fi provisioning development

    For information about how to call provisioning-related APIs to implement Wi-Fi provisioning, see Wi-Fi device provisioning adaptation and development.

  • Cloud-initiated detach and factory reset

    After the device is detached, the cloud sends a detach notification event: {"identifier":"awss.BindNotify","value":{"Operation":"Unbind"}} When the device receives this message, it can reset the provisioning or clear local data.

    If you use the app to restore the device to its factory settings, the cloud sends a Reset notification event: {"identifier":"awss.BindNotify","value":{"Operation":"Reset"}} When the device receives this message, it can reset the provisioning or clear local data. Based on the specific product type, the developer can decide which data to clear after the device receives the detach and factory reset notifications.

    You can refer to the notify_msg_handle function in the example/smart_outlet/smart_outlet_main.c sample code and make the following changes.

    static int notify_msg_handle(const char *request, const int request_len)
    {
        ....
    
        if (!strcmp(item->valuestring, "awss.BindNotify")) {
            cJSON *value = cJSON_GetObjectItem(request_root, "value");
            if (item == NULL || !cJSON_IsObject(value)) {
                cJSON_Delete(request_root);
                return -1;
            }
            cJSON *op = cJSON_GetObjectItem(value, "Operation");
            if (op != NULL && cJSON_IsString(op)) {
                if (!strcmp(op->valuestring, "Bind")) {
                    EXAMPLE_TRACE("Device Bind");
                    vendor_device_bind();
                }
                if (!strcmp(op->valuestring, "Unbind")) {
                    EXAMPLE_TRACE("Device Unbind");
                    vendor_device_unbind();
                }
                if (!strcmp(op->valuestring, "Reset")) {
                    EXAMPLE_TRACE("Device Reset");
                    vendor_device_reset();
                }
            }
        }
    
        ....
    }
  • Device reset

    You must design a reset button for your product. The logic that handles the reset button must clear the device configuration, restore the device to its factory state, and call the awss_report_reset() function. Calling this function notifies the cloud to clear the attachment between the device and the user.

    Therefore, you must add a call to awss_report_reset() in the logic that handles the reset button.

    /*
     * After the application calls this API, Link Kit first stores a factory reset flag in the flash memory 
     * and reports the reset operation to the cloud.
     * If no response is received from the cloud within a specified time (3 seconds), the device re-uploads 
     * the reset request until a response is received.
     * Some products require the device to restart upon reset. If the reset operation is not successfully 
     * reported before the restart, after the next cloud connection,
     * the device first checks whether the factory reset flag is set in the flash memory. If the flag is set, 
     * the device first reports the reset to the cloud and continues to do so until it succeeds.
     */
    int awss_report_reset();
  • OTA development

    If you enabled the Over-the-Air (OTA) update feature, see OTA programming.