0

Below is the code that i tried and it was working before i added NTP client and WiFiUdp . The credentials are all right. I even tried commenting the newly added portions, but now, all I am getting is Firebase.failed() , but does not return any no. when I printed out firebase.error()what could be the problem? The rules are all set to TRUE. I also tried creating a new database and tried sending data to that database, which also failed!

Using the same ESP board, I'm able to get date and time from NTP server!

I'm running on ArduinoJson 5.13.5 , I know there are update ones, but since I couldn't understand how to modify my code(even after watching some tutorials), I thought of sticking with this one! Is this version the problem?

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <SoftwareSerial.h>
#include <NTPClient.h>
#include <WiFiUdp.h>


//---------firebase creds---------
#define FIREBASE_HOST "~~~~~~~~" 
#define FIREBASE_AUTH "@#$%^&" 

//--------wifi creds--------
#define WIFI_SSID "!@#$%"
#define WIFI_PASSWORD "@#$%^&*" 
SoftwareSerial esp(D2,D8);

//--------data from arduino to esp-------
float temp_fb;
float gas_fb;
float hum_fb; 

//-------checking time elapsed b4 printing ------
unsigned long last_chk = 0 ; 
unsigned long time_elapsed; 

//-----ctrlling sending rate to firebase----
bool t_ar , h_ar , g_ar = false ; //chk arrival of all data b4 sending
char r;  
int found = 1;

//-----setting feeder pos from firebase
String cu_st= "0"; 


//-----getting time stamp from ntp server
char time_stamp[12]; 
int len;
const long utcOffsetInSeconds = 19800; //gmt+5hrs:30mins => 19800 sec
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

void setup() 
{
  Serial.begin(9600);
  esp.begin(4800);

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting"); 
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 
  if(Firebase.failed())
     {
      Serial.print("failed...");
      Serial.println(Firebase.error()); 
     }
  timeClient.begin();
}

void loop() 
{
  time_elapsed = millis(); 
  if(time_elapsed - last_chk > 5000)
  { 
    Serial.println("checking for data from arduino...");

    last_chk = time_elapsed;
    time_elapsed = millis();
  }
   while(esp.available()>0)
  { 
     if(found == 1)
     {
      Serial.println("................found data...............") ;
      found = 0;
     } 

     timeClient.update();
     len = sprintf(time_stamp , "%d:%d:%d" , timeClient.getHours() , timeClient.getMinutes() , timeClient.getSeconds() ) ;
     Serial.print("Time stamp:\t");
     Serial.println(time_stamp); 
     r = esp.read(); 
     //Serial.print("first char\t");
     //Serial.println(r); 
     switch(r)
     {

      case 't':
      {
        Serial.print("got t...") ;
        t_ar = true;
        temp_fb = esp.parseFloat(); 
        Serial.println(temp_fb);
        break ;
      }

      case 'g':
      {
          Serial.print("got g...") ;
          g_ar = true;
          gas_fb = esp.parseFloat();
          Serial.println(gas_fb);
          break ;
      }

      case 'h':
      {
        Serial.print("got h...") ;
        h_ar = true;
        hum_fb = esp.parseFloat();
        Serial.println(hum_fb);
        break ;   
      }
      default: break; 

     }

  }

  found = 1 ; 

  if(g_ar and t_ar and h_ar)
  {
     //writing to firebase  
     Serial.println("got the set.. to fb now"); 
     Firebase.pushString("Time stamp" , time_stamp); 
     Firebase.setFloat("GAS SENSORinst" ,gas_fb);
     Firebase.setFloat("HUMIDITY SENSORinst" ,hum_fb);
     Firebase.setFloat("TEMP SENSORinst" ,temp_fb);
     Firebase.pushFloat("GAS SENSOR" ,gas_fb);
     Firebase.pushFloat("HUMIDITY SENSOR" ,hum_fb);
     Firebase.pushFloat("TEMP SENSOR" ,temp_fb);
     if(Firebase.failed())
     {
      Serial.print("failed...");
      Serial.println(Firebase.error()); 
     }

  }

  t_ar , h_ar , g_ar = false ;

  cu_st = Firebase.getString("feeder");
  if(Firebase.failed())
     {
      Serial.print("failed to read from ...");
      Serial.println(Firebase.error()); 
     }

  if (cu_st == "1")
   {
    Serial.println("\trecd req to feed"); 
      esp.print('o');
      cu_st = "0";    
      Serial.println("\tsetting feeder to close in firebase");
      Firebase.setString("feeder" , "0");

   }

}
  • Sometimes the firebase add new key secret, but is the same problem in my project. The ESP 32 is OK, not stoped to work – rafael pascale Feb 28 at 16:28
  • Could this library not work in leap years? – rafael pascale Feb 28 at 16:34
  • I don't know why you think that way.., it was working just fine two days ago! – Somasundharam Sampath Feb 28 at 16:38
  • Me too, was working 2 days ago. I have an thermometer data logger that doesn t work at leap years just in february – rafael pascale Feb 28 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.