Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Arm Research
    • DesignStart
    • Education Hub
    • Graphics and Gaming
    • High Performance Computing
    • Innovation
    • Multimedia
    • Open Source Software and Platforms
    • Physical
    • Processors
    • Security
    • System
    • Software Tools
    • TrustZone for Armv8-M
    • 中文社区
  • Blog
    • Artificial Intelligence
    • Automotive
    • Healthcare
    • HPC
    • Infrastructure
    • Innovation
    • Internet of Things
    • Machine Learning
    • Mobile
    • Smart Homes
    • Wearables
  • Forums
    • All developer forums
    • IP Product forums
    • Tool & Software forums
    • Pelion IoT Platform
  • Activity
  • Support
    • Open a support case
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • More
  • Cancel
Internet of Things
Internet of Things
Internet of Things How to build remote configuration for Arduino devices
  • Blog
  • Videos & Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
  • New
Internet of Things requires membership for participation - click to join
More blogs in Internet of Things
  • Internet of Things

  • Wearables blog

Tags
  • internet_of_things
  • Arduino
  • iot
  • home_automation
  • pubnub
  • configuration
  • remote
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

How to build remote configuration for Arduino devices

Joe Hanson
Joe Hanson
November 19, 2014

A 'smart' device isn't smart if you can only control it locally. What good is that? You need the ability to control your devices remotely. And that's where remote configuration comes into play. Remote configuration enables developers and users to trigger actions and control their devices from anywhere. The device state interprets a signal that is transferred through a network (in this case, PubNub), and is interpreted to permanently change the state of a device (like a light bulb turning from off to on).

A Messaging Layer for Remote Configuration

In this tutorial, we'll show you how to make remote configuration a reality for [Microchip-based] Arduino connected devices. In developing, we came across two issues.

  1. The need to detect the device state of all connected devices (eg. online/offline status) in realtime
  2. The state of the devices connected to the cloud

The first one can easily be solved using the Presence API, so let's focus on the second issue. We'll be using Storage & Playback to store and retrieve the state of connected devices for a home automation solution. In this case, we'll be able to control smart devices remotely, sending signals in realtime. A typical example of a state will be a JSON object looking like this:

{"state":[    

     {"alive":"true"},    

     {"CoffeeAmount: Half"},    

{"Temperature":"45"} ]}

Overall Procedure for Arduino Remote Configuration

  • Sign up for a free PubNub account. In doing so, you'll get your unique publish/subscribe keys which you'll use to initiate PubNub. These keys can be found in the Developer's Console.
  • Publish messages through the PubNub IoT Network using Arduino to control smart devices.
  • Access these messages through a web browser.

Onto the tutorial!

Step 1: Connect to PubNub

Say we want to control the temperature on a refrigerator. The following parameters can be stored as the state of the device, for example, seeing if the door is open/closed, temperature, power consumption, and even volume of our fridge.

arduino remote configuration home automation Run this on the Arduino IDE, and check out the tutorial on connecting PubNub to Arduino in 2 steps for more details.

Step 2: Create a JSON Object in Arduino

To create a json object in Arduino, we use the JSON.h library. The above JSON object can be created using the following:

aJsonObject *msg = aJson.createObject();

     aJson.addStringToObject(msg, "name", "Arduino");

     aJson.addNumberToObject(msg, "TemperatureOutside", 34);

Step 3: Signaling Devices

Other than that, it’s just about publishing a message using the Arduino IDE. The following code lets you do just that:

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char pubkey[] = "demo";

char subkey[] = "demo";

char channel[] = "devices_state";

//setup void setup()

{

     Serial.begin(9600);

     Serial.println("Serial set up");

     while (!Ethernet.begin(mac)) {

          Serial.println("Ethernet setup error");

          delay(1000);

          }

          Serial.println("Ethernet set up");

          PubNub.begin(pubkey, subkey);

          Serial.println("PubNub set up");

}

// establishing internet connection to the Arduino and publishing the state void loop()

{

          Ethernet.maintain();

          EthernetClient *client;

          client = PubNub.publish(channel, msg);

          if (!client) {

               Serial.println("publishing error");

          } else {

               client->stop(); }

          delay(5000);

}

And one more thing, what if we were able to check the state of devices in simply a web browser? Paste the code below in a browser console and watch the state be filled in.

// Initialize with Publish & Subscribe Keys

var pubnub = PUBNUB.init({     

     publish_key: 'PUBLISH_KEY_HERE',     

     subscribe_key: 'SUBSCRIBE_KEY_HERE',     

     uuid: 'devices_state'

});

// Retrieving the messages that have been published on to this channel using History.

pubnub.history({     

     channel: 'history_channel',     

     callback: function(m){console.log(JSON.stringify(m))},

});

That's it! Just a note, PubNub doesn't limit the number of messages that you can publish or retrieve via history. You can try this out with as many Arduinos as you want, and check their state remotely.

The use cases are endless for remote configuration, from agriculture to shipping and logistics, to home automation. It gives you complete control over your smart devices from anywhere on Earth, and that’s powerful.

Anonymous
Internet of Things
  • Internet of Things: The secrets to delivering successful IoT projects

    Jesse Dukes
    Jesse Dukes
    For enterprises and OEMs there is huge opportunity to be gained in the adoption of IoT. Learn from experts in connectivity: the Mobile Network Operators.
    • June 17, 2020
  • Internet of Things: Arm Corstone Virtual Platforms now Available at no Cost: A Simplified, Faster Route to Successful Secure SoCs

    Radhika Jagtap
    Radhika Jagtap
    The Arm Corstone-300 and Corstone-700 Fixed Virtual Platforms are now available at no cost to easily and instantly start early exploration and software development ahead of silicon availability.
    • June 15, 2020
  • Internet of Things: Improving Trust in Data with Pelion Device Sentry

    Duncan Jones
    Duncan Jones
    In this blog, read about the May 2020 updates to Pelion device management.
    • June 5, 2020