esp8266/esp12f安装MQTT Client 客户端
代码我已经写好了,由于只有一个esp12f,发布和订阅用的是一个模块。
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
WiFiClient espClient;
PubSubClient client(espClient);
// Update these with values suitable for your network.
const char* ssid = "replace with your ssid";
const char* password = "replace with ssid's password";
const char* mqtt_server = "ip address of mqtt server";
unsigned long lastMsg = 0;
char msg[50];
int light=2;
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status()

本文介绍了如何在ESP8266/ESP12F上安装和配置MQTT客户端,实现TCP/IP连接,并在实际操作中,使用同一模块进行发布和订阅。
最低0.47元/天 解锁文章
1821

被折叠的 条评论
为什么被折叠?



