使用 BlueMix 的 Node-RED 编辑器和 MQTT->Debug Node 时出现意外字符串

Unexpected String when using BlueMix's Node-RED editor and MQTT->Debug Node

我正在学习本教程, http://energia.nu/creating-an-iot-connected-sensor-with-energia-mqtt/

我看到推送的数据,但 Node-RED 编辑器不断打印 'Hello World #XX'。我在代码中看不到任何暗示其来源的内容:

  #include <WiFi.h>
  #include <PubSubClient.h>
  #include <SPI.h> //only required if using an MCU LaunchPad + CC3100 BoosterPack. Not needed for CC3200 LaunchPad
  WiFiClient wclient;

  byte server[] = { 198, 41, 30, 241 }; //  Public MQTT Brokers: http://mqtt.org/wiki/doku.php/public_brokers
  byte ip[]     = { 172, 16, 0, 100 };

  char sensorRead[4];

  #define       WIFI_SSID         "SSID"
  #define       WIFI_PWD          "WIFIPASSWORD"

  PubSubClient client(server, 1883, callback, wclient);

  void callback(char* inTopic, byte* payload, unsigned int length){
  // Handle callback here
  }

  void setup()
  {
    //Initialize serial and wait for port to open:
    Serial.begin(115200);

    Serial.println("Start WiFi");
    WiFi.begin(WIFI_SSID, WIFI_PWD);
    while(WiFi.localIP() == INADDR_NONE) {
      Serial.print(".");
      delay(300);
    }
    Serial.println("");

    printWifiStatus();

  }

  void loop()
  {
    // read the input on analog pin:
    int sensorValue = analogRead(24);
    Serial.println(sensorValue);

    // convert into to char array
    String str = (String)sensorValue; 
    int str_len = str.length() + 1;  // Length (with one extra character for the null terminator)
    char char_array[str_len];  // Prepare the character array (the buffer) 
    str.toCharArray(char_array, str_len);  // Copy it over 

    // publish data to MQTT broker
    if (client.connect("LaunchPadClient")) {
      client.publish("outTopic", char_array);
      //client.subscribe("inTopic");
      Serial.println("Publishing successful!");
      client.disconnect();
    }

  }

  void printWifiStatus() {
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());

    // print your WiFi shield's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);
  }

这是因为这是一个 free/trial 帐户吗?顺便说一句,它显示我正在使用 512MB/2GB,这似乎很高...它包括发送的数据,还是 512MB 只是应用程序大小?

您正在使用 public 面向世界的 MQTT 代理,任何人都可以将数据发布到该代理上的任何主题。这些消息可能来自对您自己进行类似实验的其他人。

outTopic 是很多人可以用来测试的那种主题名称,尝试在发布代码和 Node 中的 MQTT In 节点中将其更改为一些随机字符串-红色。

至于 Bluemix 中的大小,这是分配给您的应用程序的内存量,目前不太可能实际使用接近该数量的内存。