• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Added User to Firebase ESP8266 WebApp can't change physical device

Q&A Forum › Category: ESP8266 › Added User to Firebase ESP8266 WebApp can't change physical device
0 Vote Up Vote Down
Brent asked 4 years ago

I add another 2nd email address to authorized users to the working Firebase App after Part 4. (of Firebase Web App ESP32&ESP8266 V1.0 book)  With the 2nd email I can logon OK, and when I toggle the GPIO’s on the web page, the web pages reflects the change from ON to OFF and visa versa etc .   BUT the physical GPIO’s (LEDs) don’t change.    They only change when I login with the first email to create APP.
Any ideas?  Thanks in advance

Question Tags: Firebase APP
9 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Does the second user write to the same database nodes as the other user?
What happens on the database when you click on the buttons on the web page for that second user?
Regards,
Sara

0 Vote Up Vote Down
Brent answered 4 years ago

Hi.   I now see that the second user is writing to a different UsersData node.  (with UID associated with second email account)  It is a duplicate of the data fields and it is being updated when the second user toggles something. But of course that doesn’t updated to the hardware since it is wrong UsersData node.    So how do I get the second user to be accessing the same UsersData node?   Do I just edit the second UID to be the same as first?  It doesn’t look like it is editable.

Thanks for your help

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.

The way the project is structured is that one user can only access its own data. It writes under a node with its UID.

If you want multiple users to access the same data, you need to organize your database in a different way.

Instead of each user writing to its specific node, they need to write to a common node. For example:
UsersData > data > …..

Then, you would need to change the database rules to only allow access to the database to those specific UIDs. For example:

{
    "rules": {
      ".read": "auth != null && (auth.uid === 'UID_OF_USER_1' || auth.uid === 'UID_OF_USER_2')",
      ".write": "auth != null && (auth.uid === 'UID_OF_USER_1' || auth.uid === 'UID_OF_USER_2')",
    }
}

I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
Brent answered 4 years ago

OK, I change the Firebase Realtime Database rules under Edit rules from the original setup

// these rules grant access to a node matching autorized UID
{
    “rules”: {
       “UsersData”: {
          “$uid” :{
              “.read”: “$uid === auth.uid”,
              “.write”: “$uid === auth.uid”
          }
      }
   }
}

to the following New Rules;

// these rules grant access to a node matching autorized UID
{
    “rules”: {

        “.read”: “auth !=null && (auth.uid === ‘P2Nla…’ || auth.uid === ‘9xHd…’)”,
       “.write”: “auth !=null && (auth.uid === ‘P2Nla,,,’ || auth.uiD === ‘9xHd…’)”,
       }
}

 

I have truncated the actual UIDs (In this reply) to better fit this screen.
After this change, the first UID can still function ok.  ie webAapp changes the Firebase Realtime Database and the actual hardware LEDs.   But when I log on with the second email and try to change something on the webApp it still generates a new UsersData Node with it own datafields etc but of course this does not change the hardware.
What am I missing?
Thanks for your help

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
 
That is happening because they are not writing to the same database nodes.
As I’ve mentioned previously, you need to change the database structure, so that all users publish to the same node.
To do that, you need to change the Javascript code and the Arduino code.
 
In the Arduino code, you need to change the path, so that it no longer writes to the node with the UID. So, it can be simply like this:

databasePath = "/UsersData";

Instead of

databasePath = "/UsersData/" + uid;

 
In the JavaScript file, you also need to change the paths. You need to remove the uid from all paths:

// Database paths
var dbPathBtn1 = 'UsersData/'outputs/digital/2';
var dbPathBtn2 = 'UsersData/outputs/digital/12';
var dbPathSlider1 = 'UsersData/outputs/pwm/13';
var dbPathSlider2 = 'UsersData/outputs/pwm/14';
var dbPathBmeTemp = 'UsersData/sensor/temperature';
var dbPathBmeHum = 'UsersData/sensor/humidity';
var dbPathBmePres = 'UsersData/sensor/pressure';
var dbPathInput1 = 'UsersData/outputs/message';

 
This way, all users will be publishing and listening to the same nodes.
 
Regards,
Sara

0 Vote Up Vote Down
Brent answered 4 years ago

Thank you for the help.   I follow what you have suggested (edited the arduino code and the index.js code to remove references to uid in the paths,  and it works great when I am run the app via New Terminal in in VS Code with “firebase serve –only hosting”.  It works well for accessing  2 different email logons, they can both toggle the GPIOs, the hardware LED’s update with Realtime Database updates.  I thought great problem solved!

But when I try to deploy with “firebase deploy” in VS code terminal and then access my app as https://esp-iot-app-4xxxx.web.app/ it is no longer working.   neither of the 2 email users can change the GPIO (or the UsersData)
in fact the app on the website can’t retrieve the current state of the GPIOs

Getting closure to solution (with it working on local before deploying but not there yet)
Again I thank you for your help

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Try to deploy the web app again and refresh the web page.
Double-check the deploy history on the Firebase console (Hosting tab) and check that it is running the latest version.
Regards,
Sara
 

0 Vote Up Vote Down
Brent answered 4 years ago

Hi Sara,  I seam to have mess up something, because now I don’t even have my localhost version working.
(I had tried changing my OLED from a 0.91″ which I had, to a new 0.96″ which arrived yesterday.  I though only change Screen_ Height from 32 to 64.  The I2C address remain the same as 0x3c, because this is a Chinese knockoff and I checked via a simple I2C device scanner program).
Anyway, I will restart this project from the beginning (delete my project and start again) and then get back to you later
Again thanks for you help,
Brent

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Ok.
Check that VS Code is opened with your Firebase project and that the commands you’re running on the Terminal are running on the Firebase Project directory.
 
Then, let me know if you succeed with the project.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.