Preparing Hardware

Let’s start from the very beginning, as I did not use my Raspberry Pi for quite a long time.

We will need:

  • Raspberry Pi board (or other IoT-oriented platform).
  • SD or microSD card (depending on the platform).
  • 5V/1A via micro-USB.
  • LAN cable, which provides the Internet connection.
  • HDMI display, RCA display, or UART port (to enable SSH).

The very first step is downloading Raspbian. I’ve chosen the Lite version, as I’m going to use SSH instead of display.

Things have changed since the last time I did it: now there is a great burning software called Etcher, which works perfectly, and has a stunning design.

After the image burning was completed, I inserted the SD card into my Pi, plugged the LAN and power cables in, and after a while, my router registered the new device.

Great! Let’s go on and SSH into it.

No way! SSH is disabled by default

Security is OK, I like it, but this makes things a bit harder. I’ll use UART-USB converter to access the shell and enable SSH.

Using a display instead of UART makes it much easier.

After rebooting, I’m finally in.

First things first, let’s update:

sudo apt update && sudo apt upgrade -y

Now let’s connect this fresh device to the Cloud.

Installing Cloud4RPi

I decided to try the cloud platform called Cloud4RPi, which is designed for IoT. According to the docs, we need the following packages to get it running:

sudo apt install git python python-pip -y

The client library can be installed in a single command:

sudo pip install cloud4rpi

Now we need some sample code to ensure it works.

git clone && cd cloud4rpi-raspberrypi-python
git clone e && mv e/ && rmdir -r e

I decided to run, but I don’t like the fake data. Luckily, I noticed an easy way to make the diagnostic data real in this example. Add one more import to the imports section: 

from rpi import *

Then delete these functions that provide fake data (the defines them now):

def cpu_temp():
    return 70
def ip_address():
    return ''
def host_name():
    return 'hostname'
def os_name():
    return 'osx'

Now we need a token, which allows Cloud4RPi to link the devices with the accounts. To get one, create an account on and hit the New Devicebutton on this page. Replace the __YOUR_DEVICE_TOKEN__ string in the file with your device’s token and save the file. Now we are ready for the first launch. 


 Open the device page and check that the data is there.

Now let’s move to real-world data.

Connecting the sensor

We will need:

  • DHT22 or DHT11 humidity sensor
  • Wires

The DHT22 sensor measures temperature and humidity simultaneously. The communication protocol is not standardized, so we don’t need to enable it in raspi-config  — a simple GPIO pin is more than enough.

To acquire the data, I’ll use Adafruit’s great library for DHT sensors, but it may not work as is. I once found a...

Read more »