无法在 PUBNUB 上发布来自 CC3100 + MSP430F5529 的数据
Can't publish data from CC3100 + MSP430F5529 on PUBNUB
我遵循了以下教程:http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/
一步一步,我设法编译和编码并连接到我的 Wi-Fi 接入点。
我想我成功连接到了 PubNub(代码在终端屏幕上打印“PubNub 设置”,但在代码中没有真正验证它确实已设置。
我在 PubNub 上开设了一个帐户,并将我的频道命名为“测试”(我在上传的代码中将其命名为相同的名称 - 我检查了一百万次),当我转到 Dev Console 并单击订阅时我什么也看不见!我的意思是我可以通过 Dev Console post 消息,但我真正想看到的是来自 CC3100 的消息。
我检查了我电脑上的 UART 终端,我看到数据不断打印,所以我知道它正在工作。
我一遍又一遍地浏览教程,我在做同样的事情,但它就是行不通。
如有任何帮助,我们将不胜感激!
我错过了什么?
谢谢
首先要验证您的 PubNub 帐户是否已正确配置并且您的本地 Wi-Fi 连接是否正常 - 您是否能够在一个浏览器中从开发控制台发布消息并在另一个浏览器的开发控制台中接收它们? (当然,两者都使用相同的频道名称)。如果可行,请发送消息至 help (at) pubnub (dot) com,并提供您的子密钥信息和有关您的项目的信息,我们将尽力帮助您追踪问题。
这个答案 post 编得真晚。我承认我忘记了这个 post 所以我决定更新它(虽然晚了几年)。
我开始挖掘,试图找出问题所在,我想我找到了。首先,我看到 PubNub.publish() 无法与 json_String 一起正常工作,因为 json_String 有 90% 是乱码。所以我删除了大部分构造 json_String 的代码(插入模拟值的部分)并使其更简单。
然后我还在末尾添加了一部分代码,这是客户端变量的正确性能所需要的,我从一部分代码中提取了一部分代码,该代码用于使用 CC3100 的基于 arduino 的项目。
无论如何,新代码是下面的代码,现在可以正常工作了!我终于在 PubNub 上看到了所有的输入流!非常感谢! :D
/*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
我遵循了以下教程:http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/ 一步一步,我设法编译和编码并连接到我的 Wi-Fi 接入点。 我想我成功连接到了 PubNub(代码在终端屏幕上打印“PubNub 设置”,但在代码中没有真正验证它确实已设置。
我在 PubNub 上开设了一个帐户,并将我的频道命名为“测试”(我在上传的代码中将其命名为相同的名称 - 我检查了一百万次),当我转到 Dev Console 并单击订阅时我什么也看不见!我的意思是我可以通过 Dev Console post 消息,但我真正想看到的是来自 CC3100 的消息。 我检查了我电脑上的 UART 终端,我看到数据不断打印,所以我知道它正在工作。 我一遍又一遍地浏览教程,我在做同样的事情,但它就是行不通。 如有任何帮助,我们将不胜感激!
我错过了什么?
谢谢
首先要验证您的 PubNub 帐户是否已正确配置并且您的本地 Wi-Fi 连接是否正常 - 您是否能够在一个浏览器中从开发控制台发布消息并在另一个浏览器的开发控制台中接收它们? (当然,两者都使用相同的频道名称)。如果可行,请发送消息至 help (at) pubnub (dot) com,并提供您的子密钥信息和有关您的项目的信息,我们将尽力帮助您追踪问题。
这个答案 post 编得真晚。我承认我忘记了这个 post 所以我决定更新它(虽然晚了几年)。
我开始挖掘,试图找出问题所在,我想我找到了。首先,我看到 PubNub.publish() 无法与 json_String 一起正常工作,因为 json_String 有 90% 是乱码。所以我删除了大部分构造 json_String 的代码(插入模拟值的部分)并使其更简单。 然后我还在末尾添加了一部分代码,这是客户端变量的正确性能所需要的,我从一部分代码中提取了一部分代码,该代码用于使用 CC3100 的基于 arduino 的项目。
无论如何,新代码是下面的代码,现在可以正常工作了!我终于在 PubNub 上看到了所有的输入流!非常感谢! :D
/*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