I have node mcu and i am trying to use the example code on github and pubnub blog to send a msg as an experiment but can't figure how to do it.

I used 2 example as the reference - https://github.com/pubnub/arduino , https://www.pubnub.com/docs/arduino/data-streams-publish-and-subscribe

Here is the code which i have. I modified it to include some libraries and my API keys. Let me know what changes i have to make:-

#include <ESP8266WiFi.h>
#define PubNub_BASE_CLIENT WiFiClient

#include <PubNub.h>

String pubkey = "pub-c-4a9cdbca-5688-4939-a852-f63cf6743980";
String subkey = "sub-c-9b4067ae-1293-11e9-b4a6-026d6924b094";
String pubchannel = "sec-c-NmFiYjliODYtMTc3Mi00YTMzLTg0OWMtMDgzYjE2ZGUwNzg5";

void setup() {
    /* For debugging, set to speed of your choice */

    /* Start the Pubnub library by giving it a publish and subscribe
       keys */
    PubNub.begin(pubkey, subkey);

void loop() {
    /* Maintain DHCP lease. For other HW, you may need to do
       something else here, or maybe nothing at all. */

    /* Publish message. You could use `auto` here... */
    PubNonSubClient *pclient = PubNub.publish(pubchannel, "\"message\"");
    if (!pclient) return;
    PublishCracker cheez;
    /** You're mostly interested in `outcome()`, and,
        if it's "failed", then `description()`. 
    Serial.print("Outcome: "); Serial.print(cheez.outcome());
    Serial.print(' '); Serial.println(cheez.to_str(cheez.outcome()));
    Serial.print("description: "); Serial.println(cheez.description());
    Serial.print("timestamp: "); Serial.println(cheez.timestamp());
    Serial.print("state: "); Serial.print(cheez.state());
    Serial.print(' '); Serial.println(cheez.to_str(cheez.state()));

    /* Wait for news. */
    PubSubClient *sclient = PubNub.subscribe(subchannel);
    if (!sclient) return; // error
    String msg;
    SubscribeCracker ritz(sclient);
    while (!ritz.finished()) {
        if (msg.length() > 0) {
            Serial.print("Received: "); Serial.println(msg);


node_mcu_test_code:44:46: error: 'subchannel' was not declared in this scope

     PubSubClient *sclient = PubNub.subscribe(subchannel);


node_mcu_test_code:54:14: error: 'class PubSubClient' has no member named 'stop'



exit status 1
no matching function for call to 'PubNub::begin(String&, String&)'
  • 1
    what is subchannel? pubchannel?
    – Juraj
    Jan 19, 2019 at 17:30
  • #include <PubSubClient.h> - why? no demos or docs say you need to do that Jan 20, 2019 at 0:15
  • <PubSubClient> is what I found in old forums so put that just for checking. I specified sub and pubchannel with API key. If not like that then how to do it. Jan 20, 2019 at 18:16
  • is what I found in old forums so put that just for checking don't add things without knowing what they do Jan 21, 2019 at 5:42
  • also, you've not declared a variable called subchannel ... yet you try to use a variable called subchannel ... which is why you get an error that states error: 'subchannel' was not declared in this scope - because it isn't Jan 21, 2019 at 5:43

1 Answer 1


The pubchannel and subchannel can be defined as any values in char variable.

Here is the right code:-

const char * pubkey = "publisher key from your account";
const char * subkey = "subscriber key from your account";

const char * pubchannel = "demo_keyset";
const char * subchannel = "demo_keyset";

Then the error disappeared

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.