My app doesnt read values from firebase. ESP 12E (8266) with dht11 and induction sensor

Hello,
As i mentioned in topic, my app doesnt read values from firebase.
My ESP Code is

#include <ESP8266WiFi.h>                 
#include <FirebaseArduino.h>
#include <DHT.h>              
 
#define frb_link "axxxxxxxxxxxxxxxeio.com"      
#define frb_haslo "8JGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxOJGq3"            
#define wifi_ssid "SM-xxxxxx"                                  
#define wifi_haslo "mnxxxxxx"            
 
#define DHTPIN D2                                            // Cyfrowy pin podlaczony do sensoru
#define DHTTYPE DHT11                                        // definiowanie sensoru temperatury
#define Indupin D3								// 
DHT dht(DHTPIN, DHTTYPE);    

String msg1 = " Wykryto metal";
String msg2 = " Nie wykrywa";

void setup() 
{
  pinMode(Indupin, INPUT);							// definiuje typ pinu 2
  Serial.begin(9600);
  dht.begin();                                                  //odczytuje dane z sensora
            
  WiFi.begin(wifi_ssid, wifi_haslo);                                  // Logowanie do wifi
  Serial.print(wifi_ssid);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
 
  Serial.println();
  Serial.print("Polaczono z siecia");
  Serial.print("Adres IP: ");
  Serial.println(WiFi.localIP());                               //wyświetla lokalne ip
  Firebase.begin(frb_link, frb_haslo);                 // łączenie do bazy danych
}
 
void loop() 
{
float t = dht.readTemperature();                              // Odczyt temperatury w celsjuszach 
  
  int sensorValue = digitalRead(Indupin);
	if(sensorValue==LOW)
		{
		Serial.println(msg1);					// komunikat w konsoli
		Firebase.setString("Indukcja", msg1);		// Zmiana wpisu w bazie danych
		delay(500);
		}
	else
		{
		Serial.println(msg2);					// komunikat w konsoli
		Firebase.setString("Indukcja", msg2);	// Zmiana wpisu w bazie danych
    }
  Serial.print("%  Temperatura: ");  
  Serial.print(t);  
  Serial.println("°C ");
  
  Firebase.setFloat ("Temperatura",t);				// wypchniecie do bazy danych wartosci temperatury
  delay(2500);
    
}

My app inventor code looks like this
obraz_2023-01-12_160430934
My app looks like this:

Im sure my project bucket and link to database is correct too.
On firebase im lacking temperature readings bcs i didnt connect it yet, induction works:

Please help

I vaguely remember a problem with getting Data Changed events from Firebase when an IOT device does the update.

Unfortunately, I failed to record it in my Firebase FAQ.

To work around this, you could pull in a Clock Timer and poll the Firebase tag/value every few seconds.

(If any one has a link to this problem's history, please post it here.)

Im pretty fresh to app inventor, can you elaborate on how to do that with clock?

Did you pull in a Clock component from the Sensors Drawer in the Designer yet?

yes but i dont quite understand what to do with it or how

image
Smth like that? ( i want to use button to manually refresh values aswell sometimes)

Did you pull in a Clock1 Timer event block in the Blocks Editor?

Yes but what do i need to put in it? To make it work like a refresher/puller of data from firebase>?

You put in it the same Get blocks you had in that button Click event you showed us.

There is a tool tip that pops up when you hover your cursor over each block.
It helps to read those.

image
Is this it? Should be working now?

Yes, that's it.

If the Timer is enabled, it should be shooting off requests to Firebase every second, following the Clock1 attributes.


and
image
But it still doesnt work when i download it on android
It's still the same screen im getting in the beggining with both labels having "text for the label"

And i have like this in firebase
image

Am I doing something wrong with this app? Cuz im really hopeless ngl.
No matter what i do the changes wont show in my android phone at all ;/

You are supposed to read all the blocks in the FireBase Blocks Pallette to see what they do.

Especially the golden event blocks.

That should give you a hint of what you need.

1 Like

okay nvm, my esp 12 e wrote things in wrong directory. They just weren't in bucket but were buckets themselves. After correctly arranging them i succeded in properly getting read from firebase!
Thanks for patience! <3

Could you post your new code from both sides, for the next person who needs this?

Here a tutorial

2 Likes

Here, the wiever with firebase


The block code:

The ESP 8266 code:

#include <ESP8266WiFi.h>                 
#include <FirebaseArduino.h>
#include <DHT.h>              
 
#define frb_link "axxxxxxxxxxxxxxxeio.com"      
#define frb_haslo "8JGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxOJGq3"            
#define wifi_ssid "SM-xxxxxx"                                  
#define wifi_haslo "mnxxxxxx"            
 
#define DHTPIN D2                                            // Cyfrowy pin podlaczony do sensoru
#define DHTTYPE DHT11                                        // definiowanie sensoru temperatury
#define Indupin D3								// 
DHT dht(DHTPIN, DHTTYPE);    

String msg1 = " Wykryto metal";
String msg2 = " Nie wykrywa";

void setup() 
{
  pinMode(Indupin, INPUT);							// definiuje typ pinu 2
  Serial.begin(9600);
  dht.begin();                                                  //odczytuje dane z sensora
            
  WiFi.begin(wifi_ssid, wifi_haslo);                                  // Logowanie do wifi
  Serial.print(wifi_ssid);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
 
  Serial.println();
  Serial.print("Polaczono z siecia");
  Serial.print("Adres IP: ");
  Serial.println(WiFi.localIP());                               //wyświetla lokalne ip
  Firebase.begin(frb_link, frb_haslo);                 // łączenie do bazy danych
}
 
void loop() 
{
float t = dht.readTemperature();                              // Odczyt temperatury w celsjuszach 
  
  int sensorValue = digitalRead(Indupin);
	if(sensorValue==LOW)
		{
		Serial.println(msg1);					// komunikat w konsoli
		Firebase.setString("Indukcja", msg1);		// Zmiana wpisu w bazie danych
		delay(500);
		}
	else
		{
		Serial.println(msg2);					// komunikat w konsoli
		Firebase.setString("project-787465550920/Indukcja", msg2);	// Zmiana wpisu w bazie danych
    }
  Serial.print("%  Temperatura: ");  
  Serial.print(t);  
  Serial.println("°C ");
  
  Firebase.setFloat ("project-787465550920/Temperatura",t);				// wypchniecie do bazy danych wartosci temperatury
  delay(2500);
    
}

There you go, all the changes ive made so far.

If you use Firebase realtime, the Timer is not necessary since the change is detected automatically with the "DataChanged" block. Have you consulted my tutorial?