|
|
|
@ -27,7 +27,7 @@ const char* host = "192.168.3.26:8873";
|
|
|
|
|
|
|
|
|
|
|
|
// MQTT代理
|
|
|
|
// MQTT代理
|
|
|
|
const char *mqtt_broker = "47.242.184.139";
|
|
|
|
const char *mqtt_broker = "47.242.184.139";
|
|
|
|
const char *topic = "/device/esp8266/001";
|
|
|
|
const char *topic = "/device/esp8266/004";
|
|
|
|
const char *mqtt_username = "admin";
|
|
|
|
const char *mqtt_username = "admin";
|
|
|
|
const char *mqtt_password = "publish452131wW452131wW$";
|
|
|
|
const char *mqtt_password = "publish452131wW452131wW$";
|
|
|
|
const int mqtt_port = 1883;
|
|
|
|
const int mqtt_port = 1883;
|
|
|
|
@ -68,7 +68,7 @@ void setup() {
|
|
|
|
//mqtt init
|
|
|
|
//mqtt init
|
|
|
|
//连接到mqtt代理
|
|
|
|
//连接到mqtt代理
|
|
|
|
client.setServer(mqtt_broker, mqtt_port);
|
|
|
|
client.setServer(mqtt_broker, mqtt_port);
|
|
|
|
//client.setCallback(callback);
|
|
|
|
client.setCallback(callback);
|
|
|
|
while (!client.connected()) {
|
|
|
|
while (!client.connected()) {
|
|
|
|
String client_id = "esp8266-client-";
|
|
|
|
String client_id = "esp8266-client-";
|
|
|
|
client_id += String(WiFi.macAddress());
|
|
|
|
client_id += String(WiFi.macAddress());
|
|
|
|
@ -83,7 +83,7 @@ void setup() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 发布和订阅
|
|
|
|
// 发布和订阅
|
|
|
|
// client.publish(topic, "hello emqx");
|
|
|
|
// client.publish(topic, "hello emqx");
|
|
|
|
//client.subscribe(topic);
|
|
|
|
client.subscribe(topic);
|
|
|
|
|
|
|
|
|
|
|
|
/* 2. oled屏幕初始化 */
|
|
|
|
/* 2. oled屏幕初始化 */
|
|
|
|
oled.init();
|
|
|
|
oled.init();
|
|
|
|
|