IoT Hands On: Build a Realtime App with Raspberry Pi 2 and PubNub
Step-by-step guide of building a realtime Internet of Things application using sensor data from Raspberry Pi 2. Just released, this hardware makes it quick and easy to build and deploy internet-enabled sensors. You'll also learn how to aggregate that sensor data and display it with realtime updates over the PubNub network.
For Workshop attendees, please fill this out after the session. Thank you :-)
The workshop slide deck is available at: https://docs.google.com/presentation/d/1kHjN8CIbggBlr44m2JpsRpR6IHB-Yu7b5bECC-_ntK4/edit?usp=sharing
Setting up Raspberry Pi
Skip the Step 0 and go to Step 1, if you have a preloaded SD Card from CanaKit or elsewhere.
0. Formatting an SD Card
The following steps are done on your computer.
- Download SD Formatter 4.0 and install on your computer.
- Insert it in SD card reader in the computer. If you need, use a Micro SD adapter (photo).
- Run the SD Card Formatter.
- Download the Noobs zip file from raspberrypi.org and extract to a desired location.
- Open up the SD card drive, and drag-drop the unzipped Noobs contents (not the entire folder!) you just downloaded, into the SD card. Then eject the SD card.
1. Installing Raspbian on Raspberry Pi
From now on you are working directly on your Raspberry Pi.
- Insert the formatted SD card in Pi.
- Plug in your USB keyboard, USB mouse, and HDMI monitor cables.
- Plug in your Wi-Fi adapter.
- Plug a USB power, and turn your Pi on.
After connecting to a monitor:
- Your Raspberry Pi will boot, and a window will appear with a list of operating systems that you can install. Select Raspbian by ticking the box next to Raspbian and click on Install.
- Raspbian will run through its installation process. Just wait. This takes a while.
- When the install process has completed, the Raspberry Pi configuration menu (raspi-config) will load. You can exit this menu by using Tab on your keyboard to move to Finish.
2. Starting Raspbian
The default login for Raspbian is username pi with the password raspberry.
When you see a prompt, start the GUI.
pi@raspberrypi ~$ startx
If you get the following message, ignore it for now: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject
3. Configuring Wi-Fi
Go to Menu > Preference > WiFi Configuration
- When you see the WiFi config window, click Scan.
- Find your wireless access point from the list and double-click it. It will open another window.
- Enter your passwork in PSK field then click Add.
- On the first window, click Connect.
Update and Upgrade Raspbian
First, update your system's package list, by using this command on a terminal:
sudo apt-get update
Next, upgrade all your installed packages to the latest versions:
sudo apt-get upgrade
Remote Connect Your Raspberry Pi from Your Laptop
When you do not have an access to work directly on your Pi, you may need to access to your Pi from another computer.
Getting Pi's IP Address
First, open LXTerminal:
Obtain an IP address of your Pi:
$ hostname -I
You will need the IP address in the next step. (Remotely connecting your Pi)
Remote Connect Methods
There are multiple ways to connect you Pi from your own laptop:
Getting started with Programming Pi
Hello World with PubNub
Let's write your first PubNub publish program:
Hello World with Hardware
Your First IoT
- IoT-fying LED: Remote-control LED from Web Interface
Now, let's connect some sensors to Raspberry Pi, and learn more about sending and receiving data to/from the sensors using PubNub APIs!
Check out more projects under: