This is the 17th day of my participation in the Genwen Challenge. For details, see genwen Challenge to create Aliyun products

  1. Log in to aliyun Iot cloud platform and watch the tutorial

  2. Create a device



    Select Create product



    After filling in the relevant information, select OK

  3. Create a device





    After the device is created, click to view or copy the device certificate in the dialog box that is displayed.

    Device certificates include ProductKey, DeviceName, and DeviceSecret.

    In this example, is

{
  "ProductKey": "a16u28xxxxxV",
  "DeviceName": "LED1",
  "DeviceSecret": "6bd8400346505b80370bf861785xxxxx"
}

Copy the code

Specific implementation

Download the development board file

Download ESP8266 development board file, download slow can choose mine.

The program

#include < esp8266wifi. h> static WiFiClient espClient; #include < aliyuniotsdk. h> #define PRODUCT_KEY "a16U28XXxxx" #define DEVICE_NAME "LED1" #define DEVICE_SECRET "Six bd8400346505b80370bf8617xxxxxxx" # define REGION_ID "cn - Shanghai" / / set the wifi information # define WIFI_SSID "STM32L476" # define WIFI_PASSWD "284122348" void setup() { Serial.begin(115200); // Initialize wifi wifiInit(WIFI_SSID, WIFI_PASSWD); // To initialize iot, pass in wifi client, And device product information AliyunIoTSDK:: BEGIN (espClient, PRODUCT_KEY, DEVICE_NAME, DEVICE_SECRET, REGION_ID); // Bind a device property callback. When this property is modified remotely, // PowerSwitch is the ID of the iot model defined in the device product AliyunIoTSDK::bindData("PowerSwitch", powerCallback); // LightLuminance is the ID of the iot model defined in the device product AliyunIoTSDK::send("LightLuminance", 100); } void loop() { AliyunIoTSDK::loop(); } void wifiInit(const char *ssid, const char *passphrase) {wifi.mode (WIFI_STA); WiFi.begin(ssid, passphrase); while (WiFi.status() ! = WL_CONNECTED) { delay(1000); Serial.println("WiFi not Connect"); } Serial.println("Connected to AP"); Void PowerSwitch (JsonVariant p) {int PowerSwitch = p["PowerSwitch"]; If (PowerSwitch == 1) {// Start device}}Copy the code

subsequent

If you like, just watch it

Writing is not easy, thank you for your support.

This article uses the article synchronization assistant to synchronize