Control Raspberry Pi & IOT Devices From Cloud Using Cloud4RPi

Sohail
Sohail

Table of Contents

Raspberry Pi is one of the best inventions of our times. We can use this low-cost device to make something really cool and useful. In this article, I will show you how you can control your Raspberry Pi and send instructions to the devices connected to your RPi from anywhere in the world.

What is Cloud4RPi?

Cloud4RPi is a very simple web control panel for accessing your Raspberry Pi devices. Configuring it takes not more than 2 minutes and you can access your Raspberry Pi anywhere in the world. So let’s start.

How to setup Cloud4RPi with Raspberry Pi?

  • Register a new account with Cloud4RPi (It is free).
cloud4rpi control panel

After you sign up, you’ll be redirected to your control panel. As you can see, there is already a control panel added to your account. It is a demo and clicking on it will give some demo services or devices running on a connected RPi.

cloud4rpi new control panel

To start adding our own device, let us create a new control panel first. Click on ‘New Control Panel’.

Add a device

Now add a device. Adding a device is really simple. Click ‘Devices’ from the top navigation bar.

Enter the new device name. It can be anything you like.

The next we will configure our RPi to talk to Cloud4RPi. For this, we will install an agent that will connect RPi to the web interface. Just use the following command to install Cloud4RPi agent.

sudo apt update && sudo apt upgrade -y
sudo apt install git python python-pip -y

sudo pip install cloud4rpi

If you have python3, then use -
sudo python3 -m pip install cloud4rpi

For ease, the developers’ team has created an example code for your device. Download it using git.

git clone https://github.com/cloud4rpi/cloud4rpi-raspberrypi-python.git && cd cloud4rpi-raspberrypi-python

Passing the above command will download the configuration file from github repo and move you inside the configuration directory. The final step is to enter the Token into the configuration file so that it can send data to our account on Cloud4RPi.

cloud4rpi client folder tree

Edit control.py file  –

nano control.py

Now move to the device page and click the device that you just created. Copy the Device Token. And paste this token in control.py where it says ‘__YOUR_DEVICE_TOKEN__‘.

cloud4rpi set device token

After this save the file(Ctrl+x > Y) and everything is setup.

Finally, run sudo python control.py to complete the setup.

connect rpi to cloud4rpi control.py

Now open Cloud4RPi dashboard and see it has received your RPi information.

my raspberry pi device

As you can see the information has been fetched. You can see the IP address, hostname, CPU temperature, etc. If you have more sensors or devices attached to RPi, you can get that information as well. 

Now click on Control panels and open the control panel that we created in the first step. Here you can add widget that will represent your devices’ data graphically.

cloud4rpi widgets

For these gadgets to work, you should first setup proper sensors or services on your RPi. You can send inputs to your devices from this panel. Let’s say you want to fetch room temperature or power on Coffee machine, etc. You can do all that right from your control panel.

Linux TutorialsNewUncategorizedtutorial