This topic describes how to use the IoT Platform software development kit (SDK) to develop Ethernet devices that connect to IoT Platform.
Define a product in IoT Platform
- Create a project.
For more information, see Create a project.
- Create a product.
For more information, see Create a product. Set Connection Method to Ethernet. This allows the public IoT Platform app to add devices using local discovery.
- Define product features.
Define the features for your product. For more information, see Function Overview.
- 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 non-AliOS SDK (based on Link Kit v2.3.0). For more information, see Obtain an SDK.
- Recommended SDK configurations
Read the "SDK Trimming" section in Compilation instructions to understand the SDK configurations and the purpose of each option.
You can configure the required features by modifying the make.settings file or by running
make menuconfigin 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 mainland China.
FEATURE_Device_MODEL_ENABLED y: Enable the Thing Specification Language (TSL) 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 features related to user binding. FEATURE_SUPPORT_TLS y: Enable TLS encryption. FEATURE_OTA_ENABLED y: Enable over-the-air (OTA) updates. If your device needs to connect to servers outside China, see Develop devices for Alibaba Cloud International Website.
- HAL adaptation
Implement the hardware abstraction layer (HAL) based on the following documents:
- Device identity authentication mode
When a device connects to Alibaba Cloud IoT Platform, it can be authenticated 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 device-side logic for the product features that you defined in the cloud. For more information, see TSL model programming.
- OTA development
If you enabled the OTA update feature, see OTA programming.
- Cloud-initiated unbinding and factory reset
After the device binding process is complete, the cloud sends a binding notification:
{"identifier":"awss.BindNotify","value":{"Operation":"Bind"}}. When the device receives this message, it can confirm that the binding was successful.After the device is unbound, the cloud sends an unbinding notification:
{"identifier":"awss.BindNotify","value":{"Operation":"Unbind"}}. When the device receives this message, it can reset the network configuration, clear local data, or perform other similar actions.If you use the app to restore the device to its factory settings, the cloud sends a Reset notification:
{"identifier":"awss.BindNotify","value":{"Operation":"Reset"}}. When the device receives this message, it can reset the network configuration, clear local data, or perform other similar actions. You can decide which data to clear after the device receives unbinding and factory reset notifications based on the product type.You can refer to the
notify_msg_handlefunction in the sample code at example/smart_outlet/smart_outlet_main.c to implement this logic.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 development
When you develop a product for IoT Platform, you must design a reset button. This button should clear the device's configuration, restore it to its factory state, and call the
awss_report_reset()function. This function notifies the cloud to clear the binding relationship between the device and the user.Therefore, you must add a call to
awss_report_reset()in the handler logic for the reset button./* * When an application calls this API, Link Kit stores a factory reset flag in the flash memory * and reports the reset operation to the cloud. If the device does not receive a response from * the cloud within 3 seconds, it repeatedly sends the report until it receives a response. * Some products may need to restart when a reset occurs. If the reset report fails to upload * before the restart, the device checks for the factory reset flag in the flash memory upon * its next connection to the cloud. If the flag is set, the device reports the reset to the * cloud until the report is successful. */ int awss_report_reset();