【问题标题】:Message is not publishing to ESP8266 from IBM Bluemix消息未从 IBM Bluemix 发布到 ESP8266
【发布时间】:2017-05-24 15:59:13
【问题描述】:

我已经为我的 ESP8266 编程并订阅了一个主题以继续收听消息。这是我向 IBM IoT 节点注入消息的图形视图。

这是我的注入视图设置

这是我对 IBM IoT 节点的设置。

这是我在串行监视器上的日志,它已连接并订阅了 cmd 频道

到目前为止一切顺利,当我尝试向我的 IBM IoT 节点注入消息时,它没有发布消息,因为它没有到达串行监视器并且没有登录调试视图。在这里你可以看到

这里是源代码:

#include <ESP8266WiFi.h>
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.3

const char* ssid = "shiv";
const char* password = "manmohan@12345";

#define ORG "2kafk4"
#define DEVICE_TYPE "ESP8266"
#define DEVICE_ID "5CCF7FEED6F0"
#define TOKEN "opKF7v3@8jRM*mGkb_"

char server[] = ORG ".messaging.internetofthings.ibmcloud.com";
char topic[] = "iot-2/cmd/test/fmt/String";
char authMethod[] = "use-token-auth";
char token[] = TOKEN;
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;

WiFiClient wifiClient;

void callback(char* topic, byte* payload, unsigned int payloadLength) {
  Serial.print("callback invoked for topic: "); Serial.println(topic);

  for (int i = 0; i < payloadLength; i++) {
    Serial.print((char)payload[i]);
  }
}
PubSubClient client(server, 1883, callback, wifiClient);

void setup() {
  Serial.begin(115200);
  Serial.println();
  wifiConnect();
  mqttConnect();
}

void loop() {
  if (!client.loop()) {
    mqttConnect();
  }
}

void wifiConnect() {
  Serial.print("Connecting to "); Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("nWiFi connected, IP address: "); Serial.println(WiFi.localIP());
}

void mqttConnect() {
  if (!client.connected()) {
    Serial.print("Reconnecting MQTT client to "); Serial.println(server);
    while (!client.connect(clientId, authMethod, token)) {
      Serial.print(".");
      delay(500);
    }
    initManagedDevice();
    Serial.println();
  }
}

void initManagedDevice() {
  if (client.subscribe(topic)) {
    Serial.println("subscribe to cmd OK");
  } else {
    Serial.println("subscribe to cmd FAILED");
  }
}

我尝试使用cf 命令检查云代工日志,这里是https://pastebin.com/dfMaS1Gd

谁能提示我我做错了什么?提前致谢。

【问题讨论】:

  • @valerielampkin 你有什么想法吗?
  • IoTin 节点有什么用?我认为默认情况下需要 json,而不是字符串。
  • 我遇到了一个教程,他们举了一个字符串的例子。无论如何,我会在这里注入 JSON i.stack.imgur.com/hFbIa.png 像 { "name": "williams"} 并将 IOT 节点的格式更改为 json。我希望是你的意思
  • 我会尝试为订阅使用通配符:char topic[] = "iot-2/cmd/+/fmt/+"; 但我想知道为什么您的输出必须不断重新连接。
  • 无论您在 IBM IoT out 节点中注入什么格式,您都需要使用 IBM IoT in 节点来监听。

标签: arduino ibm-cloud esp8266 node-red watson-iot


【解决方案1】:

确认在您的节点配置中正确指定了设备类型。目前,屏幕截图显示 0.16.2 似乎与您注册的设备类型以及您的代码中指定的设备类型不匹配。

【讨论】:

  • @nop77svk 怎么样?这似乎是我的答案!
猜你喜欢
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 2018-10-31
相关资源
最近更新 更多