Skip to first unread message
Assigned to gareth....@googlemail.com by steve....@gmail.com

Xiaomy Redmii

unread,
Feb 7, 2019, 8:31:54 AM2/7/19
to MIT App Inventor Forum
my app is connected in 3 different separated accounts created in firebase

each screen has 1 firebase

why should I do?

the problem is whenever I am connected in the wifi
the app responds for 1-20 minutes and other firebase won't respond properly

I am using arduino device to web to firebase to mit app inventor


TimAI2

unread,
Feb 7, 2019, 8:43:11 AM2/7/19
to MIT App Inventor Forum
Sounds like a recipe for disaster!

Why 3 firebase accounts ? One will surely be enough given the tag: value/pair and separate projectbuckets you can use

Switching (having multiple) screens also probably won't help

Xiaomy Redmii

unread,
Feb 7, 2019, 8:53:20 AM2/7/19
to MIT App Inventor Forum
yes at defense earlier I am just lucky

the device shows a lot of issue but in just one issue (3 firebase) lol

3 web PHP to 3 firebase

1 is to 1


the response is really a disaster



what should I DO?

ON php SAME url and just different project bucket name ?

(see my recent post last feb 4 solved)


that would be the answer?

TimAI2

unread,
Feb 7, 2019, 9:07:02 AM2/7/19
to MIT App Inventor Forum
Try it....

Xiaomy Redmii

unread,
Feb 7, 2019, 9:10:50 AM2/7/19
to MIT App Inventor Forum
okay sir I'll keep you updated

my phone still on charge



and why the multiple screens can affect also?

TimAI2

unread,
Feb 7, 2019, 9:47:33 AM2/7/19
to MIT App Inventor Forum
They work like separate apps (sort of) so what happens and is loaded in one screen may not work in another screen, e.g. variables / bluetooth / possibly firebase

Xiaomy Redmii

unread,
Feb 7, 2019, 10:02:52 AM2/7/19
to MIT App Inventor Forum
yeah that scenario probably occurred on me earlier

what should I do then? my project was big and need more screen

Xiaomy Redmii

unread,
Feb 9, 2019, 10:13:20 AM2/9/19
to MIT App Inventor Forum
I already put all web (http) to a single firebase 

together with the MIT app inventor (app project) with one source on firebase

I just need to try it tomorrow

is there any problem might occur then?

Xiaomy Redmii

unread,
Feb 10, 2019, 8:59:09 AM2/10/19
to MIT App Inventor Forum
having one firebase account doesn't work on my app

I did this :

1st
*having the same url and token
*then different bucket name

then proceed:

2nd
*different project in one firebase:

+having the unique url and token
+also project bucket




Xiaomy Redmii

unread,
Feb 11, 2019, 5:49:30 AM2/11/19
to MIT App Inventor Forum
need help pls

Xiaomy Redmii

unread,
Feb 12, 2019, 10:18:35 AM2/12/19
to MIT App Inventor Forum
anyone can help me in my project??

my problem is the 3 firebase 

only 1 is updating continuously :(

I don't know why


SteveJG

unread,
Feb 12, 2019, 10:38:52 AM2/12/19
to MIT App Inventor Forum
Is this part of your Trash project?   You probably can do everything you currently are trying to do on three screens on ONE.  You don not explain why you think you need several Project Buckets.   You probably can use just one Project Bucket. Is only Trash1 updating?   Perhaps you need 
to use a single Project Bucket   and different Tags for each Trash.     DistanceTrash1, DistanceTrash2 ...., then you can save all the data in a single Project Bucket.  I do not know why Trash1 works and updates but suspect when you change screens, you loose the link to Firebase...I really do not know.   If everything is on one screen (Trash1 stuff in a VerticalLayout you hide and show and the same with Trash2 and 3 you do not have to change screens.   Changing screens might be the problem.

Xiaomy Redmii

unread,
Feb 12, 2019, 10:52:05 AM2/12/19
to MIT App Inventor Forum
okay sir I will follow it

sir can you provide a sample of one screen having multiple screen?? I don't know how to hide it

SteveJG

unread,
Feb 12, 2019, 11:21:50 AM2/12/19
to MIT App Inventor Forum
An example is here  Building Apps with Many Screens  

To show a virtual screen        VerticalLayout.Visible = true, to hide it VerticalLayout.Visible=false

in your case, place all the components currently on your screen2  in a Layout (this is Trash1) ; fill a second Layout with the identical components (this will be for Trash2) and the same for Trash3.    You have a very serious problems with your Screens 2, 3 and 4.  They are very elaborate and pretty but they are very complex... why not simplify them?   You do not need all those layouts ... they will be almost imposible to reproduce for Trash 2 and 3 so you might just use simple components on those screens.





Xiaomy Redmii

unread,
Feb 12, 2019, 2:53:49 PM2/12/19
to MIT App Inventor Forum
Thank you sir :)

Xiaomy Redmii

unread,
Feb 12, 2019, 4:19:55 PM2/12/19
to MIT App Inventor Forum
Good morning!

sir here

for example: I want to disable clicking the trash1_button

because I am already on it's screen

how to set that argument in blocks? 

Have a blessed day :)

screen.png


SteveJG

unread,
Feb 12, 2019, 7:30:39 PM2/12/19
to MIT App Inventor Forum
set Trash1.Enabled = false     to disable the button      then    to re-enable  with     set Trash1.Enabled = true    where Trash1 is a Button.

Xiaomy Redmii

unread,
Feb 13, 2019, 4:31:34 AM2/13/19
to MIT App Inventor Forum
I removed the close_application
and then I am going to try your instruction :)

Xiaomy Redmii

unread,
Feb 13, 2019, 4:50:47 AM2/13/19
to MIT App Inventor Forum

check_button.png


Xiaomy Redmii

unread,
Feb 13, 2019, 5:14:32 AM2/13/19
to MIT App Inventor Forum
the enabled_false is not on screen_initialize?

and the enabled_true is for the trash_button1?

SteveJG

unread,
Feb 13, 2019, 8:20:59 AM2/13/19
to MIT App Inventor Forum
Your image is probably not correct Xiaomy.   I don't know if it will work the way you show.  Because App Inventor 2 processes commands asycronously, the set trash1.Enabled to true probably never executes.

I need a better explanation.   On which Screen is the button you want to disable?

Perhaps    Screen5.Initialize
                         Trash1.Enabled = false

or the code might be something else.    What you do depends on why you want to disable the button? 

When you leave Screen5 then, you might want to set Trash1.Enabled to true   but that code is only going to enable Trash1 if the buttonis on Screen5.  If Trash1 is on another screen, you have to pass the command using a Boolean value from the Screen5 to the Screen you want to disable the button ( istrash1enabled = true or false for example and use that to set the button's state)    I do not know why you want to disable the Trash1 button.


Xiaomy Redmii

unread,
Feb 13, 2019, 8:27:32 AM2/13/19
to MIT App Inventor Forum
when screen for trash1 initialize
 

I want the button trash1 disable and only 2 trash (trash 2 and 3) clickable

vice versa


the blocks I sent are working on the companion

not yet tried the apk qr code

SteveJG

unread,
Feb 13, 2019, 8:42:42 AM2/13/19
to MIT App Inventor Forum
OK ... then try the apk;  If it does what you want smile..
Trash1.Enabled=false
Trash2.Enabled=true
Trash3.Enabled=true

where the buttons are on Screen5????  

or you might want code like this:
if trash1.Enabled=false then  trash2.Enabled=true  and trash3.Enabled =true
else if trash2.Enabled=false then  trash1Enabled=true  and  trash3.Enabled=true
else if trash3.Enabled=false then trash1.Endabled=true and trash2.Enabled=true

I honestly do not know how this would work using multiple real Screens.   I almost never use Screens.  You are on your own . In your situation I would do a lot of experimenting until I found a solution.     Hopefully someone else will join the thread to help you with this issue.

Xiaomy Redmii

unread,
Feb 13, 2019, 8:52:12 AM2/13/19
to MIT App Inventor Forum
it worked on apk 

but the buttons (are clickable) I am going to try your instruction

SteveJG

unread,
Feb 13, 2019, 8:54:52 AM2/13/19
to MIT App Inventor Forum
The buttons are clickable probably because "Your image is probably not correct Xiaomy.   I don't know if it will work the way you show.  Because App Inventor 2 processes commands asycronously, the set trash1.Enabled to true probably never executes."     ...your code trash1.Enabled=false  NEVER executes.

Xiaomy Redmii

unread,
Feb 13, 2019, 8:55:50 AM2/13/19
to MIT App Inventor Forum
buttons are all provided on the 3 screen trash

Xiaomy Redmii

unread,
Feb 13, 2019, 9:07:31 AM2/13/19
to MIT App Inventor Forum
The blocks I sent earlier allows the app to refresh

is it helpful? just followed your blocks then?

Xiaomy Redmii

unread,
Feb 13, 2019, 9:12:21 AM2/13/19
to MIT App Inventor Forum
according to a developer from firebase

it must be refreshed so the token that is (expire) will auth again? I am not sure about his saying

SteveJG

unread,
Feb 13, 2019, 9:21:51 AM2/13/19
to MIT App Inventor Forum
I do not either.   I do not use Firebase for anything.  The Firebase developer might be saying Firebase cannot be used continuously for long periods of time without the token expiring.  It may mean your app has to reconnect to Firebase periodically.   I do not know how to do that other than closing your app, restarting and reconnecting periodically.   I expect an app cannot be connected to FB 24/7 without 'refreshing'.   I cannot help with this because I do not understand it...Sorry.

Xiaomy Redmii

unread,
Feb 13, 2019, 9:27:34 AM2/13/19
to MIT App Inventor Forum
it's okay sir :) 
you always help me solve problems
thank you :)

but still I need to figure this out

Xiaomy Redmii

unread,
Feb 13, 2019, 9:38:52 AM2/13/19
to MIT App Inventor Forum
It might also because the 3 accounts on my firebase are all log in my laptop? so it is the problem?

SteveJG

unread,
Feb 13, 2019, 9:50:45 AM2/13/19
to MIT App Inventor Forum
Your latest idea is a good one.

This is what the Web says about refreshing tokens:  You might read this 

Manage User Sessions | Firebase


These links may explain what the Firebase developer told you. 

You have THREE Firebase accounts?    One for each of Trash1, Trash2, Trash3 .      Yes, I think that could be the problem.   You probably should use ONLY one account???? Maybe then you will have no issues.   You should be able to use one account for each of your three categories.  Disable two of the active sessions and your app might work.

Xiaomy Redmii

unread,
Feb 14, 2019, 9:32:47 AM2/14/19
to MIT App Inventor Forum
but when I connect it with one account it doesn't work

maybe I should disable them thank you sir :) I will try it now

SteveJG

unread,
Feb 14, 2019, 9:50:24 AM2/14/19
to MIT App Inventor Forum
Oh you will have to try something different.

I do not know what "t when I connect it with one account it doesn't work'  means.   A better explanation might result in some suggestions.

What I think you are doing  is   supporting a Firebase database by populating it from an arduino.    Do you have an arduino for each Trash?  ..each writing to a separate FB account?


You shouldn't need that.    All three can write to the same account as long as what information each sends goes into different tags.   Currrently you collect  
Distance, Humidity,Temperature   from  Trash1 with those Tags     Could you have Trash2 send Tags for DistanceT2, HumidityT2, and TemperatureT2  and also Trash3 ?
All that could post in the same Firebase account.   Or is this more complicated?

Xiaomy Redmii

unread,
Feb 14, 2019, 9:55:07 AM2/14/19
to MIT App Inventor Forum
ah okay sir I will try it too

my only problem is how to connect it with php maybe it is easy too

need more trials

Xiaomy Redmii

unread,
Feb 18, 2019, 5:51:21 PM2/18/19
to MIT App Inventor Forum
sir 

good morning

Do you have any more solutions? my devices are working well and connecting in one firebase account but the data are not receive

* I tried same project bucket
* different project bucket
(all changes in the php)

SteveJG

unread,
Feb 18, 2019, 6:35:48 PM2/18/19
to MIT App Inventor Forum
OK, you still have problems.

You said "devices are working well and connecting in one firebase account "   That sounds good so please explain what the remaining problem is.   You said "the data are not receive" What does 
that mean Xiaomy?     The data does not post to Firebase?   The data posts to Firebase but you cannot read it from you Android app?

If the data posts to the Firebase , what does the Firebase dashboard screen look like?    Are you using different Tags for the ardunio data from each of Trash1, Trash2 and Trash3? You need different php code for each arduino so that you will have tags something like     TemperatureTrash1, TemperatureTrash2 and TemperatureTrash3

Are you still using separate Screens on your app to try to monitor the data from Trash1,2,3? If you do that, doing that could create problems.

To get some help,  explain in more detail what is working and what is not working.  You did not provide enough information .

TimAI2

unread,
Feb 18, 2019, 6:44:38 PM2/18/19
to MIT App Inventor Forum
Could also you provide your full php file that sends the data to firebase. Might be able to do some testing on my/our own firebase accounts for "multiple" stations

You did put some of the code in a different thread but i am not certain it was ALL of it :)

TimAI2

unread,
Feb 18, 2019, 6:46:53 PM2/18/19
to MIT App Inventor Forum
And how many trash stations are we looking at? What is the total number of trash stations going to be? 10, 50, 100, 1000 ?

Xiaomy Redmii

unread,
Feb 19, 2019, 8:31:38 AM2/19/19
to MIT App Inventor Forum
<?php

require 'firebaseLib.php';
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];


// --- This is your Firebase URL
// --- Use your token from Firebase here
$token = 'MI3ZrLNP8YrtJbZqcr2vazG8x7wPh5cheiCyR1rM';
// --- Here is your parameter from the http GET


 

$_devicestatus= array('Distance' => $Distance,
'Temperature' => $Temperature,
'Humidity' => $Humidity,

);
$firebasePath = '/thesis1-69/';
/// --- Making calls
$fb = new fireBase($url, $token);
$fb->update($firebasePath, $_devicestatus);

?>



Xiaomy Redmii

unread,
Feb 19, 2019, 8:33:19 AM2/19/19
to mitappinv...@googlegroups.com
I used the code for 3 devices but it just work on 1 device which the projectbucket name is thesis 69 

each has different names in projectbucket

I have only 3 trash

here's the firebaseLib

SteveJG

unread,
Feb 19, 2019, 8:48:39 AM2/19/19
to MIT App Inventor Forum
I do not know but expect you need this code for one of your ardunios

$_devicestatus= array('Distance' => $Distance,
'Temperature' => $Temperature,
'Humidity' => $Humidity,

);

and something like this

$_devicestatus= array('DistanceTrash2' => $DistanceTrash2,
'TemperatureTrash2' => $TemperatureTrash2,
'HumidityTrash2' => $HumidityTrash2,

);

for the next arduino

and

$_devicestatus= array('DistanceTrash3' => $DistanceTrash3,
'TemperatureTrash3' => $TemperatureTrash3,
'HumidityTrash3' => $HumidityTrash3,

);

for the third     so the you produce a different set of Tags for each arduino.  Now, Trash2 and Trash3 data write over the Trash1 data.

My suggestion might not be completely correct  so you have to experiment.

Xiaomy Redmii

unread,
Feb 19, 2019, 8:52:43 AM2/19/19
to MIT App Inventor Forum
I know I tried that already?
but okay I will try again

Xiaomy Redmii

unread,
Feb 19, 2019, 8:55:05 AM2/19/19
to MIT App Inventor Forum
require 'firebaseLib.php';
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity = $_GET["humidity"];


how about this?

SteveJG

unread,
Feb 19, 2019, 8:56:43 AM2/19/19
to MIT App Inventor Forum
You may also need to change this

require 'firebaseLib.php';
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];

for Trash2 and Trash3  ... 

require 'firebaseLib.php';
$DistanceTash2 = $_GET["distance"];
$TemperatureTrash2 = $_GET["temp_f"];
$HumidityTrash2= $_GET["humidity"];



require 'firebaseLib.php';
$DistanceTrash3 = $_GET["distance"];
$TemperatureTrash3 = $_GET["temp_f"];
$HumidityTrash3= $_GET["humidity"];

SteveJG

unread,
Feb 19, 2019, 9:06:08 AM2/19/19
to MIT App Inventor Forum
...also, I think you need only ONE project bucket .   You keep the activities separate by having different Tags for Trash1,Trash2 and Trash3. so several project buckets might also be a reason the data does not post from Trash2 and 3.

Xiaomy Redmii

unread,
Feb 19, 2019, 9:26:17 AM2/19/19
to mitappinv...@googlegroups.com
trash 2 and 3 still doesn't show it's data on firebase
Message has been deleted

SteveJG

unread,
Feb 19, 2019, 9:37:23 AM2/19/19
to MIT App Inventor Forum
I do not program in php Xiaomy so my suggestions are a guess.   Trash2 does not display on Firebase.  Are you using one project bucket or three project buckets?    If you disable Trash1 temporarily and use the same exact php code you used in Trash1 in Trash2, then does Trash2 display?  Doint that tests whether the arduino in Trash2 is working.  Is it when you disable Trash1?

Perhaps Tim will join the discussion and be able to provide clearer advice.
Message has been deleted

Xiaomy Redmii

unread,
Feb 19, 2019, 9:39:05 AM2/19/19
to MIT App Inventor Forum
yeah same projectbucket name

okay I will try it

Xiaomy Redmii

unread,
Feb 19, 2019, 9:44:20 AM2/19/19
to MIT App Inventor Forum
I use the same arduino code and php code as well

the data on the database doesn't change

SteveJG

unread,
Feb 19, 2019, 9:50:27 AM2/19/19
to MIT App Inventor Forum
OK.  If the database does not change with identical code and Trash1 turned off, it probably means that Trash2 arduino is not working as you expect.  What happens if you try to have Trash3 post data?

Xiaomy Redmii

unread,
Feb 19, 2019, 9:56:46 AM2/19/19
to MIT App Inventor Forum
but it send data on the web php 000webhost


here's my code on arduino 


this is the arduino code


#include <SoftwareSerial.h>
#include <DHT.h>;

SoftwareSerial Serial1(10, 11);

#define DHTTYPE DHT11
#define DHTPIN 2
#define TRIGGER_PIN 4
#define ECHO_PIN 3


DHT dht(DHTPIN, DHTTYPE, 11);

float humidity, temp_f;
int distance;
long duration;


void setup() {


  Serial.begin(9600);      
  Serial1.begin(9600);   
  //ESP8266.begin(9600);
  dht.begin();
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  connectWiFi();           
}

void loop() {
  
  temp_f = dht.readTemperature();
  humidity = dht.readHumidity();
  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);

  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;


  Serial1.println("AT+CIPMUX=0\r\n");      
  delay(500);                             

  // TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";   
  // cmd += "184.106.153.149";                
  cmd += "expository-spoke.000webhostapp.com";                       
  cmd += "\",80\r\n\r\n";                  

  Serial1.println(cmd);                    
  Serial.println(cmd);                     

  delay(500);                            

  if (Serial1.find("ERROR"))               
  {
    Serial.println("AT+CIPSTART error");   
    //return;
  }

  // prepare GET string
  String getStr = "GET /upload.php?distance=";
  getStr += distance;
  getStr += "&temp_f=";
  getStr += temp_f;
  getStr += "&humidity=";
  getStr += humidity;
  getStr += " HTTP/1.1\r\n";
  getStr += "Host: expository-spoke.000webhostapp.com\r\n\r\n";

  
  Serial.println(getStr);                

  cmd = "AT+CIPSEND=";                      
    cmd += String(getStr.length());
  cmd += "\r\n";

  Serial.println(cmd);                   
  Serial1.println(cmd);                 

  delay(500);                          

  if (Serial1.find(">"))                  
  {
    Serial.println("connected to Cloud");  
    Serial1.print(getStr);                 
  }
  else
  {
    Serial1.println("AT+CIPCLOSE\r\n");   
    Serial.println("AT+CIPCLOSE");         
  }


}

boolean connectWiFi() {               
  Serial1.println("AT+CWMODE=1\r\n"); 
  delay(100);                         

  String cmd = "AT+CWJAP=\"";         
  cmd += "c902b6";                   
  cmd += "\",\"";
  cmd += "262459105";                
  cmd += "\"\r\n";
  Serial.println(cmd);                
  Serial1.println(cmd);               

  delay(500);                       

  Serial1.println("AT+CWJAP?");       

  if (Serial1.find("+CWJAP"))
  {
    Serial.println("OK, Connected to WiFi.");        
    return true;
  }
  else
  {
    Serial.println("Can not connect to the WiFi.");  
    return false;
  }
}

Xiaomy Redmii

unread,
Feb 19, 2019, 9:57:35 AM2/19/19
to MIT App Inventor Forum
the last time the 3 devices were used are working  fine

TimAI2

unread,
Feb 19, 2019, 11:56:08 AM2/19/19
to MIT App Inventor Forum
Can't get my test php (send data to firebase) to connect.

Fatal error: Uncaught Error: Class 'fireBase' not found

Have you had to setup anything else other than have the firebaseLib.php in the same directory as your php file ?

and just to check, this is your ProjectBucket name?:

$firebasePath = '/thesis1-69/';


TimAI2

unread,
Feb 19, 2019, 12:32:42 PM2/19/19
to MIT App Inventor Forum
Fixed the class error, but like you, no data getting through....

TimAI2

unread,
Feb 19, 2019, 3:56:39 PM2/19/19
to MIT App Inventor Forum
Done a bit of digging around and found something :) Firebase doesn't make it easy!!

For Ai2, we use the Web API Key for the "token", found on the main project settings page

For PHP we need to use the database secret for the "token" / "$token"

You can find the database secret through:

Project Settings (1) > Service Accounts (2) > Database Secrets (3) > Key (4) - click the show button to show it

Use this key for the "token" / "$token" in the php file and data should come through

FirebaseDBSecret.png



Also remove the url and token entries from the your firebaseLib.php file, they are not needed as they are passed by your own php file

TimAI2

unread,
Feb 19, 2019, 4:27:06 PM2/19/19
to MIT App Inventor Forum
Now for your php....

You should be able to use just the one php file with a few adjustments
You need to add another parameter called "trash"
Your arduino will need to send this parameter along with the others, and this will identify which "trash" e.g. Trash1, Trash2 etc
If you were to do it manually in the browser the url would look like this for "Trash1":

https://<yourdomain.com>/<your ProjectBucket>/yourphpfile.php?trash=Trash1&distance=150&temperature=27.51&humidity=91

As you will see from the code in the php, we use "$Trash" to create the child in firebase that equates to Trash1

There may be some issues with the php file or firebase being locked if two trash facilities send data at the same time
therefore you may have to adjust timings on the arduinos so they do not clash with each other and send data at the same time

php like this:

<?php

require 'firebaseLib.php';
$Trash = $_GET["trash"];  // new entry here to get trash location
$Distance = $_GET["distance"];
$Temperature = $_GET["temperature"];
$Humidity= $_GET["humidity"];


// --- This is your Firebase URL
$baseURI = '<your url here>';

// --- Use your token from Firebase here
$token = '<your database secret here>';

// --- path or ProjectBucket
$firebasePath = '/<your project bucket here>/';

// --- Here are your parameters from the http GET
$devicestatus= array('Distance' => $Distance,'Temperature' => $Temperature,'Humidity' => $Humidity);

//   - - -  Combine the Location with the status
$full= array($Trash => $devicestatus);


/// --- Making calls
$fb = new Firebase($baseURI, $token);
$fb -> update($firebasePath, $full);


?>

Firebase should look something like this once all three trash facilities are sending data

trashfirebase.png


You don't need to create anything, the first run will generate the datasets


Now you can access the data from the app by calling in each dataset by its name: Trash1, Trash2 etc.


Enjoy :)


Xiaomy Redmii

unread,
Feb 19, 2019, 6:45:15 PM2/19/19
to MIT App Inventor Forum
sir thank you so much ! :)

sir pls help me fix the arduino code for delay

Xiaomy Redmii

unread,
Feb 19, 2019, 6:50:23 PM2/19/19
to MIT App Inventor Forum
is this right? for my GET http

String getStr = "GET /upload.php?trash=";
  getStr += Trash1;
  getStr += "&distance=";

TimAI2

unread,
Feb 20, 2019, 7:39:45 AM2/20/19
to MIT App Inventor Forum
Looks OK, try it?

regarding the timings suggest you set different delay times for each arduino, with strange numbers so they won't clash

e.g. Trash1 every 60secs, Trash2 every 73secs, Trash3 every 83secs

See here and look at the arduino code used

Xiaomy Redmii

unread,
Feb 20, 2019, 8:38:36 AM2/20/19
to MIT App Inventor Forum
look my code sir
in arduino

how to change the delay timing from it? I have 500 and 100

Xiaomy Redmii

unread,
Feb 20, 2019, 9:14:42 AM2/20/19
to mitappinv...@googlegroups.com
it doesn't work on other devices

it send data but doesn't display in firebase

Xiaomy Redmii

unread,
Feb 20, 2019, 10:00:32 AM2/20/19
to MIT App Inventor Forum
only one device works
2 devices send data on php 
but doesn't show the data on the firebase

Xiaomy Redmii

unread,
Feb 20, 2019, 10:24:36 AM2/20/19
to MIT App Inventor Forum
should I delete other firebase once used by my devices?? even I am not calling those

it might be affecting the connection of my devices on the current firebase??

SteveJG

unread,
Feb 20, 2019, 10:34:28 AM2/20/19
to MIT App Inventor Forum
Using only a single Firebase account seems the best course Xiaomy.  It is what both Tim and I recommended.  It is a good idea because "it might be affecting the connection of my devices on the current firebase" but we do not know.  It is something to try.    It could explain why Trash1 posts  and Trash2 and 3 do not post.  If you are not calling the other firebase databases, why do they still exist?    

It is certainly possible the code you use for Trash2 and 3 is not identical to the code you use for Trash1.  You should consider testing each Trash  with the other two 'offline' to see if they are interfering with one another.

Xiaomy Redmii

unread,
Feb 20, 2019, 10:56:59 AM2/20/19
to MIT App Inventor Forum
I already deleted the other database or firebase accounts
but still not connecting

SteveJG

unread,
Feb 20, 2019, 11:07:20 AM2/20/19
to MIT App Inventor Forum
Sorry, you are not being very clear.

'still not connecting' ... what is not connecting?   The Trash1 arduino or only Trash1 or all of them are not ?     What is not connecting to?  Your arduino data is not posting to Firebase dashboard or what? 

For the moment, put aside your App Inventor app (make sure it is not attempting to connect) and sort out the issues regarding the arduinos.   If Trash1 works and you have identical code in Trash2 and 3, then they MUST work too if you 'turn them on, one at a time." don't you think?

Xiaomy Redmii

unread,
Feb 20, 2019, 11:15:23 AM2/20/19
to mitappinv...@googlegroups.com
the data from 2 devices are already sent on the php data 
but their data are not displayed on the firebase


those devices had identical code with my first device :( so I am confused why those 2 are not working

TimAI2

unread,
Feb 20, 2019, 11:26:02 AM2/20/19
to MIT App Inventor Forum
Check your code: arduinos (are they all transmitting code to the php server ?)
Check your code: php (urls, tokens!)
Check your code: firebase (is it open to all/public read/write true for all users)

If the arduino code, php and firebase work for one device, that syas the php and firebase are working, so the finger points to the arduinos and their code
Message has been deleted
Message has been deleted
Message has been deleted

Xiaomy Redmii

unread,
Feb 20, 2019, 12:03:13 PM2/20/19
to MIT App Inventor Forum
<?php

require 'firebaseLib.php';
$Trash = $_GET["trash"];
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];


$token = 'xxxxxxxxxxxxxxxx';
 
$firebasePath = '/thesis1-69/';
$devicestatus= array('Distance' => $Distance,'Temperature' => $Temperature,'Humidity' => $Humidity);
$full= array($Trash => $devicestatus);
$fb = new Firebase($url, $token);

Xiaomy Redmii

unread,
Feb 20, 2019, 12:09:20 PM2/20/19
to MIT App Inventor Forum
#include <SoftwareSerial.h>
#include <DHT.h>;

SoftwareSerial Serial1(10, 11); // Rx, Tx
/* DHT SENSOR SETUP */

#define DHTTYPE DHT11
#define DHTPIN 2
#define TRIGGER_PIN 4
#define ECHO_PIN 3


DHT dht(DHTPIN, DHTTYPE, 11);

float humidity, temp_f;
int distance;
long duration;


void setup() {


  Serial.begin(9600);      // PC Arduino Serial Monitor
  Serial1.begin(9600);   // Arduino to ESP01 Communication
  //ESP8266.begin(9600);
  dht.begin();
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  connectWiFi();           // To connect to Wifi
}

void loop() {
  // put your main code here, to run repeatedly:
  // float analog_val = analogRead(temp_sensor);     // Read Analog Temperature

  //j=tempc;
  temp_f = dht.readTemperature();
  humidity = dht.readHumidity();
  digitalWrite(TRIGGER_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);

  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;


  Serial1.println("AT+CIPMUX=0\r\n");      // To Set MUX = 0
  delay(500);                             // Wait for 2 sec

  // TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";   // TCP connection with https://thingspeak.com server
  // cmd += "184.106.153.149";                // IP addr of api.thingspeak.com
  cmd += "expository-spoke.000webhostapp.com";                       // ip address of my site
  cmd += "\",80\r\n\r\n";                  // Port No. = 80

  Serial1.println(cmd);                    // Display above Command on PC
  Serial.println(cmd);                     // Send above command to Rx1, Tx1

  delay(500);                            // Wait for 20 Sec

  if (Serial1.find("ERROR"))               // If returns error in TCP connection
  {
    Serial.println("AT+CIPSTART error");   // Display error msg to PC
    //return;
  }

  // prepare GET string
  Serial.println(getStr);                 // Display GET String on PC

  cmd = "AT+CIPSEND=";                    // send data length
  cmd += String(getStr.length());
  cmd += "\r\n";

  Serial.println(cmd);                   // Display Data length on PC
  Serial1.println(cmd);                  // Send Data length command to Tx1, Rx1

  delay(500);                          // wait for 20sec

  if (Serial1.find(">"))                   // If prompt opens //verify connection with cloud
  {
    Serial.println("connected to Cloud");  // Display confirmation msg to PC
    Serial1.print(getStr);                 // Send GET String to Rx1, Tx1
  }
  else
  {
    Serial1.println("AT+CIPCLOSE\r\n");    // Send Close Connection command to Rx1, Tx1
    Serial.println("AT+CIPCLOSE");         // Display Connection closed command on PC
  }


}

boolean connectWiFi() {               // Connect to Wifi Function
  Serial1.println("AT+CWMODE=1\r\n"); // Setting Mode = 1
  delay(100);                         // wait for 100 mSec

  String cmd = "AT+CWJAP=\"";         // Connect to WiFi
  cmd += "c902b6";                   // ssid_name
  cmd += "\",\"";
  cmd += "262459105";                // password
  cmd += "\"\r\n";
  Serial.println(cmd);                // Display Connect Wifi Command on PC
  Serial1.println(cmd);               // send Connect WiFi command to Rx1, Tx1

  delay(500);                       // wait for 10 sec

  Serial1.println("AT+CWJAP?");       // Verify Connected WiFi

  if (Serial1.find("+CWJAP"))
  {
    Serial.println("OK, Connected to WiFi.");         // Display Confirmation msg on PC
    return true;
  }
  else
  {
    Serial.println("Can not connect to the WiFi.");   // Display Error msg on PC
    return false;
  }
}


TimAI2

unread,
Feb 20, 2019, 12:46:42 PM2/20/19
to MIT App Inventor Forum
Don't see the GET string in your arduino code ?

Xiaomy Redmii

unread,
Feb 20, 2019, 7:23:14 PM2/20/19
to MIT App Inventor Forum
Good morning

I don't know why it's not seen there
but it was together with the code when I paste it here

Xiaomy Redmii

unread,
Feb 20, 2019, 7:33:22 PM2/20/19
to MIT App Inventor Forum
finally!! it works sir :) I tried to upload the arduino code on other laptop 

maybe the laptop I use are not compatible with the device? or it needs to be updated

Xiaomy Redmii

unread,
Feb 20, 2019, 7:43:28 PM2/20/19
to MIT App Inventor Forum
the only issue is their delays

when 1st device is on the others stop

Xiaomy Redmii

unread,
Feb 20, 2019, 8:05:25 PM2/20/19
to mitappinv...@googlegroups.com
I still can't make the connection 

or data show simultaneously

Xiaomy Redmii

unread,
Feb 20, 2019, 8:42:10 PM2/20/19
to MIT App Inventor Forum
sir
what do you think is the best delay?
only 1 device is updating 2 devices are not

but at first the 3 devices updating after 8 seconds 
only the first device works

SteveJG

unread,
Feb 20, 2019, 8:47:27 PM2/20/19
to mitappinv...@googlegroups.com
Tim already recommended set different delay times for each arduino, with strange numbers so they won't clash (to keep them from synchronizing you to avoid them ever firing at the same exact time)

e.g. Trash1 every 60secs, Trash2 every 73secs, Trash3 every 83secs

See here and look at the arduino code example used


Your very rapid update of 8 seconds might be to0 frequent.

Xiaomy Redmii

unread,
Feb 20, 2019, 8:58:40 PM2/20/19
to MIT App Inventor Forum
can you edit my delays on arduino? I don't know how to make that seconds

I got 500 delay and 100 

SteveJG

unread,
Feb 20, 2019, 9:31:28 PM2/20/19
to MIT App Inventor Forum
I expect you need to set the delays in miliseconds (1/1000 of a second)

60secs,  =    60000 ms
73sec  =  73000 ms
 83secs = 83000 ms 


I don't know how that would be entered   perhaps     #define delayMillis 60000UL a delay of 500 is probably 1/2 a second and 100 is 100 ms so 500 and 100 are much to small a delay I expect.

Be aware, I don't program arduino so this is what the link Tim sent you seems to indicate to me. I might be wrong.

Good luck.


Xiaomy Redmii

unread,
Feb 20, 2019, 11:04:04 PM2/20/19
to mitappinv...@googlegroups.com
the set delays as suggested are contradicting to my project
in a way that my data being capture should be reliable or in a simple way is effective like a live data

simply as "I can't follow the delays being suggested"

:(

is there any way I can use ?

Xiaomy Redmii

unread,
Feb 20, 2019, 11:06:48 PM2/20/19
to MIT App Inventor Forum
How about 3 different projects in one firebase account??

Xiaomy Redmii

unread,
Feb 20, 2019, 11:52:14 PM2/20/19
to MIT App Inventor Forum
or should I go back to my recent project that involves each devices to have a 1 firebase account and 1 webserver

Xiaomy Redmii

unread,
Feb 21, 2019, 4:45:18 AM2/21/19
to MIT App Inventor Forum
need help :(

Xiaomy Redmii

unread,
Feb 21, 2019, 5:27:23 AM2/21/19
to MIT App Inventor Forum

q_img.png

only one is updating whenever the all devices are ON 

Xiaomy Redmii

unread,
Feb 21, 2019, 5:59:29 AM2/21/19
to MIT App Inventor Forum
it was suggested on me here to use this https://firebase.google.com/docs/reference/rest/database/
but I am not familiar on using this one

TimAI2

unread,
Feb 21, 2019, 5:59:46 AM2/21/19
to MIT App Inventor Forum
The delays I proposed were only suggestions so you could try 7,9,11 ?

Only seems to take @ 2 seconds for a manual browser entry to be completed

If things only update when all devices are ON, this suggests an issue between the arduinos, wifi and the webhost ? 

TimAI2

unread,
Feb 21, 2019, 6:47:04 AM2/21/19
to MIT App Inventor Forum
Firebase "REST API?"

This, I believe, is NOT the problem.
The php file works and serves data to firebase
The issue you mention above therefore lies before that in the chain: arduinos/wifi/webhost/php/firebase

Xiaomy Redmii

unread,
Feb 21, 2019, 6:53:27 AM2/21/19
to MIT App Inventor Forum
sir can you give a sample based on my code I still don't get it 
I already play with the delays

TimAI2

unread,
Feb 21, 2019, 7:01:02 AM2/21/19
to MIT App Inventor Forum
A sample of what ?

(I do not have an arduino so cannot test that part of the process)

The php part is identified in my definitive post above

Xiaomy Redmii

unread,
Feb 21, 2019, 7:04:05 AM2/21/19
to MIT App Inventor Forum
the code I provide

by changing the delays into 3 version

1 per device

TimAI2

unread,
Feb 21, 2019, 8:20:29 AM2/21/19
to MIT App Inventor Forum
How are you setting the current 8 second delay ?
Please show in your code ?

Xiaomy Redmii

unread,
Feb 21, 2019, 8:23:07 AM2/21/19
to MIT App Inventor Forum
I just make all the 500 to 800

SteveJG

unread,
Feb 21, 2019, 8:36:10 AM2/21/19
to mitappinv...@googlegroups.com
You did not change 500 to 800?  The units are milliseconds.. refreshing every 1/2 second is much more frequently than you need

Xiaomy Redmii

unread,
Feb 21, 2019, 8:49:19 AM2/21/19
to MIT App Inventor Forum
I don't get it :(
please help me with my code I already send it here
It is loading more messages.
0 new messages