0% found this document useful (0 votes)
51 views10 pages

Practical 7 - Cloud Service

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views10 pages

Practical 7 - Cloud Service

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

BAIT2123 INTERNET OF THINGS Jul 2024

Practical 7

Objective
Establish connection and communication between embedded system and cloud services

Part 1: Working with Firebase (using Raspberry Pi - Python)

Procedure
Step 1: Register an account at https://firebase.google.com/, refer to Setup - Firebase.pdf
* Do not use the TAR UMT student gmail account: it doesn't have Google Firebase features.
* Recommend to create a new Gmail account to be used among team members
(the gmail password could be used as part of log in procedure to be shown in your python code)

Step 2: There are many ways to establish connection to Google Firebase.


We use Pyrebase, that is a simple python wrapper for the Firebase API, pre-installed in our
Raspberry Pi module
* If you are using your own Raspberry Pi, do install Pyrebase by typing:
(for buster) sudo pip3 install pyrebase
(for bookworm) sudo pip3 install pyrebase4 --break-system-packages
* Reference: https://github.com/thisbejim/Pyrebase, https://github.com/nhorvath/Pyrebase4

Step 3: In Thonny Python (IDE), create a new python file named “test07.py”.
For using Grove Base HAT:
BAIT2123 INTERNET OF THINGS Jul 2024

For using Grove Pi+

1. Get the Firebase credential from the Firebase site > Project Overview> Project
Setting, modify the program code with the following codes, replace the details with
your own Firebase credentials, i.e., [API_KEY], [PROJECT_ID],
[DATABASE_NAME].
* Please follow the latest way of setting up the firebase credentials content

2. Run your code.

Task 1: Test your temperature and humidity sensor by facing it with a few breaths and
show it in your firebase’s database. Modify the code to display the values
without adding a new “child” (updating the same child values for every 2
seconds).

* Tips: refer to the Pyrebase / Pyrebase4 online document reference.


BAIT2123 INTERNET OF THINGS Jul 2024

Step 4: Test Database update with other sensors

1. Recall Practical 5 Step 5 or Practical 6 Step 1 to post push button or ultrasonic


sensor data to the Firebase’s Database.

Task 2: Adjust the database table and add additional sensors to store more data
(besides humidity and temperature) from different Raspberry Pi, with time
stamps.

Additional Support on using Google Firebase

Google Firebase with .NET


https://firebase.google.com/docs/reference/admin/dotnet

Google Firebase with C# (example)


https://www.example-code.com/csharp/fireBase.asp

Google Firebase with Android Project


https://firebase.google.com/docs/android/setup
https://firebase.google.com/docs/database/android/start
BAIT2123 INTERNET OF THINGS Jul 2024

Part 2: Working with Firebase (using NodeMCU ESP32)

Step 1: In Arduino IDE, install the DHT sensor Library:


- Tools > Manage Libraries... >
Search for "Firebase ESP Client"
Select Firebase Arduino Client Library for ESP8266 and ESP32 by Mobizt and
Click Install.

Step 2: Modify the default *.ino code to the following codes:


BAIT2123 INTERNET OF THINGS Jul 2024
BAIT2123 INTERNET OF THINGS Jul 2024

Step 3: Upload the compiled code to NodeMCU ESP32 Module and observe the result.
- Click Sketch > Verify / Compile and Sketch > Upload to compile this modified code and
upload to the NodeMCU ESP32 module.
- Check if the firebase status are sent to the Serial Monitor display
- Check if the Firebase content is updated accordingly

Task 1 : Modify the code to upload the temperature, humidity from DHT sensor, and
Ultrasonic distance values to the firebase.

Task 2 : Read the value from Firebase and turn on the Buzzer if the read value is = 1.

Reference: https://randomnerdtutorials.com/esp32-firebase-realtime-database/
BAIT2123 INTERNET OF THINGS Jul 2024

Other cloud services (Additional):

Part 3: Connecting to the cloud (internet) - thinkspeak.com, using Grove Pi+


* Similar work can be conducted by using Grove Base HAT

Step 1: Test Light and Sound sensors

* Picture is for illustration ONLY, please follow the steps correctly.

1. Connect a sound sensor to port A0, a Grove Light sensor to port A1 and a Grove
DHT sensor at port A2. Connect a green LED to port D3.
* Port A0, A1, A2 are analog ports
* Port D3 is the Pulse Wave Modulation (PWM) port, responding to the light conditions.

Step 2: In Thonny Python (ID), click “New” to create a new python file and Save As “test07.py”.
Type the following codes:
BAIT2123 INTERNET OF THINGS Jul 2024

Step 3: Register an account at Thingspeak.com, refer to Setup - Thingspeak.pdf

Step 4: Replace the api_key with your own one. Run the code.

* Explore the other way to display data (line graph, gauge chart, etc) by selecting
different visualization features in Thingspeak.com

* Attach with another display device (*Tips: setRGB is for ______, refer to Practical 4)

Task 1: Update more sensors value to the Thingspeak.com

Task 2: Modify the code to make LED brightness responses to the changes of input
sensors (e.g., sound sensor / light sensor)
BAIT2123 INTERNET OF THINGS Jul 2024

Part 4: Connecting to the cloud (internet) - Beebotte.com, using Grove Pi+


* Similar work can be conducted by using Grove Base HAT

Step 1: We use Beebotte.com, that is a simple IOT dashboard display, pre-installed in our
Raspberry Pi module
* If you are using your own Raspberry Pi, do install Beebotte by typing:
sudo pip3 install beebotte
* Reference: https://beebotte.com/tutorials/quick_start

Step 2: In Thonny Python (ID), click “New” to create a new python file and Save As “test08.py”.
Type the following codes:

2. Get the Beebotte credential from the Beebotte site > Account Setting > Access
Management (refer to Setup - Beebotte.pdf file), replace the content with your own
API Key and Secret Key.
BAIT2123 INTERNET OF THINGS Jul 2024

3. Run the code.

Task 1: Choose various graphical presentations to show the updated values.

Task 2: Extend the module to online reporting using one of these visualization
websites.

https://www.thethingsnetwork.org/forum/t/visualize-and-push-your-iot-data/1788

Task 3: Compare the advantages and disadvantages of each visualization website.

You might also like