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
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
ABG
January 12, 2023, 4:25pm
2
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.)
Divi77e:
Im pretty fresh to app inventor, can you elaborate on how to do that with clock?
Im pretty fresh to app inventor, can you elaborate on how to do that with clock?
ABG
January 12, 2023, 6:00pm
5
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
Smth like that? ( i want to use button to manually refresh values aswell sometimes)
ABG
January 12, 2023, 8:48pm
8
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>?
ABG
January 12, 2023, 8:53pm
10
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.
Divi77e
January 12, 2023, 8:57pm
11
Is this it? Should be working now?
ABG
January 12, 2023, 9:01pm
12
Yes, that's it.
If the Timer is enabled, it should be shooting off requests to Firebase every second, following the Clock1 attributes.
Divi77e
January 12, 2023, 9:10pm
13
and
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"
Divi77e
January 12, 2023, 9:14pm
14
And i have like this in firebase
Divi77e
January 12, 2023, 9:19pm
15
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 ;/
ABG
January 12, 2023, 10:24pm
16
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
Divi77e
January 12, 2023, 10:37pm
17
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
ABG
January 12, 2023, 10:42pm
18
Could you post your new code from both sides, for the next person who needs this?
Divi77e
January 13, 2023, 7:02am
20
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.
Divi77e:
The block code:
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?