c_cpp ESPn66的Pubnub Arduino SDK代码示例。演示发布和订阅。从PubNub Developer Portal获取您唯一的PubNub密钥
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp ESPn66的Pubnub Arduino SDK代码示例。演示发布和订阅。从PubNub Developer Portal获取您唯一的PubNub密钥相关的知识,希望对你有一定的参考价值。
#include <ESP8266WiFi.h>
#define PubNub_BASE_CLIENT WiFiClient
#include <PubNub.h>
const char* ssid = "your-ssid";
const char* password = "your-password";
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, pass);
if(WiFi.waitForConnectResult() == WL_CONNECTED){
PubNub.begin("pub-key", "sub-key");
} else {
Serial.println("Couldn't get a wifi connection");
while(1) delay(100);
}
}
void loop() {
PubNub_BASE_CLIENT *client;
Serial.println("publishing a message");
client = PubNub.publish(channel, "\"\\\"Hello world!\\\" from Arduino.\"");
if (!client) {
Serial.println("publishing error");
delay(1000);
return;
}
while (client->connected()) {
while (client->connected() && !client->available());
char c = client->read();
Serial.print(c);
}
client->stop();
Serial.println();
Serial.println("waiting for a message (subscribe)");
PubSubClient *pclient = PubNub.subscribe(channel);
if (!pclient) {
Serial.println("subscription error");
delay(1000);
return;
}
while (pclient->wait_for_data()) {
char c = pclient->read();
Serial.print(c);
}
pclient->stop();
Serial.println();
}
以上是关于c_cpp ESPn66的Pubnub Arduino SDK代码示例。演示发布和订阅。从PubNub Developer Portal获取您唯一的PubNub密钥的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp 每分钟读取一次当前UV索引级别,并在值更改时将值发布到PubNub,并且每10分钟至少发布一次
c_cpp 66.加一
c_cpp #66加一
c_cpp 66.cpp
c_cpp 66.加上One-DifficultyEasy - 2018.8.17
带有 PubNub 的 Socket.io ......为啥?