Below code was working fine without using classes, after using class an error pops up: esp8266 is not defined in this scope
#include<SoftwareSerial.h>
#include<ArduinoJson.h>
#include<Wire.h>
#include<LCD.h>
#include<LiquidCrystal_I2C.h>
#include<SPI.h>
#define DEBUG true
// Housekeeping stuff for LCD display
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C
lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
class baseFunctions {
public:
baseFunctions() {
Serial.begin(115200); // Housekeeping stuff
esp8266.begin(115200); // Housekeeping stuff
sendData("AT+RST\r\n", 2000, DEBUG); // reset module
// Code for display
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH); // Switch on the backlight
lcd.home (); // go home
lcd.print("In development");
pinMode(8, OUTPUT);
}
String sendData(String command, const int timeout, boolean debug) {
String response = "";
esp8266.print(command); // send the read characte to esp8266
long int time = millis();
while ( (time + timeout) > millis() ) {
while (esp8266.available()) {
// The esp has data so display its output to serial window
char c = esp8266.read(); // read the next character
response += c;
}
}
if (debug) {
Serial.print(response);
}
return response;
}
void connectToWifi() {
sendData("AT+CWMODE=1\r\n", 3000, DEBUG); // Configure as clint
sendData("AT+CWJAP=\"moto g\", \"hvats555\"\r\n", 5000, DEBUG); // Connects to wifi
}
String fetchJson() {
StaticJsonBuffer<200> jsonBuffer;
char json[] = "{\"power\":\"high\"}";
JsonObject& root = jsonBuffer.parseObject(json);
const char* power = root["power"];
return power;
}
};
void setup() {
baseFunctions go;
}
void loop() {
}
Here is the error
exit status 1
'esp8266' was not declared in this scope