Build

Publish/Subscribe for IoT with MQTT and PubNub Arduino SDK

3 min read Chandler Mayo on Jun 13, 2019
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.

An overview for using the PubNub Arduino SDK and PubNub MQTT Gateway to pub/sub data with two common WiFi modules included on Arduino-compatible development boards.

This is an overview for using both the PubNub Arduino SDK and PubNub MQTT gateway to send and receive data with two common WiFi modules included on Arduino-compatible development boards.

Hardware used:

Skip to Tutorials:

NodeMCU 1.0 ESP8266

MKR1000 ATWINC15001

Why Use PubNub with the Internet of Things

PubNub provides a robust and global messaging infrastructure that can transmit data in under 0.25 seconds anywhere in the world. This is ideal for instant updates from sensors or triggering a smart device action for instance. With a 99.999% SLA on all its services, IoT data is transmitted reliably. PubNub also supports over 70 SDKs and has features like push notifications and Project EON that you can use for monitoring. Sensor reading out of range? Get a notification.

With MQTT specifically, PubNub’s MQTT gateway makes it easy to switch to PubNub as your MQTT broker. You can use any MQTT client or library that supports MQTT 3.1 or newer.

Lastly, PubNub offers a serverless environment to execute functions on messages as they route through the PubNub Network. You can incorporate logic like:

  • Re-routing: Forward to other channels.
  • Augmenting: Supplement with more information.
  • Filtering: Remove outliers or strip words.
  • Aggregating data: Combine data before it’s received.
uv_index_-indicator

NodeMCU ESP8266 and LED Controlled with PubNub

Comparing PubNub Arduino SDK and PubNub MQTT Gateway

You may want to commit to one connection method over the other after considering the following:

  • If you’re building a new project: Start with the PubNub Arduino SDK. You’ll be able to take advantage of more PubNub features as they become available and won’t need to depend on an MQTT library.
  • If you’re already using MQTT in your project: The PubNub MQTT gateway is perfect for making an easy switch to PubNub as your MQTT broker.
  • If you need to use every last bit of memory: The PubNub Arduino SDK is optimized to be lightweight. However, you may be able to find or build a minimal MQTT library if you need every drop of memory.

Getting Started

First, download and install the latest Arduino IDE.

Next, sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys from the PubNub Admin Dashboard. PubNub is always free, up to 1 million real-time transactions per month (more than enough for R&D).

Sign up using the form below:

Next Steps:

We now have all of the core pieces you need to start building. Depending on the development board you are using, select one of the following tutorials:

NodeMCU 1.0 ESP8266

MKR1000 ATWINC15002

Other ways to expand your IoT projects with PubNub:

Have suggestions or questions about the content of this post? Reach out at devrel@pubnub.com.

More from PubNub

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff