Build

PubNub & Raspberry Pi: Up and Running

2 min readJoe Hanson on Nov 5, 2013
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

How to get a Raspberry Pi up and running with PubNub and Raspbian for the purpose of connected/embedded device demos

This tutorial was originally published on rexstjohn.com. Rex St John is a mobile software engineer living in Seattle’s Capitol Hill neighborhood who has worked on a wide variety of enterprise and consumer mobile applications including touch walls, games, mobile sales tools and more.

raspberry pi

What follows is a tutorial outlining how to get up and running with PubNub on a Raspberry Pi running Raspbian. I have created this tutorial to walk through the process of getting up and running with PubNub for the purpose of connected device / embedded device demonstrations at the upcoming Wearable Computing AT&T Hackathon.

Step 1: Have a Raspberry Pi configured and running Raspbian

This should be relatively straightforward, your OS does not honestly have to be Raspbian but that is what I am using to go through this process. More than likely any common Linux distribution will be fine.

In my case I ordered a basic Raspberry Pi development kit which comes complete with an HDMI cable, an SD card, a mini-usb power supply and a plastic shell to keep you from shorting out the motherboard.

You will need to have a PubNub account…logged in and activated as a developer (free!).

Also make sure you have (obviously) some type of internet connection whether it be a WiFi Nub or ethernet cable. Assuming your Pi is plugged in, turned on and connected to the internet…proceed from there.

raspberry pi

Step 2: Clone into the PubNub C-Library GitHub Account

Create and navigate to a folder on your Desktop or other such desired location in the terminal. Much of this information can already be found on the GitHub page for the Raspberry Pi C client for PubNub here: https://github.com/pubnub/c.

On your standard command line run:

You will also need to run the following commands to install the libraries necessary to “make” or build the PubNub C libary

Next, browse to your “C” folder which you just cloned from GitHub where the PubNub C libraries now should reside

Step 3: Test Your Pub / Sub Connection

Time to try a publish / subscribe communication between your Pi and PubNub.

Open example-sync-demo.c with your favorite editor

Now change the following lines to match your PubNub pub / sub credentials. These credentials should be on your PubNub API dashboard:

raspberry pi

Replace the demo publish and subscribe tags below with your actual credentials in the example-sync-demo.c file.

Next, customize your message which you are publishing to something you will recognize (line 27):

Next, you will need to build a “.o” file by running “make” while in the examples directory. The result should be example-sync-demo.o.

Run this file in the terminal with: ./example-sync-demo

You should see the following:

Trackbacks/Pingbacks

mBed, Arduino, Raspberry Pi & PubNub Links – Rex St John

More from PubNub

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff