用esp8266上传云服务器,数据上传不上去,求大神们帮忙-Arduino中文社区 - Powered by Discuz! Archiver

cxfy 发表于 2016-12-12 17:09

用esp8266上传云服务器,数据上传不上去,求大神们帮忙

#include <ESP8266WiFi.h>
#include <;PubSubClient.h>
const char *ssid = "lzc";// cannot be longer than 32 characters!
const char *pass = "7758521ZHAO";//
// Update these with values suitable for your network.
IPAddress server(115, 28, 134, 249);
void callback(const MQTT::Publish& pub) {
// handle message arrived
}
WiFiClient wclient;
PubSubClient client(wclient, server);
void setup() {
// Setup console
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
client.set_callback(callback);
}
void loop() {
if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println("...");
    WiFi.begin(ssid, pass);
    if (WiFi.waitForConnectResult() != WL_CONNECTED)
      return;
    Serial.println("WiFi connected");
}
if (WiFi.status() == WL_CONNECTED) {
    if (!client.connected()) {
      if (client.connect("arduinoClient")) {
client.publish("outTopic","hello world");
//client.subscribe("inTopic");
      }
    }
    if (client.connected())
      client.loop();
}
}



不知道哪里出错了,新人,不太懂mqtt的通讯方式
页: [1]
查看完整版本: 用esp8266上传云服务器,数据上传不上去,求大神们帮忙