消息未从 IBM Bluemix 发布到 ESP8266

Message is not publishing to ESP8266 from IBM Bluemix

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

这是我的注入视图设置

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

这是我在 Serial Monitor 上的日志,它已连接并订阅了 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 命令检查 cloud foundry 日志,这里是 https://pastebin.com/dfMaS1Gd

任何人都可以提示我做错了什么吗?提前致谢。

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