#include <ESP8266WiFi.h>
#include <PubSubClient.h> // 1. PubSubClient by Nick O’Leary。
WiFiClientSecure espClient;
PubSubClient client(espClient);
const char* willMsg = “CLIENT-OFFLINE”; // 遗嘱消息内容
const int willQos = 0; // 遗嘱QoS
const bool willRetain = true; // 遗嘱保留
const bool cleanSession = false; // 清除会话(如QoS>0必须要设为false)
const char *mqtt_broker = “XXXXXX.ala.cn-hangzhou.emqxsl.cn”; // broker address
const char *mqtt_username = “XXXX”; // username for authentication
const char mqtt_password = “XXXX”; // password for authentication
const int mqtt_port = 8883; // port of MQTT over TLS/SSL
const char fingerprint = “7E:52:D3:84:48:3C:5A:9F:A4:39:9A:8B:27:01:B1:F8:C6:AD:D4:47”;
//连接WIFI代码省略
espClient.setFingerprint(fingerprint);
client.setServer(mqtt_broker, mqtt_port);
client.setCallback(callback);
client.connect(client_id.c_str(), mqtt_username, mqtt_password) //可以连接
client.connect(client_id.c_str(), mqtt_username, mqtt_password, topic,willQos, willRetain, willMsg, cleanSession)//连不上