Sending array of data to firebase

Hi Everyone, I want to pushArray to firebase but right now I am only sending a certain amount of sensor data but I would want to send about 100 datasets per second (10hz) I was wondering how I would be able to do so? here is my code below

#include <MB_List.h>
#include <FirebaseJson.h>
#include <FBJS_Config.h>

#include <ArduinoJson.h>

// Make sure we've installed all needed libraries.

#include <ArduinoECCX08.h>
#include <ArduinoHttpClient.h>
#include <FirebaseJson.h>
#include <Arduino.h>
//#include <Firebase_Arduino_WiFiNINA.h>
#include "Firebase_Arduino_WiFiNINA.h"

#include <NTPClient.h>
#include <WiFiUdp.h>

// Include SPI and WiFi Libraries
#include <SPI.h>
#include <WiFiNINA.h>
#include "Firebase.h"

// Set these to run example.
#define FIREBASE_HOST "name.firebaseio.com"
#define FIREBASE_AUTH ""

// WiFi Credentials (edit as required)
#define WIFI_SSID ""
#define WIFI_PASSWORD ""

int status = WL_IDLE_STATUS;

// Initialize the Wifi client
WiFiSSLClient client;

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

// Define Firebase objects
FirebaseData fbdo;
FirebaseData stream;

unsigned long sendDataPrevMillis = 0;
String path = "/data_collection";

int count = 0;

//remember you put the switch towards 'A' not 'D' for analog input
int sensorPin = A1;   //for analog input


void connectToAP() {
  // Connect to Wifi Access Point
  
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(WIFI_SSID);
    
    // Connect to WPA/WPA2 network
    status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

    // wait 1 second for connection:
    delay(1000);
    Serial.println("Connected...");
  }
}

void printWifiStatus() {
  // Print results to serial monitor  
 
 // Network SSID  
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  
  // Device IP address
  IPAddress ip = WiFi.localIP(); 
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void setup() {
  
  // Start the Serial port
  Serial.begin(9600);

  // Wait for serial port to connect.
  while (!Serial) {
    ; 
  }
  
  // Check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("WiFi module failed!");
    while (true);
  }
   
  connectToAP();  
  printWifiStatus();

//  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH, WIFI_SSID, WIFI_PASSWORD);
  Firebase.reconnectWiFi(true);

  if (!Firebase.beginStream(stream, path))
  {
    Serial.println("Can't connect stream, " + stream.errorReason());
    Serial.println();
  }

  // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(-28800);  //PTZ is UTC-8:00 Hrs
}

void loop() {

  // set value
  String abc = "["1","2","3"]"; // this is getting error expected ',' or ';' before numeric constant
  if (Firebase.pushArray(fbdo, "/anumber", abc)) {     
    Serial.println("ok");   
    }

  timeClient.update();
  
  int heartValue = analogRead(sensorPin);    //reading the analog value
  Serial.println(heartValue);   //printing the value to the serial plotter

  String heartrate = String(heartValue);

// compute the required size
  const size_t CAPACITY = JSON_ARRAY_SIZE(100);

// allocate the memory for the document
  StaticJsonDocument<CAPACITY> doc;

// create an empty array
  JsonArray array = doc.to<JsonArray>();
  JsonObject obj = doc.as<JsonObject>();

// add some values
  array.add(e);
  array.add(heartrate);

  String output;

// serialize the array and send the result to Serial
  serializeJsonPretty(doc, output);

  if (Firebase.pushArray(fbdo, path + "/path2array", output))
  {
  Serial.println("push array ok");
  }else{
  Serial.println("push array failed");
  Serial.println(fbdo.errorReason());
  }
}```

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