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
1 Answer 1
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>
.)
-
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?Sultan Morbiwala– Sultan Morbiwala01/19/2019 14:30:38Commented Jan 19, 2019 at 14:30
-
if it is ""Error compiling..." then there is some compilation error01/19/2019 14:47:47Commented Jan 19, 2019 at 14:47
-
no worries, got itSultan Morbiwala– Sultan Morbiwala01/19/2019 14:50:08Commented Jan 19, 2019 at 14:50