概述
1.修改以下例程中的参数,其中线上环境参数从小工具中获取
小工具网盘链接: https://pan.baidu.com/s/16qRsPle_oUXB6hIYFFWvXQ?pwd=9xtt 提取码: 9xtt
#include <ESP8266WiFi.h>
/* 依赖 PubSubClient 2.4.0 */
#include <PubSubClient.h>
/* 依赖 ArduinoJson 5.13.4 */
#include <ArduinoJson.h>
#define SENSOR_PIN
13
/* 连接您的WIFI SSID和密码 */
#define WIFI_SSID
"WIFI名称"
#define WIFI_PASSWD
"WIFI密码"
/* 设备的三元组信息*/
#define PRODUCT_KEY
"gwbmE0Kg1oZ"
#define DEVICE_NAME
"Esp8266_1"
#define DEVICE_SECRET
"5430a923098af6223e6f650f382d266f"
/* 线上环境域名和端口号,从小工具中获取 */
#define MQTT_SERVER
"gwbmE0Kg1oZ.iot-as-mqtt.cn-shanghai.aliyuncs.com"
#define MQTT_PORT
1883
#define MQTT_USRNAME
"Esp8266_1&gwbmE0Kg1oZ"
#define CLIENT_ID
"123456|securemode=3,signmethod=hmacsha1|"
#define MQTT_PASSWD
"40FE77BA140AFC32A62D503395C2502C40FDD189"
#define ALINK_BODY_FORMAT
"{"id":"123","version":"1.0","method":"thing.event.property.post","params":%s}"
#define ALINK_TOPIC_PROP_POST
"/sys/" PRODUCT_KEY "/" DEVICE_NAME "/thing/event/property/post"
unsigned long lastMs = 0;
WiFiClient espClient;
PubSubClient
client(espClient);
void callback(char *topic, byte *payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
payload[length] = '