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

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4009|回复: 0

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

[复制链接]
发表于 2016-12-12 17:09 | 显示全部楼层 |阅读模式
#include <ESP8266WiFi.h>
#include <ubSubClient.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:ublish& 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的通讯方式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 08:40 , Processed in 0.110677 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表