/*Configure the domain name and port number*/
String ALIYUN_SERVER = "iot-as-mqtt.cn-shanghai.aliyuncs.com";
uint16_t PORT = 1883;
/*Product identifier that needs to be operated*/
/*需要操作的产品标识符(温度和湿度两个标识符)*/
String TempIdentifier = "Temperature";
String HumiIdentifier = "Humidity";
String ledIdentifier = "LED_S";
/*TOPIC that need to be published and subscribed*/
const char * subTopic = "/sys/a1DP0w8Z8i/rxgcbeEhora43tMXaFMR/thing/service/property/set";//you_sub_Topic";//****set
const char * pubTopic = "/sys/a1DP0w8Z8i/rxgcbeEhora43tMXaFMR/thing/event/property/post";//******post
void ConnectCloud(){
while(!client.connected()){
Serial.print("Attempting MQTT connection...");
/*A device connected to the cloud platform based on an automatically calculated username and password*/
if(client.connect(myIot._clientId,myIot._username,myIot._password)){
Serial.println("connected");
client.subscribe(subTopic);
}else{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void setup(){
Serial.begin(115200);
pinMode(BEDROOD_LIGHT,OUTPUT);
pinMode(DHT11_PIN,INPUT);
closeLight();
/*Connect to WIFI*/
connectWiFi();
/*Initialize the configuration of Aliyun*/
/*初始化Alinyun的配置,可自动计算用户名和密码*/
myIot.init(ALIYUN_SERVER,ProductKey,ClientId,DeviceName,DeviceSecret);
client.setServer(myIot._mqttServer,PORT);
/*Set the callback function to execute the callback function when receiving the subscription information*/
/*设置回调函数,当收到订阅信息时会执行回调函数*/
client.setCallback(callback);
/*Connect to the cloud platform*/
/*连接到Aliyun*/
ConnectCloud();
}