0

I am new to using NodeMCU and IOT. I am testing the NodeMCU (ESP8266) so that I can connect with pubnub server. Have taken code from github but there is error saying

'mac was not declared in this scope' 

and some other error too.

Can anyone tell whats the problem?

This code is from pubnub github page - https://github.com/pubnub/arduino

Code:-

#include <Ethernet.h>
#include <PubNub.h>
void setup() {
 /* For debugging, set to speed of your choice */
 Serial.begin(9600);
 /* If you use some other HW, you need to do some other
 initialization of it here... */
 Ethernet.begin();
 /* Start the Pubnub library by giving it a publish and subscribe
 keys */
 PubNub.begin(publisher key, subscriber key);
}
void loop() {
 /* Maintain DHCP lease. For other HW, you may need to do
 something else here, or maybe nothing at all. */
 Ethernet.maintain();
 /* Publish message. You could use `auto` here... */
 PubNonSubClient *pclient = PubNub.publish(pubchannel, "\"message\"");
 if (!pclient) return;
 PublishCracker cheez;
 cheez.read_and_parse(pclient);
 /** 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()));
 pclient->stop();
 /* Wait for news. */
 PubSubClient *sclient = PubNub.subscribe(subchannel);
 if (!sclient) return; // error
 String msg;
 SubscribeCracker ritz(sclient);
 while (!ritz.finished()) {
 ritz.get(msg);
 if (msg.length() > 0) {
 Serial.print("Received: "); Serial.println(msg);
 }
 }
 sclient->stop();
 delay(1000);
}
error :-
 sketch_jan17a:28:47: error: 'pubchannel' was not declared in this scope
 PubNonSubClient *pclient = PubNub.publish(pubchannel, "\"message\"");
 ^
sketch_jan17a:44:46: error: 'subchannel' was not declared in this scope
 PubSubClient *sclient = PubNub.subscribe(subchannel);
 ^
Multiple libraries were found for "Ethernet.h"
 Used: C:\Users\sultan\AppData\Local\Arduino15\packages\esp8266\hardware\esp82662円.5.0-beta2\libraries\Ethernet
 Not used: C:\Program Files (x86)\Arduino\libraries\Ethernet
exit status 1
'mac' was not declared in this scope
Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Jan 17, 2019 at 14:53
0

1 Answer 1

2

I don't believe you have an Wiznet Ethernet module connected to your NodeMcu. Ethernet library is for the Wiznet chips for wired LAN. You want to use the WiFi of the NodeMcu. For that the esp8266 core has the ESP8266WiFi library. It has the same API as other WiFi libraries based on Arduino WiFi library. So you can modify the WiFi examples of the Arduino pubnub library. Only change #include <WiFi101.h> to #include <ESP8266WiFi.h>. (And remove #include <SPI.h>.)

answered Jan 17, 2019 at 16:20
3
  • yes no error after doing it. But now it says "Error compiling for board NodeMCU 1.0 (ESP-12E Module)." Mine is node mcu 2 but can;t find it in the board setting. what to do? Commented Jan 19, 2019 at 14:30
  • if it is ""Error compiling..." then there is some compilation error Commented Jan 19, 2019 at 14:47
  • no worries, got it Commented Jan 19, 2019 at 14:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.