ESP8266 NodeMCU and MPU6050 accelerometer sensor data transfer to Firestore

I am trying to write a code that will transfer data from firebase database to cloud firestore every two minutes for 2 seconds using ESP8266 NodeMCU and MPU6050 accelerometer. but when I run the code I get an error like this:

Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: TOO_MANY_ATTEMPTS_TRY_LATER : Access to this account has been temporarily disabled due to many failed login attempts. You can immediately restore it by resetting your password or you can try again later.
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: bad request

The code I wrote is as follows:

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>

// good connection for database
#include "addons/TokenHelper.h"

#define FIREBASE_AUTH "xxxxxxxx"

// wifi info
#define WIFI_SSID "xxxxxxxx"
#define WIFI_PASSWORD "xxxxxxxxx"

// Firebase project API Key
#define API_KEY "xxxxxxxxxxx"

// project ID
#define FIREBASE_PROJECT_ID "xxxxxxxx"

// database url
#define DATABASE_URL "xxxxxxxxxxxx"

//user e mail
#define USER_EMAIL "xxxxxxxxxx"
#define USER_PASSWORD "xxxxxxxxxxx"

// Firebase data object
FirebaseData fbdo;
// auth
FirebaseAuth auth;
FirebaseConfig config;

Adafruit_MPU6050 mpu;
FirebaseData firebaseData;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    delay(10); 

  Serial.println("Adafruit MPU6050 test!");

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  mpu.setAccelerometerRange(MPU6050_RANGE_4_G);
  Serial.print("Accelerometer range set to: ");
  switch (mpu.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.println("+-2G");
    break;
  case MPU6050_RANGE_4_G:
    Serial.println("+-4G");
    break;
  case MPU6050_RANGE_8_G:
    Serial.println("+-8G");
    break;
  case MPU6050_RANGE_16_G:
    Serial.println("+-16G");
    break;
  }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  Serial.print("Gyro range set to: ");
  switch (mpu.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.println("+- 250 deg/s");
    break;
  case MPU6050_RANGE_500_DEG:
    Serial.println("+- 500 deg/s");
    break;
  case MPU6050_RANGE_1000_DEG:
    Serial.println("+- 1000 deg/s");
    break;
  case MPU6050_RANGE_2000_DEG:
    Serial.println("+- 2000 deg/s");
    break;
  }

  mpu.setFilterBandwidth(MPU6050_BAND_260_HZ);
  Serial.print("Filter bandwidth set to: ");
  switch (mpu.getFilterBandwidth()) {
  case MPU6050_BAND_260_HZ:
    Serial.println("260 Hz");
    break;
  case MPU6050_BAND_184_HZ:
    Serial.println("184 Hz");
    break;
  case MPU6050_BAND_94_HZ:
    Serial.println("94 Hz");
    break;
  case MPU6050_BAND_44_HZ:
    Serial.println("44 Hz");
    break;
  case MPU6050_BAND_21_HZ:
    Serial.println("21 Hz");
    break;
  case MPU6050_BAND_10_HZ:
    Serial.println("10 Hz");
    break;
  case MPU6050_BAND_5_HZ:
    Serial.println("5 Hz");
    break;
  }

  Serial.println("");
  delay(100);

  Serial.println("Accelerometer Test"); Serial.println("");

  // Wi-Fi bağlantısı
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Ağa Bağlanıyor");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Bağlandı. IP Adresi: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  // MPU6050 başlat
  mpu.begin();

  // Print Firebase client version
  Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

  // API Key paylaşımı
  config.api_key = API_KEY;

  // Kullanıcı oturum açma kimlik bilgilerinin paylaşımı
  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  // Token callback
  config.token_status_callback = tokenStatusCallback;  // see addons/TokenHelper.h

  // Firebase'i başlatma
  Firebase.begin(&config, &auth);

  // Gerek duyulursa Wi-Fi yeniden başlatma
  Firebase.reconnectWiFi(true);
}

void loop() {
  // firestore döküman yolu oluşturma
  String documentPath = "VibrationData/MPU6050";

  //Depolanan veri için FirebaseJson nesnesi oluşturma
  FirebaseJson content;

  // Read temperature, acceleration and gyro from the MPU6050 sensor
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);

float acceleration = a.acceleration.x;
float temperature = temp.temperature;
float gyro = g.gyro.x;

  // Print temperature, acceleration and gyro from the MPU6050 sensor
  Serial.println(acceleration);
  Serial.println(temperature);
  Serial.println(gyro);

  // Check if the values are valid (not NaN)
  if (!isnan(acceleration) && !isnan(temperature) && !isnan(gyro)) {
    // Set the 'Acceleration' 'Temperature' and 'Gyro' fields in the FirebaseJson object
    content.set("fields/Acceleration/stringValue", String(acceleration, 2));
    content.set("fields/Temperature/stringValue", String(temperature, 2));
    content.set("fields/Gyro/stringValue", String(gyro, 2));
    Serial.print("Update/Add MPU Data... ");

    // Use the patchDocument method to update the Acceleration Temperature and Gyro Firestore document
    if (Firebase.Firestore.patchDocument(&fbdo, FIREBASE_PROJECT_ID, "", documentPath.c_str(), content.raw(), "Acceleration") && Firebase.Firestore.patchDocument(&fbdo, FIREBASE_PROJECT_ID, "", documentPath.c_str(), content.raw(), "Temperature") && Firebase.Firestore.patchDocument(&fbdo, FIREBASE_PROJECT_ID, "", documentPath.c_str(), content.raw(), "Gyro") ) {
      Serial.printf("ok\n%s\n\n", fbdo.payload().c_str());
      } else {
            Serial.println(fbdo.errorReason());
          }
        } else {
          Serial.println("Failed to read mpu data.");
        }

  // Delay before the next reading
  delay(10000);
}

In this way, the circuit can run the basic readings code and transfer data to the realtime database. Adafruit library was used for the MPU6050 sensor. However, it has nothing to do with the realtime database and what I am working on. Firebase cloud firestore was installed in test mode. What is the reason why I am getting this error in the code? What is the right code for this study?


The data received from the accelerometer should also be transferred as an array when transferring to firestore. Since the data received will be 520 samples for two seconds, I think it would be appropriate to throw it as an array. I'm waiting for your help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.