Senior Content Strategist, PubNub
IN THIS ARTICLE

    Whether it be a simple electronics project with Arduino or a full embedded system with Raspberry Pi, building Internet of Things applications in the lab with IoT hardware, remote signaling may be an afterthought.

    You may have a single device, or a group of devices communicating with your server, on your consistent network. But take that device out in the wild, and it’s an entirely new ballgame. With inconsistent networks, environmental roadblocks, changing between WiFi and 3G, and 4G networks, signaling and sending data using Raspberry Pi isn’t so easy. This is where reliable and fast remote signaling is essential.

    With all the buzz surrounding the Internet of Things, its only natural for us at PubNub to dive right into it. We want to make it as easy and reliable to connect and remotely signal your IoT devices, whether you’re connecting your car, your smart home, embedded wearables, or shooting a nerf gun turret.

    Think of PubNub is IoT Embedded Remote Signaling 101.

    Raspberry Pi is a fully functional mini-computer, and is a cheap solution for harnessing the Internet of Things. It includes plenty of inputs and outputs for sensory add-ons to test light, temperature, humidity and more. Arduino on the other hand is a micro-controller, which is great for smaller scale electronics projects, like triggering LED lights or signaling to a quadcopter.

    This blog post walks you through the steps of connecting a Raspberry Pi and Arduino to the PubNub Data Stream Network for the purpose of remote signaling. PubNub sits as your communication for remote signaling between devices. This enables you to connect with millions of other devices on our global network and start sending and receiving data between Raspberry Pi or Arduino devices.

    Advantages of Connecting Raspberry Pi and Arduino to PubNub for Remote Signaling

    A built-out, globally redundant Data Stream Network provides reliable and secure remote signaling for Internet of Things devices. There are five pressing challenges when it comes to Internet of Things connectivity, with the two most paramount being reliable signaling (no matter what platform, device, or environment you’re building on), and security. You have to be 100% confident that you’re data will reach Point A to Point B when it’s sent, and you have to be 100% sure that nobody has access to your data.

    Luckily for you, PubNub Evangelist Bhavana Srinivas (@bhavana1110) whipped up a two step process to connect your Raspberry Pi or Arduino to the PubNub Data Stream Network. Below is the Raspberry Pi Tutorial, and keep scrolling down for Arduino. Or check out the full documentation for Arduino, Raspberry Pi, or our other IoT SDKs.

    Raspberry Pi Remote Signaling

    iot remote signallingConnecting Raspberry Pi to the PubNub Data Stream Network for the purpose of remote signaling is pretty simple. We’ll go through it in two steps.

    STEP 1: Connect the Pi to a monitor, keyboard, mouse and ethernet cable. Check out the Raspberry Pi website to set up your Pi. Log in to the Raspberry Pi OS and open IDLE, the python IDE. You’ll also need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal.

    STEP 2: Open a new window and paste the following code.

    The above code lets you set up the following :

    • publish key using “publish_key”
    • subscribe key using “subscribe_key”
    • UUID using “uuid”
    • channel you wish to subscribe and publish to using “channel”
    • message that you want to send. This is a JSON message

    This creates an instance of the iotbridge called pi and we can use the SEND and CONNECT methods belonging to that class.

    SEND: This invokes the publish() API to send any message over a desired channel.

    CONNECT: This invokes the subscribe() API to listen for messages from other embedded devices connected to the same channel. The call back function receiver is invoked when subscribe runs.

    You can customize the channels you publish/subscribe to, the UUID you assume and also the messages you send by just changing the above fields.You can now talk Raspberry Pi to any other device or application subscribing/publishing to the same channel. Check out all the code you need on our Github page to see it in action locally.

    Additionally, mobile software engineer Rex St. John created a tutorial of his own to get Raspberry Pi up and running on PubNub for the purpose of embedded devices.

    Arduino Remote Signaling

    arduino_5Connecting Arduino to the PubNub Data Stream Network for the purpose of remote signaling is pretty simple. Adruino is a great way to experiment with electronics and embedded devices. We’ll go through it in two steps.

    STEP 1: Connect the Arduino to a monitor, keyboard, mouse and ethernet cable.

    STEP 2: You’ll need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal.

    Open a new window and paste the following code.

    The above code lets you set the following :

    • publish key using “pubkey”
    • subscribe key using “subkey”
    • UUID using “uuid”
    • channel you wish to subscribe and publish to using “channel”

    For all of you who are familiar with Arduino, you will notice that this is in fact only a few additional lines of code in loop(). The remaining code sets up the Ethernet connection to the Arduino.

    The keys lines of code are just three lines:

    • arduino.init() that lets you initialize variables
    • arduino.send() that lets you send a message over the specified channel
    • arduino.connect() that lets you subscribe to a channel to receive messages

    We create an instance of the iotbridge called “arduino” and we can use the SEND and CONNECT methods belonging to that class.

    SEND: This invokes the publish() API to send any message over a desired channel.

    CONNECT: This invokes the subscribe() API to listen for messages from other embedded devices connected to the same channel.

    NOTE: The call back function receive is invoked when subscribe runs. Connect() will block on subscribe, waiting for a message to be sent to the device. You can write your own simple task scheduler and bounce between tasks according to their timing requirements.

    You can customize the channels you publish/subscribe to, the UUID you assume and also the messages you send by just changing the above fields. You can find the Arduino PubNub extensions here. For additional resources, check out the PubNub Arduino documentation page.

    Get Started
    Sign up for a free account and use PubNub to power IoT remote signaling

    Try PubNub today!

    Build realtime applications that perform reliably and securely, at global scale.
    Try Our APIs
    Try PubNub today!
    More From PubNub