//#include <KeyboardLayout.h>
//#include <Keyboard.h>
//Include the needed library, we will use softer serial communication with the ESP8266
#include <SoftwareSerial.h>
//#include <avr/power.h>
//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //sometimes the LCD adress is not 0x3f. Change to 0x27 if it dosn't work.
//Define the used
#define ESP8266_RX 10 //Connect the TX pin from the ESP to this RX pin of the Arduino
#define ESP8266_TX 11 //Connect the TX pin from the Arduino to the RX pin of ESP
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int Potentiometer_1 = 22;
int Potentiometer_2 = 23;
int Potentiometer_3 = 24;
int Potentiometer_4 = 25;
int switch1 = 7;
int switch2 = 8;
int switch3 = 9;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Variables you must change according to your values/////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add your data: SSID + KEY + host + location + id + password
//////////////////////////////////////////////
const char SSID_ESP[] = "Brainycube"; //Give EXACT name of your WIFI
const char SSID_KEY[] = "Sunway@123"; //Add the password of that WIFI connection
const char* host = "https://homiecube.000webhostapp.com"; //Add the host without "www" Example: electronoobs.com
String NOOBIX_id = "99999"; //This is the ID you have on your database, I've used 99999 becuase there is a maximum of 5 characters
String NOOBIX_password = "12345"; //Add the password from the database, also maximum 5 characters and only numerical values
String location_url = "/TX.php?id="; //location of your PHP file on the server. In this case the TX.php is directly on the first folder of the server
//If you have the files in a different folder, add thas as well, Example: "/ESP/TX.php?id=" Where the folder is ESP
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Used variables in the code
String url = "";
String URL_withPacket = "";
unsigned long multiplier[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
//MODES for the ESP
const char CWMODE = '1';//CWMODE 1=STATION, 2=APMODE, 3=BOTH
const char CIPMUX = '1';//CWMODE 0=Single Connection, 1=Multiple Connections
//Define the used functions later in the code, thanks to Kevin Darrah, YT channel: https://www.youtube.com/user/kdarrah1234
boolean setup_ESP();
boolean read_until_ESP(const char keyword1[], int key_size, int timeout_val, byte mode);
void timeout_start();
boolean timeout_check(int timeout_ms);
void serial_dump_ESP();
boolean connect_ESP();
void connect_webhost();
unsigned long timeout_start_val;
char scratch_data_from_ESP[20];//first byte is the length of bytes
char payload[200];
byte payload_size = 0, counter = 0;
char ip_address[16];
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Variable to SEND to the DATABASE
bool sent_bool_1 = 0;
bool sent_bool_2 = 0;
bool sent_bool_3 = 0;
int sent_nr_1 = 0;
int sent_nr_2 = 0;
int sent_nr_3 = 0;
int sent_nr_4 = 0;
int sent_nr_5 = 0;
//Variable RECEIVED from the DATABASE
bool received_bool_1 = 0;
bool received_bool_2 = 0;
bool received_bool_3 = 0;
bool received_bool_4 = 0;
bool received_bool_5 = 0;
int received_nr_1 = 0;
int received_nr_2 = 0;
int received_nr_3 = 0;
int received_nr_4 = 0;
int received_nr_5 = 0;
String received_text = "";
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Store received chars in this variables
char t1_from_ESP[5]; //For time from web
char d1_from_ESP[2]; //For received_bool_2
char d2_from_ESP[2]; //For received_bool_2
char d3_from_ESP[2]; //For received_bool_3
char d4_from_ESP[2]; //For received_bool_4
char d5_from_ESP[2]; //For received_bool_5
char d9_from_ESP[6]; //For received_nr_1
char d10_from_ESP[6]; //For received_nr_2
char d11_from_ESP[6]; //For received_nr_3
char d12_from_ESP[6]; //For received_nr_4
char d13_from_ESP[6]; //For received_nr_5
char d14_from_ESP[300]; //For received_text
//DEFINE KEYWORDS HERE
const char keyword_OK[] = "OK";
const char keyword_Ready[] = "Ready";
const char keyword_no_change[] = "no change";
const char keyword_blank[] = "#&";
const char keyword_ip[] = "192.";
const char keyword_rn[] = "\r\n";
const char keyword_quote[] = "\"";
const char keyword_carrot[] = ">";
const char keyword_sendok[] = "SEND OK";
const char keyword_linkdisc[] = "Unlink";
const char keyword_t1[] = "t1";
const char keyword_b1[] = "b1";
const char keyword_b2[] = "b2";
const char keyword_b3[] = "b3";
const char keyword_b4[] = "b4";
const char keyword_b5[] = "b5";
const char keyword_n1[] = "n1";
const char keyword_n2[] = "n2";
const char keyword_n3[] = "n3";
const char keyword_n4[] = "n4";
const char keyword_n5[] = "n5";
const char keyword_n6[] = "n6";
const char keyword_doublehash[] = "##";
SoftwareSerial ESP8266(ESP8266_RX, ESP8266_TX);// rx tx
void setup() { // SETUP START
lcd.init(); //Init the LCD
lcd.backlight(); //Activate backlight
//Pin Modes for ESP TX/RX
pinMode(ESP8266_RX, INPUT);
pinMode(ESP8266_TX, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(Potentiometer_1, INPUT);
pinMode(Potentiometer_2, INPUT);
pinMode(Potentiometer_3, INPUT);
pinMode(Potentiometer_4, INPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
ESP8266.begin(9600);//default baudrate for ESP
ESP8266.listen();//not needed unless using other software serial instances
Serial.begin(9600); //for status and debug
delay(2000);//delay before kicking things off
setup_ESP();//go setup the ESP
}
void loop() {
sent_nr_1 = analogRead(Potentiometer_1);
sent_nr_1 = analogRead(Potentiometer_2);
sent_nr_1 = analogRead(Potentiometer_3);
sent_nr_1 = analogRead(Potentiometer_4);
sent_bool_1 = digitalRead(switch1);
sent_bool_2 = digitalRead(switch2);
sent_bool_3 = digitalRead(switch3);
send_to_server_1();
digitalWrite(LED1, received_bool_1);
digitalWrite(LED2, received_bool_2);
digitalWrite(LED3, received_bool_3);
digitalWrite(LED4, received_bool_4);
digitalWrite(LED5, received_bool_5);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0, 1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);//5 seconds between tries
/*
send_to_server_2();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
send_to_server_3();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
send_to_server_4();
digitalWrite(LED1,received_bool_1);
digitalWrite(LED2,received_bool_2);
digitalWrite(LED3,received_bool_3);
digitalWrite(LED4,received_bool_4);
digitalWrite(LED5,received_bool_5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("N1: "); lcd.print(received_nr_1); lcd.print(" N2: "); lcd.print(received_nr_2);
lcd.setCursor(0,1);
lcd.print("N3: "); lcd.print(received_nr_3); lcd.print(" N4: "); lcd.print(received_nr_4);
delay(1000);
*/
send_to_server_5();
digitalWrite(LED1, received_bool_1);
digitalWrite(LED2, received_bool_2);
digitalWrite(LED3, received_bool_3);
digitalWrite(LED4, received_bool_4);
digitalWrite(LED5, received_bool_5);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(received_text);
delay(1000);
}//End of the main loop
ERROR
home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/MAIN_ESP8266.ino:148:16: note: in expansion of macro 'ESP8266'
148 | SoftwareSeriaPreformatted textl ESP8266(ESP8266_RX, ESP8266_TX);// rx tx
| ^~~~~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/MAIN_ESP8266.ino: In function 'void setup()':
MAIN_ESP8266:183:11: error: request for member 'begin' in '1', which is of non-class type 'int'
183 | ESP8266.begin(9600);//default baudrate for ESP
| ^~~~~
MAIN_ESP8266:184:11: error: request for member 'listen' in '1', which is of non-class type 'int'
184 | ESP8266.listen();//not needed unless using other software serial instances
| ^~~~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/connect_ESP.ino: In function 'boolean connect_ESP()':
connect_ESP:7:11: error: request for member 'print' in '1', which is of non-class type 'int'
7 | ESP8266.print("AT+CIPSTART=0,\"TCP\",\"www.homiecube.000webhostapp.com\",80\r\n");//connect to your web server
| ^~~~~
connect_ESP:14:11: error: request for member 'print' in '1', which is of non-class type 'int'
14 | ESP8266.print("AT+CIPSEND=0,");//send AT+CIPSEND=0, size of payload
| ^~~~~
connect_ESP:15:11: error: request for member 'print' in '1', which is of non-class type 'int'
15 | ESP8266.print(payload_size);//the payload size
| ^~~~~
connect_ESP:17:11: error: request for member 'print' in '1', which is of non-class type 'int'
17 | ESP8266.print("\r\n\r\n");//cap off that command with a carriage return and new line feed
| ^~~~~
connect_ESP:26:13: error: request for member 'print' in '1', which is of non-class type 'int'
26 | ESP8266.print(payload[i]);
| ^~~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/read_until_ESP.ino: In function 'boolean read_until_ESP(const char*, int, int, byte)':
read_until_ESP:18:28: error: request for member 'available' in '1', which is of non-class type 'int'
18 | while(!ESP8266.available()){//wait until a new byte is sent down from the ESP - good way to keep in lock-step with the serial port
| ^~~~~~~~~
read_until_ESP:25:24: error: request for member 'read' in '1', which is of non-class type 'int'
25 | data_in[i]=ESP8266.read();// save the byte to the buffer 'data_in[]
| ^~~~
read_until_ESP:56:28: error: request for member 'available' in '1', which is of non-class type 'int'
56 | while(!ESP8266.available()){// same thing as done in the buffer
| ^~~~~~~~~
read_until_ESP:65:33: error: request for member 'read' in '1', which is of non-class type 'int'
65 | data_in[key_size-1]=ESP8266.read();//save the new data in the last position in the buffer
| ^~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/serial_dump_ESP.ino: In function 'void serial_dump_ESP()':
serial_dump_ESP:5:17: error: request for member 'available' in '1', which is of non-class type 'int'
5 | while(ESP8266.available()){
| ^~~~~~~~~
serial_dump_ESP:6:19: error: request for member 'read' in '1', which is of non-class type 'int'
6 | temp =ESP8266.read();
| ^~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/setup_ESP.ino: In function 'boolean setup_ESP()':
setup_ESP:3:11: error: request for member 'print' in '1', which is of non-class type 'int'
3 | ESP8266.print("AT\r\n");// Send just 'AT' to make sure the ESP is responding
| ^~~~~
setup_ESP:11:12: error: request for member 'print' in '1', which is of non-class type 'int'
11 | ESP8266.print("AT+RST\r\n");// Give it a reset - who knows what condition it was in, better to start fresh
| ^~~~~
setup_ESP:19:12: error: request for member 'print' in '1', which is of non-class type 'int'
19 | ESP8266.print("AT+CWMODE=");// set the CWMODE
| ^~~~~
setup_ESP:20:12: error: request for member 'print' in '1', which is of non-class type 'int'
20 | ESP8266.print(CWMODE);//just send what is set in the constant
| ^~~~~
setup_ESP:21:12: error: request for member 'print' in '1', which is of non-class type 'int'
21 | ESP8266.print("\r\n");
| ^~~~~
setup_ESP:29:12: error: request for member 'print' in '1', which is of non-class type 'int'
29 | ESP8266.print("AT+CWJAP=\"");// set the SSID AT+CWJAP="SSID","PW"
| ^~~~~
setup_ESP:30:12: error: request for member 'print' in '1', which is of non-class type 'int'
30 | ESP8266.print(SSID_ESP);//from constant
| ^~~~~
setup_ESP:31:12: error: request for member 'print' in '1', which is of non-class type 'int'
31 | ESP8266.print("\",\"");
| ^~~~~
setup_ESP:32:12: error: request for member 'print' in '1', which is of non-class type 'int'
32 | ESP8266.print(SSID_KEY);//form constant
| ^~~~~
setup_ESP:33:12: error: request for member 'print' in '1', which is of non-class type 'int'
33 | ESP8266.print("\"\r\n");
| ^~~~~
setup_ESP:42:11: error: request for member 'print' in '1', which is of non-class type 'int'
42 | ESP8266.print("AT+CIFSR\r\n");//command to retrieve IP address from ESP
| ^~~~~
setup_ESP:61:12: error: request for member 'print' in '1', which is of non-class type 'int'
61 | ESP8266.print("AT+CIPMUX=");// set the CIPMUX
| ^~~~~
setup_ESP:62:12: error: request for member 'print' in '1', which is of non-class type 'int'
62 | ESP8266.print(CIPMUX);//from constant
| ^~~~~
exit status 1
request for member 'begin' in '1', which is of non-class type 'int'
Try calling it something else, maybe like "esp82xx"
now its throwing error like this
MAIN_ESP8266:148:23: error: 'SoftwareSerial esp8266' redeclared as different kind of entity
148 | SoftwareSerial esp8266(esp8266_RX, esp8266_TX);// rx tx
| ^
In file included from /home/udit/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h:42,
from sketch/MAIN_ESP8266.ino.cpp:1:
/home/udit/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/core_esp8266_version.h:121:11: note: previous declaration 'namespace esp8266 { }'
121 | namespace esp8266 {
| ^~~~~~~
/home/udit/Desktop/HomeAutomationSystem/ESP_tutorial/MAIN_ESP8266/MAIN_ESP8266.ino: In function 'void setup()':
MAIN_ESP8266:183:10: error: expected primary-expression before '.' token
183 | esp8266.begin(9600);//default baudrate for ESPPreformatted text
...and that why I wrote "esp82xx"
what shall i do now?
In the Arduino IDE, make sure Tools > Board is set to "Arduino Mega or Mega 2560"
1 Like
Now finally worked .But data is not being sent to server using ESP8266.Initially, I had selected Generic ESP8266 module as a board
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.