how to connect Arduino mega and esp8266 to firebase
please help me
At first, I changed the AT_firmware for esp8266 as shown in the picture
and then I connected the MFRc522 and ultrasonic with the Arduino Mega and it worked fine, but when I used it with the firebase, the following errors appeared to me
In file included from C:\Users\MASADER\Desktop\sketch_feb22a\sketch_feb22a.ino:5:0:
C:\Users\MASADER\Documents\Arduino\libraries\firebase-arduino-master\src/FirebaseHttpClient.h:4:10: fatal error: string: No such file or directory
#include
^~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
The code is
#include "WiFiEsp.h"
#include <SPI.h>
#include <MFRC522.h>
#include <ArduinoJson.h>
#include <FirebaseHttpClient.h>
#include <FirebaseArduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// ********************************************************* DEFINITIONS *********************************************************
char ssid[] = ""; // your network SSID (name)
char pass[] = ""; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
const int trigPin1 = 8;
const int echoPin1 = 9;
const int trigPin2 = 10;
const int echoPin2 = 11;
String CustomerUid;
#define SS_PIN 53
#define RST_PIN 49
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
// set the LCD address to 0x27 for a 20 chars 4 line display
LiquidCrystal_I2C lcd(0x27,16,2);
// ********************************************************* INITIALIZE *********************************************************
void setup() {
Serial.begin(115200); // initialize serial 0 for debugging
Serial1.begin(115200);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
lcd.init();
// Print our characters on the LCD
lcd.backlight(); //Backlight ON if under program control
lcd.setCursor(3,0); //Start at character 3 on line 0
lcd.print("Hello, world!");
delay(1000);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
// initialize serial 1 for ESP module
WiFi.init(&Serial1); // initialize ESP module
if (WiFi.status() == WL_NO_SHIELD) { // check for the presence of the shield
Serial.println("WiFi shield not present"); // If shield not present, don't continue
while (true);
}
while ( status != WL_CONNECTED) { // attempt to connect to WiFi network
Serial.print("Attempting to connect to WPA SSID: "); // Print message to serial monitor
Serial.println(ssid); // Print SSID to serial monitor
status = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network
}
Serial.println("You're connected to the network"); // Print success message to serial monitor
// connect to Firebase.
//Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
//delay(1000);
//Firebase.setString("park/park1/car","1");
//delay(1000);
}
// ********************************************************* MAIN LOOP *********************************************************
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
CustomerUid = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
CustomerUid.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
CustomerUid.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println(CustomerUid);
// Halt PICC
mfrc522.PICC_HaltA();
// check the network connection once every 10 seconds
Serial.println();
//printCurrentNet();
//printWifiData();
Serial.println(getDistanceCm(trigPin1, echoPin1));
delay(1000);
Serial.println(getDistanceCm(trigPin2, echoPin2));
}
// ********************************************************* FUNCTION DEFINITIONS *********************************************************
// Print WiFi data to serial Monitor --------------------------------------------------------
void printWifiData()
{
// *** print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// *** print your MAC address
byte mac[6];
WiFi.macAddress(mac);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
// Print WiFi connection details to serial Monitor --------------------------------------------------------
void printCurrentNet()
{
// *** print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// *** print the MAC address of the router you're attached to
byte bssid[6];
WiFi.BSSID(bssid);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
Serial.print("BSSID: ");
Serial.println(buf);
// *** print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.println(rssi);
}
int getDistanceCm(const int trigPin, const int echoPin){
int distanceCm;
long duration;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);// Returns the duration in microseconds or gives up and returns 0 if no complete pulse was received within the timeout.
distanceCm = duration*0.034/2;
if(distanceCm <= 2)
return 0;
else
return distanceCm;
}