1

I have programmed to my ESP8266 and subscribed one topic to keep listening messages. This is my graphical view of injecting message to IBM Iot node.

enter image description here

This is my settings of inject view

enter image description here

This is my settings of IBM Iot node.

enter image description here

Here are my logs at Serial Monitor, it is connected and subscribed to cmd channel

enter image description here

So far so good, When I am trying to inject a message to my IBM Iot node then it is not publishing a message, as it is not reaching on serial monitor and no log on debug view. here you can see

enter image description here

Here is source code:

#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");
  }
}

I tried to check cloud foundry logs using cf command, here it is https://pastebin.com/dfMaS1Gd

Can anyone hint me what I am doing wrong ? Thanks in advance.

N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • @valerielampkin Do you have any idea ? – N Sharma May 24 '17 at 16:02
  • What do you have for the IoTin node? I think by default that expects json, not string. – ValerieLampkin May 24 '17 at 18:19
  • I came across one tutorial, they took an example of string. Anyways, I will inject JSON here https://i.stack.imgur.com/hFbIa.png like { "name": "williams"} and change format of IOT node to json. I hope it is what you mean – N Sharma May 25 '17 at 05:09
  • I'd try wildcards for the subscribe: `char topic[] = "iot-2/cmd/+/fmt/+";` But I'm wondering why your output has to keep re-connecting. – amadain May 25 '17 at 11:49
  • Whatever format you inject in the IBM IoT out node is what you need to listen for with the IBM IoT in node. – ValerieLampkin May 25 '17 at 11:54
  • @amadain I disconnect ESP8266 from power source then plugged back.. some sort of this so it was re-connecting – N Sharma May 25 '17 at 16:51
  • @ValerieLampkin I tried to send JSON , see this configuration of inject node http://imgur.com/a/Y295a and JSON `{ "d": { "count": 3, "time": "2014-12-30 16:14:59" } }` and IBM IOT Node http://imgur.com/a/hyZmS and in my code topic is `char topic[] = "iot-2/cmd/test/fmt/json";` can you check logs at your end what I am doing wrong ? – N Sharma May 25 '17 at 17:20
  • @ValerieLampkin can you suggest ? what could be the problem ? – N Sharma May 26 '17 at 17:17

1 Answers1

1

Confirm the device type is correctly specified in your node configuration. Currently the screenshot show 0.16.2 which doesn't seem to match the device type you registered and what is specified in your code.

ValerieLampkin
  • 2,620
  • 13
  • 27