|
|
|
|
@ -68,7 +68,7 @@ void setup() {
|
|
|
|
|
//mqtt init
|
|
|
|
|
//连接到mqtt代理
|
|
|
|
|
client.setServer(mqtt_broker, mqtt_port);
|
|
|
|
|
client.setCallback(callback);
|
|
|
|
|
//client.setCallback(callback);
|
|
|
|
|
while (!client.connected()) {
|
|
|
|
|
String client_id = "esp8266-client-";
|
|
|
|
|
client_id += String(WiFi.macAddress());
|
|
|
|
|
@ -83,7 +83,7 @@ void setup() {
|
|
|
|
|
}
|
|
|
|
|
// 发布和订阅
|
|
|
|
|
//client.publish(topic, "hello emqx");
|
|
|
|
|
client.subscribe(topic);
|
|
|
|
|
//client.subscribe(topic);
|
|
|
|
|
|
|
|
|
|
/* 2. oled屏幕初始化 */
|
|
|
|
|
oled.init();
|
|
|
|
|
@ -149,15 +149,13 @@ void loop() {
|
|
|
|
|
Serial.println(sendStr);
|
|
|
|
|
client.publish(topic,sendStr.c_str());
|
|
|
|
|
|
|
|
|
|
oled.clear();
|
|
|
|
|
oled.setFont(ArialMT_Plain_16); // 设置字体
|
|
|
|
|
oled.drawString(0, 0, wendu); // 将要显示的文字写入缓存
|
|
|
|
|
oled.drawString(0, 20,shidu); // 将要显示的文字写入缓存
|
|
|
|
|
oled.drawString(0, 40,sendStr); // 将要显示的文字写入缓存
|
|
|
|
|
oled.display(); // 将缓存里的文字在屏幕上显示
|
|
|
|
|
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on
|
|
|
|
|
delay(300);
|
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
Serial.println(client.state());
|
|
|
|
|
String client_id = "esp8266-client-";
|
|
|
|
|
|