我遵循了以下教程:http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/一步一步地完成编译和编码,并连接到我的Wi接入点。我想我成功地连接到了PubNub (在终端屏幕"PubNub设置“上打印的代码),但是在代码中没有真正的验证是否确实设置了它。
我在PubNub上开了一个帐户,我把我的频道命名为“that”(在我上传的代码中我给它起了相同的名字--我检查了一百万次),当我到Dev控制台点击订阅时,我什么也看不见!我的意思是我可以通过Dev控制台发布消息,但我真正想看到的是来自CC3100的消息。我检查了我的计算机上的UART终端,我看到数据不断地被打印,所以我知道它在工作。我一遍又一遍地看了一遍教程,我也在做同样的事情,但它就是不起作用。任何帮助都将不胜感激!
我遗漏了什么?
谢谢
发布于 2017-01-17 09:26:39
这个答案发得太晚了。我承认我忘记了这篇文章,所以我决定更新它(虽然迟了几年)。
我开始挖掘,试图看看是什么问题,我想我找到了。首先,我看到PubNub.publish()没有在json_String中正常工作,因为json_String是90%的gibrish。因此,我删除了构建json_String (插入模拟值的部分)的大部分代码,并使其更简单。然后,我还在最后添加了一部分代码,这是客户端变量的适当性能所必需的,这是我从代码的一部分中获得的,该代码用于使用CC3100的基于arduino的项目。
不管怎么说,新的代码就是下面的代码,现在它工作得很好!我终于看到了PubNub上的所有输入流!非常感谢!
/*PubNub sample JSON-parsing client with WiFi support
This combines two sketches: the PubNubJson example of PubNub library
and the WifiWebClientRepeating example of the WiFi library.
This sample client will properly parse JSON-encoded PubNub subscription
replies using the aJson library. It will send a simple message, then
properly parsing and inspecting a subscription message received back.
This is achieved by integration with the aJson library. You will need
a version featuring Wiring Stream integration, that can be found
at http://github.com/pasky/aJson as of 2013-05-30.
Please refer to the PubNubJson example description for some important
notes, especially regarding memory saving on Arduino Uno/Duemilanove.
You can also save some RAM by not using WiFi password protection.
created 30 May 2013
by Petr Baudis
https://github.com/pubnub/pubnub-api/tree/master/arduino
This code is in the public domain.
*/
#include <SPI.h>
#include <WiFi.h>
#include <PubNub.h>
#include <aJSON.h>
static char ssid[] = "NetSSID_Name"; // your network SSID (name)
static char pass[] = "NetworkdPassword"; // your network password
static int keyIndex = 0; // your network key Index number (needed only for WEP)
const static char pubkey[] = "pub-c-51eb45ec-b647-44da-b2aa-9bf6b0b98705";
const static char subkey[] = "sub-c-7e78ed9c-991d-11e4-9946-02ee2ddab7fe";
const static char channel[] = "testing";
#define NUM_CHANNELS 4 // How many analog channels do you want to read?
const static uint8_t analog_pins[] = {23, 24, 25, 26}; // which pins are you reading?
void setup()
{
Serial.begin(9600);
Serial.println("Start WiFi");
WiFi.begin(ssid, pass);
while(WiFi.localIP() == INADDR_NONE) {
Serial.print(".");
delay(300);
}
Serial.println("WiFi set up");
PubNub.begin(pubkey, subkey);
Serial.println("PubNub set up");
delay(5000);
}
void loop()
{
WiFiClient *client;
// create JSON objects
aJsonObject *msg, *analogReadings;
msg = aJson.createObject();
aJson.addItemToObject(msg, "analogReadings", analogReadings = aJson.createObject());
// get latest sensor values then add to JSON message
/*for (int i = 0; i < NUM_CHANNELS; i++) {
String analogChannel = String(analog_pins[i]);
char charBuf[analogChannel.length()+1];
analogChannel.toCharArray(charBuf, analogChannel.length()+1);
int analogValues = analogRead(analog_pins[i]);
aJson.addNumberToObject(analogReadings, charBuf, analogValues);
}*/
// convert JSON object into char array, then delete JSON object
char *json_String = aJson.print(msg);
aJson.deleteItem(msg);
// publish JSON formatted char array to PubNub
Serial.print("publishing a message: ");
Serial.println(json_String);
Serial.println(channel);
client = PubNub.publish(channel, json_String);
Serial.println(*client);
free(json_String);
if (!client) {
Serial.println("publishing error");
delay(1000);
return;
}
client->stop();
delay(500);
}
//- See more at: http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/#sthash.tbQXMIzw.dpuf发布于 2015-01-11 18:29:59
首先,要验证您的PubNub帐户是否配置正确,并且您的本地Wi连接正常,您是否能够在一个浏览器中发布来自开发控制台的消息,并在另一个浏览器上的开发控制台中接收消息?(当然,两者都使用相同的频道名称)。如果这是可行的,请发送一条信息,以帮助(在) pubnub (点) com与您的子键信息和您的项目信息,我们将尽力帮助您跟踪问题。
https://stackoverflow.com/questions/27882739
复制相似问题