Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPSPlus.h>
- #include <WiFi.h>
- #include <FirebaseESP32.h>
- #include <addons/TokenHelper.h>
- #include <addons/RTDBHelper.h>
- #define seat_no_1 36
- #define seat_no_2 39
- #define seat_no_3 34
- #define seat_no_4 35
- #define seat_no_5 32
- #define seat_no_6 33
- int seat_no_1_State;
- int seat_no_2_State;
- int seat_no_3_State;
- int seat_no_4_State;
- int seat_no_5_State;
- int seat_no_6_State;
- #define WIFI_SSID "network"
- #define WIFI_PASSWORD "123456789"
- #define API_KEY "AIzaSyAEPYl4Pgt9mA1LDMPObokuEdigGTGLz2Q"
- #define USER_EMAIL "[email protected]"
- #define USER_PASSWORD "123456789"
- #define DATABASE_URL "esp32-project-9ae45-default-rtdb.firebaseio.com"
- #define DATABASE_SECRET "h4EezjpVFqGVowB3a2Y8E0XX0CUCzSQJegn5nyXV"
- char google_maps_link[70];
- String google_maps_link_string = "";
- String Longitude = "1";
- String Latitude = "1";
- FirebaseData fbdo;
- FirebaseAuth auth;
- FirebaseConfig config;
- unsigned long dataMillis = 0;
- int count = 0;
- TinyGPSPlus gps;
- void setup() {
- Serial.begin(9600);
- Serial2.begin(9600);
- connect_WiFi_and_Firebase();
- pinMode(seat_no_1,INPUT);
- pinMode(seat_no_2,INPUT);
- pinMode(seat_no_3,INPUT);
- pinMode(seat_no_4,INPUT);
- pinMode(seat_no_5,INPUT);
- pinMode(seat_no_6,INPUT);
- }
- void loop() {
- seat_no_1_State = digitalRead(seat_no_1);
- seat_no_2_State = digitalRead(seat_no_2);
- seat_no_3_State = digitalRead(seat_no_3);
- seat_no_4_State = digitalRead(seat_no_4);
- seat_no_5_State = digitalRead(seat_no_5);
- seat_no_6_State = digitalRead(seat_no_6);
- read_GPS_receiver();
- send_data_Firebase();
- }
- void read_GPS_receiver() {
- while (Serial2.available() > 0) {
- if (gps.encode(Serial2.read())) {
- if (gps.location.isValid()) {
- Latitude = String(gps.location.lat(), 6);
- Longitude = String(gps.location.lng(), 6);
- Serial.print(Latitude);
- Serial.print(",");
- Serial.print(Longitude);
- Serial.println();
- google_maps_link_string = "http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=" + Latitude + "+" + Longitude;
- google_maps_link_string.toCharArray(google_maps_link, 70);
- }
- else {
- Serial.println(F("INVALID"));
- }
- }
- }
- if (millis() > 5000 && gps.charsProcessed() < 10) {
- Serial.println(F("No GPS detected: check wiring."));
- while (true);
- }
- }
- void connect_WiFi_and_Firebase() {
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- Serial.print("Connecting to Wi-Fi");
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(300);
- }
- Serial.println();
- Serial.print("Connected with IP: ");
- Serial.println(WiFi.localIP());
- Serial.println();
- Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
- config.api_key = API_KEY;
- auth.user.email = USER_EMAIL;
- auth.user.password = USER_PASSWORD;
- config.database_url = DATABASE_URL;
- Firebase.reconnectWiFi(true);
- fbdo.setResponseSize(4096);
- config.token_status_callback = tokenStatusCallback;
- config.max_token_generation_retry = 5;
- Firebase.begin(&config, &auth);
- }
- void send_data_Firebase() {
- if (millis() - dataMillis > 5000 && Firebase.ready())
- {
- dataMillis = millis();
- Serial.printf("Set String... %s\n", Firebase.setString(fbdo, "/Golf_Cart/Latitude/",Latitude.c_str()) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set String... %s\n", Firebase.setString(fbdo, "/Golf_Cart/Longitude/",Longitude.c_str()) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_1/", seat_no_1_State) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_2/", seat_no_2_State) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_3/", seat_no_3_State) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_4/", seat_no_4_State) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_5/", seat_no_5_State) ? "ok" : fbdo.errorReason().c_str());
- Serial.printf("Set Bool... %s\n", Firebase.setInt(fbdo, "/Golf_Cart/Seat_No_6/", seat_no_6_State) ? "ok" : fbdo.errorReason().c_str());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment