This shows you the differences between two versions of the page.
iothings:laboratoare:2022:lab4 [2022/10/27 19:10] dan.tudose [Exercise 1] |
iothings:laboratoare:2022:lab4 [2025/03/20 18:30] (current) andreea.miu [Exercise 1] email authorisation info |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Lab 4: Databases for IoT ==== | + | ==== Lab 4: Databases for IoT - Firebase ==== |
- | In this lab assignment we'll explore hot to leverage online databases to write and read sensor data from an IoT application and access this data from anywhere in the world. We'll use two similar DB platforms: InfluxDB and Firebase. | + | In this lab assignment we'll explore how to leverage online databases to write and read sensor data from an IoT application and access this data from anywhere in the world. We'll use two similar DB platforms: InfluxDB and Firebase. |
==== Firebase ==== | ==== Firebase ==== | ||
Line 60: | Line 60: | ||
{{ :iothings:laboratoare:2022:firebase8.png?600 |}} | {{ :iothings:laboratoare:2022:firebase8.png?600 |}} | ||
- | Use the code below, replace the credentials at the beginning of the code (WiFi AP, password, DB URL and API Key) and the upload it to your ESP32 Sparrow board. | + | Use the code below, replace the credentials at the beginning of the code (WiFi AP, password, DB URL and API Key) and then upload it to your ESP32 Sparrow board. |
<code C firebaseWrite.ino> | <code C firebaseWrite.ino> | ||
Line 278: | Line 278: | ||
=== Setting Up DB Security Rules === | === Setting Up DB Security Rules === | ||
- | As you can probably notice in the previous exercise, you can only save the last recording of your data. If we want to log multiple readings for our data and also guarantee that our data is more or less secure, we will need to configure the Firebase DB. | + | As you can probably notice in the previous exercise, you can only save the last recording of your data. If we want to log multiple readings for our data and also guarantee that our data is more or less secure, we will need to configure the Firebase DB. |
+ | |||
+ | On the Authentication tab, select Sign-in method > Sign-in providers > Add new provider. From this tab, select Email/Password provider, which will allow logging in the database through email. To authorise your email for logging in, from the same tab select Users > Add user, and input your email and password. This action will generate a user UID associated with your data. | ||
On the Realtime Database tab, select the Rules tab at the top. Then, click on Edit rules, copy the following rules and then click Publish. | On the Realtime Database tab, select the Rules tab at the top. Then, click on Edit rules, copy the following rules and then click Publish. | ||
Line 447: | Line 449: | ||
==== Exercise 2 ==== | ==== Exercise 2 ==== | ||
- | <note> The code above sends fake temperature readings and also appends a timestamp to them, so they can be logged under a UUID. Modify the above code to send real temperature readings from the BME680 sensor with the added timestamps</note> | + | <note> The code above sends fake temperature readings and also appends a timestamp to them, so they can be logged under a UUID. Modify the above code to send real temperature readings from the BME680 sensor with the added timestamps.</note> |
==== Firebase Web App ==== | ==== Firebase Web App ==== | ||
+ | Firebase does not only offer the backend solution for storing your data, but we can also use it to build a hosted frontend complete with authentication and data visualization. | ||
+ | |||
+ | However, this will require more than what the online Firebase configuration interface can handle, so we'll have to install Firebase on our local computer, together with Node.js and a (better) IDE than Arduino to write code in. | ||
+ | |||
+ | You'll need to follow the next tutorials and install the necessary programs and tools: | ||
+ | |||
+ | - Install [[https://randomnerdtutorials.com/esp32-firebase-web-app/#install-vs-code | Visual Studio Code IDE]] | ||
+ | - Install [[https://randomnerdtutorials.com/esp32-firebase-web-app/#install-nodejs | Node.js]] (version 18.x LTS) and the [[https://randomnerdtutorials.com/esp32-firebase-web-app/#install-nodejs-extension-pack | Node.js extension pack]] for VS Code | ||
+ | - Install [[https://randomnerdtutorials.com/esp32-firebase-web-app/#install-firebase-tools | Firebase Tools]] | ||
+ | Follow the tutorial [[https://randomnerdtutorials.com/esp32-esp8266-firebase-gauges-charts/ | here]] to build a fully functional web app that can be accessed from anywhere in the world. | ||