daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #define PubNub_BASE_CLIENT WiFiClient
  3. #define PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP
  4.  
  5. #include <PubNub.h>
  6.  
  7. String pubkey = "pub-c-4a9cdbca-5688-4939-a852-f63cf6743980";
  8. String subkey = "sub-c-9b4067ae-1293-11e9-b4a6-026d6924b094";
  9. String pubchannel = "sec-c-NmFiYjliODYtMTc3Mi00YTMzLTg0OWMtMDgzYjE2ZGUwNzg5";
  10.  
  11. void setup() {
  12.     /* For debugging, set to speed of your choice */
  13.     Serial.begin(9600);
  14.  
  15.  
  16.     /* Start the Pubnub library by giving it a publish and subscribe
  17.        keys */
  18.     PubNub.begin(pubkey, subkey);
  19. }
  20.  
  21. void loop() {
  22.     /* Maintain DHCP lease. For other HW, you may need to do
  23.        something else here, or maybe nothing at all. */
  24.  
  25.  
  26.     /* Publish message. You could use `auto` here... */
  27.     PubNonSubClient *pclient = PubNub.publish(pubchannel, ""message"");
  28.     if (!pclient) return;
  29.     PublishCracker cheez;
  30.     cheez.read_and_parse(pclient);
  31.     /** You're mostly interested in `outcome()`, and,
  32.         if it's "failed", then `description()`.
  33.     */
  34.     Serial.print("Outcome: "); Serial.print(cheez.outcome());
  35.     Serial.print(' '); Serial.println(cheez.to_str(cheez.outcome()));
  36.     Serial.print("description: "); Serial.println(cheez.description());
  37.     Serial.print("timestamp: "); Serial.println(cheez.timestamp());
  38.     Serial.print("state: "); Serial.print(cheez.state());
  39.     Serial.print(' '); Serial.println(cheez.to_str(cheez.state()));
  40.     pclient->stop();
  41.  
  42.     /* Wait for news. */
  43.     PubSubClient *sclient = PubNub.subscribe(subchannel);
  44.     if (!sclient) return; // error
  45.     String msg;
  46.     SubscribeCracker ritz(sclient);
  47.     while (!ritz.finished()) {
  48.         ritz.get(msg);
  49.         if (msg.length() > 0) {
  50.             Serial.print("Received: "); Serial.println(msg);
  51.         }
  52.     }
  53.     sclient->stop();
  54.  
  55.     delay(1000);
  56. }
  57.  
  58. Error:-
  59. node_mcu_test_code:44:46: error: 'subchannel' was not declared in this scope
  60.  
  61.      PubSubClient *sclient = PubNub.subscribe(subchannel);
  62.  
  63.                                               ^
  64.  
  65. node_mcu_test_code:54:14: error: 'class PubSubClient' has no member named 'stop'
  66.  
  67.      sclient->stop();
  68.  
  69.               ^
  70.  
  71. exit status 1
  72. no matching function for call to 'PubNub::begin(String&, String&)'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top