Author Archives: Joe Hanson

About Joe Hanson

Joe Hanson is Content Marketing Manager at PubNub, the world's only global data stream network for web, mobile, and IoT applications. PubNub enables IoT developers to easily, securely, and reliably connect and signal Internet of Things devices. Check PubNub out at PubNub.com

Building an IoT coffee maker with realtime capacity monitoring


Now you can see how much coffee is left in the pot without leaving your chair. 


You’ve all been in the situation before: You arrive at the office coffee maker in the morning only to find that it’s empty. If only you could curb that disappointment with realtime reporting on exactly how much coffee is left in the pot. Well fortunately for you, PubNub has harnessed the power of the ATmega328P MCU and the PubNub Data Stream Network to build the IoT Coffee Maker with realtime coffee capacity monitoring. The project works by collecting coffee volume levels and then streams the data in realtime to a live-updating UI.

In the video below, the coffee maker’s creator Kurt Clothier introduces his project, walks through some of the steps to build it, and shows it in action. If you want to get to creating one for yourself or your workplace, be sure to check out the entire IoT coffee pot tutorial and live demo on PubNub.

In a nutshell, the Atmel IoT coffee pot gathers volume data based on the weight of the coffee pot using a scale. The ATmega328P MCU is the brains behind the operation, while an ESP8266 is used for Internet connection. The volume data is then sent to a realtime web UI and visualized in realtime via PubNub Pub/Sub Messaging and the EON JavaScript framework.

atmel iot coffee maker diagram

The project requires the following:

Web UI updates the % of coffee left in realtime.

Web UI updates the % of coffee left in realtime.

Obviously, this tutorial can be expanded outside the kitchen to a broad number of powerful IoT use cases. With this same design, you can track readings from any number of sensors, and stream its data in realtime to any number of subscribers in realtime. Thinking big, you can implement similar technology in large scale industrial IoT settings, like agriculture, oil or medical.

You can even get rid of the scale altogether and use these concepts to collect data from anything with a segmented LCD screen. With that said, Clothier and the PubNub team would love to see what you come up with, so be sure to let them know about your awesome project! But for now, let’s enjoy the fact that we know exactly what percentage of the coffee pot is full.

Creating realtime IoT dashboards and maps with PubNub


EON is an open source JavaScript framework for creating beautiful realtime dashboards, charts and maps.


The realtime publishing and streaming of data is a key component of the Internet of Things, especially when it comes to tracking and monitoring connected devices. We need a way to easily collect, detect, and distribute data as it’s created or changes, and immediately have it be received and acted upon.

There are several great frameworks for bringing data to life: D3.js, C3.js, WebGL, the list goes on. However, the missing component is how to deliver and reflect changes in that data in realtime, a vital requirement of the ever-growing IoT. Whether you’re streaming sensor data to a dashboard, monitoring device(s) health, or tracking a fleet of vehicles on a live-updating map, delivering the data in realtime is essential.

With this in mind, PubNub wanted an easier way to stream data to create beautiful IoT dashboards, charts, and maps. And so, the team built Project EON, an open source Javascript framework. EON not only enables you to build these dashboards and maps, but stream the raw JSON data to them as well.

iot maps and geolocation

Let’s check out the details! Then we’ll show you EON in action, using an Atmel MCU (because what’s better than connecting hardware and software?).

Realtime Charts and Dashboards for Connected Devices

The charting and graphing component of EON is based on C3.js, an open source charting library. This allows you to build realtime line, bar, pie, gauge, and donut charts. When new data is streamed, transitions are animated and changes are reflected in realtime — no manual refreshing required!

These charts are especially useful when it comes to monitoring and displaying data from Internet of Things connected devices, and gives you flexibility on how you want to display that data.

EON bar, pie, and gauge charts

EON bar, pie, and gauge charts

IoT use cases include:

  • Home automation: Temperature readings, power usage and consumption for individual devices
  • Connected car: RPMs, state of fleet of vehicles, analytics on vehicles including gas usage, capacity, or money earned, vehicle telemetry
  • Industrial and factory: Oil field sensor readings, brewery analytics (eg. pressure, capacity), factory statistics

Mapping for Connected Vehicles and Wearables

Realtime maps are a staple of any connected transportation application. For applications on the move, you need a way to track movement and current location.

The mapping and geolocation component of EON is based on Mapbox, a series of APIs and tools for building custom maps. Give EON a marker icon (bus, train, plane, person), and a geolocation. When the geolocation is updated, the market animates and travels to the new location.

EON maps for bus systems, aircrafts, and wearables

EON maps for bus systems, aircrafts, and wearables

IoT use cases for live-updating maps include:

  • Connected car, fleet management and public transportation: navigation, taxi/rideshare dispatch based on proximity, collect and publish road conditions, hailing and fare calculation for car services, monitor and calculate route and arrival times for public transit
  • Wearables: navigation and tracking, fitness applications
  • Air and sea: track and monitor location of aircraft and sea craft for consumer travel, freight, and delivery.

In Action: Atmel MCU Realtime Temperature Sensor

So let’s see EON and the Internet of Things working together!

Our demo application is a realtime temperature sensor built using an Atmel | SMART SAM D21 Xplained Pro and a temperature sensor. The concept is fairly simple, we collect the data using the Atmel sensor, and stream it in realtime to a live dashboard, where the temperature data is displayed as it changes.

That streaming and visualization is EON at work. And with some CSS added on, we have something that looks like this:

xplained_pro_demo_gif

Just think, this is just a simple demonstration. Imagine having hundreds or even thousands of these sensors spread across a region, all collecting and streaming that data to a single dashboard. Or even a single sensor streaming to hundreds of dashboards, all simultaneously.

The use cases are endless, and it really comes down to collecting data, streaming data, and visualizing that data. And that’s where EON does the work.

To learn more about the Atmel Realtime Temperature Sensor demo, check out our full tutorial and code repository, or watch the video below.

The 10 challenges of securing IoT communications


From the very beginning of developing an IoT product, IoT security must be a forethought.


One of the hottest topics at last week’s IoT StreamConf was security. In other words, how are we going to secure communication for billions of connected devices? How can we ensure that attackers can’t take control of our devices, steal information, disrupt services, or take down entire networks of expensive, imperative devices?

With IoT is still in its early stages, security is not fully understood and well-defined when compared to other industries, like the financial and e-commerce sectors. From the very beginning of developing an IoT product, whether it’s small-scale like a wearable device, to massive-scale IoT deployments, like an oil field sensor network or global delivery operation, IoT security must be a forethought.

10-challenges-securing-IoT-PubNub-Atmel

In this talk, Rohini Pandhi, Product Manager at PubNub, walks through the ten challenges of securing Internet of Things communication. Rohini discusses flexible and secure messaging design patterns for IoT communication, and how they can be implemented and scaled. There are a number of security considerations, but after watching this talk, you should have a good idea of how you can secure your IoT deployment.

(Scroll below video for a table of contents of when individual concepts are talked about in the video).

Video Table of Contents

  1. Defining the Internet of Things (10:27)
  2. Unprotected devices will be attacked (13:15)
  3. Encryption (15:46)
  4. Single security model for all communications (17:56)
  5. Access control (20:13)
  6. Tracking device metadata (21:14)
  7. Provisioning in the field (22:38)
  8. Firmware updates in the field (24:07)
  9. Compliance with regulations (25:15)
  10. Reinventing the wheel (26:17)

More Resources on Securing IoT Communication

Below are a couple great pieces on IoT security, and some code tutorials for IoT developers:

Connecting an Arduino to a mobile cellular network


PubNub’s Ian Jennings demonstrates how to connect your Arduino to a mobile cellular network with a GSM/GPRS shield.


There’s a ton of tutorials out there on hooking your Arduino up to the LAN, whether it be Wi-Fi, an Ethernet, or other. But what about beyond the LAN? What if you want to connect your Arduino to the Internet in the wild?

In this tutorial from PubNub’s Developer Evangelist Ian Jennings, we’ll show you how to connect your Arduino to a mobile cellular network with a GSM/GPRS shield. This enables you to stream data bidirectionally or trigger device actions anywhere with a cellular network.

And, that’s powerful for any mobile IoT implementation (think connected car or drones) or apps without a Wi-Fi signal (think irrigation or weather sensor networks). Like like the many other DIY Arduino projects out there, it’s easy, affordable, and powerful.

So let’s get the tutorial started!

arduino mobile cellular network

What You’ll Need

  • Arduino UNO Rev3 (ATmega328)
  • Seeed Studio GPRS Shield V2.0
  • AT&T SIM Card (standalone)
  • C size batteries (x5)
  • C size battery holder (x5)
  • Smartphone
  • Laptop

Setting up the SIM Card

iphone-activation-card-600The first thing you’ll need to do is unlock the SIM card and make sure it has a data plan associated with it (hence why we included the smartphone on the list above).

Put the SIM card into your phone and read the instructions on the package. In the case of an AT&T SIM card, you may have to dial a series of numbers to activate the card, then configure the plan online, but this may vary depending on the carrier.

Note: Make sure your mobile plan supports data transfer and not just calls and texts.

Then, connect to a website on your mobile phone. If it works, you have data and the SIM card will work on your Arduino.

Setting up Arduino GPRS

Plug in your now-activated SIM card to your Arduino GPRS Shield. For how to do this, Seeed Studio has a great tutorial. Follow the tutorial, but stop and come back to this tutorial before uploading code in “Test Setup.”

Arduino Libraries

There are a fair amount of libraries needed to get setup on Arduino, but at the end, it’ll make it all a lot easier. The specific libraries for the Seeed Studio GPRS Shield v2 can be found here. In the docs, you’ll see the three libraries you’ll need to connect to a mobile network.

Import all three libraries into the Arduino setup.

Software Serial

Now that our shield and Arduino environment are ready, let’s move onto the fun part of this tutorial: playing with the cell networks. We need a way to talk to the SIM900 chip on the Arduino. Instead of using a hardware serial and talking directly to it, we’re going to use Arduino’s software serial.

Open up the SIM_900_Serial_Debug example from your Arduino examples folder.

This example is pretty simple. All we’re doing it proxying the serial data from Arduino’s serial port into SIM900’s. This enables us to use the included Arduino serial debug tool to interact with our SIM900.

void loop(){
  if(gprs.available()){
    Serial.write(gprs.read());
  }
  if(Serial.available()){     
    gprs.write(Serial.read()); 
  }
}

Call Yourself

To test everything out, we’re going to attempt to call ourselves with the Arduino GSM shield. First, load the software serial example onto the Arduino and then open up the serial debugger. Be sure to power the SIM card on the Arduino GPRS shield using the button on the side.

Power up the SIM900 by pressing the power button for around 2 seconds. The red LED will turn on. The green one beside it will begin blinking. If the shield joins the network successfully, the green LED will blink every 3 seconds. Wonderful!

Make sure you put your old SMS card back into your phone after testing the Arduino SIM. Now, type the following into your Arduino serial window.

AT

Serial output should show something like:

RDY
 
+CFUN: 1
 
+CPIN: READY
 
+PACSP: 0
 
Call Ready

If you don’t see the messages in the serial monitor, click the “send new” option that will add carriage return at the end of AT command, and then send AT command “AT+IPR=19200″ to set the baud rate of the SIM900.

Now try calling yourself. Enter the following command, replacing 1***8675309 with your own number.

ATD1***8675309;

If it succeeds, a message ATH OK will show up as the picture below. Otherwise, No CARRIER will show up instead. The reason might be nonexistent phone number or incorrect command format.

Connecting to the Mobile Cellular Network

Now that we’ve configured our Arduino to work over GSM, let’s get it connected to the mobile cellular network.

Make sure that the baud rate of SIM900 is 9600! You can use the AT Command(AT+IPR=9600) to set it through SerialDebug.

Load up the the GPRS_TCPConnection example from GPRS_Shield_Suli. This example makes a simple request tombed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n

However, it probably won’t run when you load it on your Arduino. This is because it’s not configured to work with your specific cellular network.

In my case I’m using AT&T, so I needed to change the following lines to configure my GPRS connection:

GPRS gprs(PIN_TX, PIN_RX, BAUDRATE,"cmnet");

This line isn’t sufficient in most cases. We’ll also need to supply an APN, username, and password. These parameters are omitted from the example but you can simply supply them on your own. You can find the relevant code here.

GPRS(int tx, int rx, uint32_t baudRate = 9600, const char* apn = NULL, const char* userName = NULL, const char *passWord = NULL);

To connect to AT&T, use the following config:

GPRS gprs(PIN_TX, PIN_RX, BAUDRATE, "wap.cingular", "WAP@CINGULARGPRS.COM", "CINGULAR1");

Now run the code. You should be able to obtain an IP and issue the request. However, the app will probably crash (SIM turns off) when the request has been issued. This might be confusing, but there’s an easy fix.

Battery Considerations

The Seeed Studio and a variety of other shields advertise to be “plug and play” with Arduino. However, this isn’t always the case. This shield in particular doesn’t have enough power from the single 5v USB supply to successfully complete TCP requests.

This is easy enough to fix though, all we need to do is give it more power! Online forums suggest adding 5 C-cell batteries to power the GSM chip, which is what we did below:

The batteries should be wired in series, with the positive end wired into the VIN input and negative wired into the GND. After you’ve added batteries, try the example again. It should connect successfully.

Great! Now we’re ready to signal with PubNub.

Signaling with the PubNub Data Stream Network

We’re going to use the PubNub Data Stream Network as our backend messaging layer for signaling our Arduino. This enables you to send and receive data bidirectionally between your Arduinos and signal to trigger device actions.

Load the following example onto your Arduino, changing the GPRS gprs() configuration as mentioned previously.

#include 
  #include 
  #include 
  #include 
 
  #define PIN_TX    7
  #define PIN_RX    8
  //make sure that the baud rate of SIM900 is 9600!
  //you can use the AT Command(AT+IPR=9600) to set it through SerialDebug
  #define BAUDRATE  9600
 
 
  GPRS gprs(PIN_TX, PIN_RX, BAUDRATE, "wap.cingular", "WAP@CINGULARGPRS.COM", "CINGULAR1");
 
  void publishData(String data) {
 
    Serial.println("attempting to publish");
 
    while (false == gprs.join()) {
      Serial.println("gprs join network error");
      delay(2000);
    }
 
    String str = "GET /publish/demo/demo/0/pubnub_gprs/0/\"" + data + "\" HTTP/1.0\r\n\r\n";
 
    // Length (with one extra character for the null terminator)
    int str_len = str.length() + 1; 
 
    // Prepare the character array (the buffer) 
    char http_cmd[str_len];
 
    // Copy it over 
    str.toCharArray(http_cmd, str_len);
 
    char buffer[512];
 
    if (false == gprs.connect(TCP, "pubsub.pubnub.com", 80)) {
      Serial.println("connect error");
    } else {
      Serial.println("publish success");
      Serial.println(data);
    }
 
    gprs.send(http_cmd, sizeof(http_cmd) - 1);
 
    gprs.close();
 
  }
 
  int counter = 0;
 
  void setup() {
 
    Serial.println("starting");
 
    Serial.begin(9600);
    // use DHCP
    gprs.init();
    // attempt DHCP
 
    while(true){
      publishData(String(counter));
      counter++;
      delay(1000);
    }
 
    gprs.disconnect();
 
  }
 
  void loop() {
 
  }

This example connects to PubNub and publishes a message every second. It works just like the previous example, but instead of retrieving data, this example streams information to the PubNub network where it’s accessible from anywhere.

Rest Client

You can see how the message is assembled by looking at the publishData() function.

See how the url is created here:

String str = "GET /publish/demo/demo/0/pubnub_gprs/0/\"" + data + "\" HTTP/1.0\r\n\r\n";

It may be confusing at first, but let’s break it down. The url is formatted according to the PubNub REST Push API.

http://pubsub.pubnub.com
/publish
/pub-key
/sub-key
/signature
/channel
/callback
/message

The domain pubsub.pubnub.com is defined later in the function. The publish key refers to is the pubnub command (you can also subscribe). The pub-key and sub-key come from your own PubNub account, but you can use thedemo keys for now. Don’t worry about signature.

The channel is really important. This is like an IRC channel for your PubNub devices to talk to each other.

Show Me the Data

Since we don’t have any other device listening for messages from the Arduino, let’s use the PubNub console to observe our channel activity.

If you’re using the default code above, you can use this link to view channel activity for your GPRS chip.

If your demo is running you should see a count like 1, 2, 3, 4 appear in the “message” pane.

We’re able to view the data coming out of the Arduino because we plugged the same publish and subscribe key into the PubNub console as we did into the Arduino. Since we’re using the demo keys the channel is shared publicly, but if you create your own account your data will be privatized.

Additional Resources and More Information

This is just one of our many Arduino-PubNub implementations. We’ve also connected Arduino Yún to the Internet, as well as showing you how to connect Arduino Uno and Seeed Studio Ethernet Shield v2. For all our Arduino related posts, here’s the full feed.


Ian Jennings is a developer evangelist at PubNub, a secure global data stream network for IoT, mobile, and web applications. He cofounded Hacker League, a site devoted to simplifying the organization of intensely collaborative tech events known as “hackathons.” Jennings recently pretty much guaranteed that he’ll always be able to keep himself stocked up on techno-gadgets with the sale of Hacker League to Intel’s Mashery subdivision for the price of more than a few PCs. But he’s not done. In fact, his latest invention, Mote.io, is a remote that connects your web browser with various music platforms like Pandora, Youtube, and Rdio, and has gotten raves on tech sites like GigaOM; he’s also in the midst of developing the Reddit app for the uber-hyped tech accessory Google Glass.

Realtime tech is changing the way we build online experiences


Users don’t want to wait for updates anymore, they want information in realtime.


App users were once content with static apps, single-user experiences where content changes only when a user requests a new page, clicks a button or refreshes the page. New information is presented only when a user requests it.

RealTimeTechnology

But times have changed. The average attention span of a human is 8 seconds, according to the National Center for Biotech Information. Users don’t want to wait for updates anymore; they want information in realtime. As a result, we’re seeing a major shift from static apps to realtime apps, web and mobile apps that mimic real life behaviors, pushing content and information “as it happens.”

The result is the birth of applications that have created industries that wouldn’t have otherwise been possible without this realtime functionality. Realtime technology is at the core of these apps and services; its lifeblood. And these apps are just a couple examples of the exponential growth of realtime web and mobile applications.

We’re seeing increased understanding of the benefits of realtime web tech so it’s not surprising that the number of apps using the technology is rapidly increasing. Common functionality includes simple data updates for notifications, dashboards (sports, finance, site analytics and anything that’s stat-heavy), realtime news and activity streams. Or more complex functionality for multi-user chat, collaborative applications, multiplayer games, interactive 2nd screen experiences, realtime mapping and GIS.”

– Phil Leggetter in 10 Realtime Web Technology Predictions for 2014

Taxi/Ridesharing Applications: A tight realtime loop

CarIconCircle

The days of standing out on the curb to hail a cab are dwindling. In fact, I’ve watched people let empty cabs drive right by them. Why would somebody do this? It’s the realtime user experience. Users prefer to hail, track, and pay for their fare seamlessly, all in one mobile app.

Realtime maps have become a staple feature of taxi and ridesharing applications. Users expect to be able to watch their car on a live updating map, giving them an ETA and assuring them that a car is really coming. But there are also other realtime features in these apps that are vital to the overall user experience. The apps are able to dispatch drivers in under a quarter of a second with the click of a button. They’re able to monitor and track fleets of vehicles, accurately dispatching vehicles without ever double booking or dropping rides. And most of all, they’re able to create one smooth ride experience, from hailing to payment, and everything in between.

This tight information loop, fast and efficient communication between themselves, the driver, and dispatch is the reason these ride sharing and taxi apps are so popular. And that tight information loop requires realtime technology to make it all possible.

Examples: Lyft, Sidecar, Uber, GetTaxi, Flywheel

Sports Score Applications: Updates as they happen

ScoreboardIconCircle

Static or slow sport applications can’t emulate the fast-paced action of actually viewing a live sporting event. To create this user experience, there’s needs to be information pushed to the user as quickly and often as possible. A simple clock and score board that updates every 10-20 seconds doesn’t have the real life feel and speed it needs to capture the attention of its users.

Realtime technology has changed that. Information is now pushed as it happens, to thousands of users simultaneously, anywhere in the world. These apps no longer just update the score and time, but rather are fully featured applications for out-of-stadium audience interaction. This includes collaborative features like polls and trivia, social feeds, live blogging, and live statistics. The app obviously won’t completely emulate the feeling of watching a live sporting event in the flesh, but it is changing the way that somebody out of stadium can experience a live sporting event entirely from their phone.

Examples: Manchester City FC Match Day Centre, ScoreCenter

Online marketplaces: Emulating a real life auction house

AuctionIconCircle

If you remember the early days of eBay, you probably pulled your hair out with the frustrations of the last 5 minutes of a heated bid war, repeatedly tapping ‘refresh’ to see if you were still the highest bidder. Then you refresh again, the auction is over, and you’ve been outbid. A static bidding application doesn’t mimic the excitement of a real life auction, and more importantly doesn’t enable users to bid rapidly with one another for an item.

“Behavioral emails are one of best ways to capitalize on in-app activity,” said Dane Lyons, Founder and CTO of Knowtify.io, the smart email engagement platform. “People really appreciate a brand that provides the information they really need when they need it.”

Today, online auction houses need to push high volumes of data as quickly as possible. They may have hundreds or even thousands of buyers watching and bidding on a single item. Data stream networks can power this, no matter where each bidder is located across the globe. This creates a reliable, low latency connection between all the bidders, the auctioneer, and auction application, ensuring a smooth and solid bidding platform.

ExamplesTopHatter, Catawiki

Home Automation: Reliable and secure realtime signaling

HouseIconCircle

When a user presses a button on their phone to turn on a light, they expect that light to turn on as if they’re flipping a switch. Or when you cross over a certain geographical location in your vehicle, you expect your garage door to open and your house’s heater to turn on.

It seems as though every home appliance these days has an IP address. Home automation solutions are becoming increasingly popular, and our houses are getting smarter and smarter. To provide and power a full home automation product, speed, reliability and especially security are paramount requirements.

This is where realtime device signaling comes into play, a key component of any home automation product. Device signaling requires a system that is bidirectional, where updates are sent through a dedicated channel that can trigger events (such as a light turning on). This signaling is needed on both the send side and the receive side. Though low latency is key for this signaling, security and reliability are just as important. When the security of your home rests in an home automation solution, encryption and additional security features need to be a core feature of the application. This ensures that unauthorized users can’t access the home automation application.

When you lock the door from your smartphone, you want that door to lock every time, and you definitely don’t want somebody else to be able to unlock it.

ExamplesRevolv, Insteon

These are just a couple different types of web and mobile apps that reflect the exponential growth and reliance of realtime technology. We want information as it happens. And realtime technology delivers that.

Interested in learning more? Be sure to browse through a number of PubNub’s latest blog posts, as well as surf through our archive on the company’s realtime network here.

Building an Arduino-powered smart home model


PubNub Evangelist Ian Jennings walks through the process of building a smart home from scratch using Arduino.


Down the road we may build a full-sized smart home, but for now we figured a model home laser cut out of Eucaboard would do just fine for now.

We wanted to showcase how home automation, [Atmel AVR microcontroller based] Arduino, and PubNub go hand-in-hand-(in-hand). More importantly, we wanted to show how important reliable, realtime connectivity is for building a fully-featured home automation solution.

As a result, our Arduino connected home was born. In the story below, the home’s architect/PubNub Evangelist Ian Jennings walks through the process of building the home from scratch (with .gifs!). In the future, we’ll roll out a technical tutorial so you can build one yourself.


Back in September, our founder Stephen and I were talking about ways to make it easier to demonstrate where PubNub sits with the Internet of Things. Attendees at conferences often ask if we’re a “hub,” a bluetooth device, etc.

In reality, we’re a data stream network; a service similar to a CDN that provides a simple and reliable way for IoT devices to talk to each other.

I decided instead of telling people people what PubNub is, we should show them. If I handed you a mobile phone and told you to press a button and then a garage door opened, you would understand that the phone sent a message to the garage door (via Arduino remote configuration).

How did it send the message? That’s PubNub.

So I built the garage door, and a front door, and some lights, and a house, and a mobile app, and I recorded every minute of it. You can check out that video below:

The PubNub IoT Model House from PubNub on Vimeo.

Why a house?

When I think IoT, my mind goes to home automation. It’s a great use case of a number of different connected devices where reliability and security are paramount. In this case, the house is a single IoT device that represents any number of devices.

I started by looking for a suitable “house.” Originally the idea was the have the house fold down so it could be packed and shipped around to conferences. This lead me to believe laser cutting was the best option, because the “snap fit” ability is not only sturdy, but portable.

I eventually stumbled upon this CAD file of a house from “The Simpsons.” It was extremely well designed and only $15. I took a 2 hour lesson here at ATX Hackerspace and learned how to use the laser cutter. A couple days later my roommate came home with some extra Eucaboard.

I wasted half of the board because Corel Draw determines scaling settings when each file is opened. Apparently I cut all 4 laser files at different scales, so none of the pieces fit together! Once I figured this out I had a clean cut.

From there I needed to glue the smaller parts like the windows and chimney. No need to set these up on the road.

It turns out gorilla glue is extremely messy because it expands over time. This created a bunch of huge solid glue globs that completely ruined the aesthetics of the house. I used a dremel to cut away at the excess glue. It took me a while but I definitely leveled up my dremel skills.

Then I started prototyping. I used an Arduino Uno Rev 3 and an ethernet shield to get up and running fast. I started with a breadboard, LEDs, and used electrical tape to test mounting the servos.

Hooking Up PubNub

Everything checked out so I started to hook it up to PubNub. We have drivers for Arduino which made it really easy.

I used a Seed Studio Ethernet Shield v2 to provide an internet connection to the IoT house. I didn’t have an Ethernet port around, so I was using my Macbook’s Internet Sharing setting to share the WiFi network connection to the Arduino. There were some slight modifications I needed to make for the SS v2 drivers to work with our v1 library (a full post about this fix coming later).

I opted to use a key value syntax to process messages. As you can see in the video, it was as simple as “garage:0” or “lightLeft:1” to close the garage and turn the left light on.

When I verified that this worked correctly, I soldered everything into a separate board that could be mounted inside the house.

Looking back now, this board should have been a “prototype shield” for Arduino but at the time I thought it would be so simple that it wouldn’t require an entire shield. This was a mistake, and there are now 7 extra wires that would have been unnecessary with a shield.

I built a simple UI in a CodePen to publish PubNub messages on the same channel the house was listening to. I then mounted the LEDs in the house, drilled mounts for the servos and connected them to doors, and mounted the circuit board and the Arduino + Ethernet shield to the house.

It worked!…

About half of the time.

There was something really strange about the behavior. I would have a great connection to PubNub and everything would work… then suddenly it was completely broken. I noticed that something was amuck, and I suspected it was the internet connection.

I dug down into the network, spending many hours looking at WireShark for hints and configuring the WiFi network.

I tried things like assigning an IP address to the Arduino, making sure the MAC address was correct, and even ordering a second Ethernet shield from a different manufacturer and switching from driver-supported USB to native Thunderbolt sharing. Eventually I was able to isolate the problem.

Whenever I opened the garage door, the ethernet shield would reset. I laughed, in what other situation could opening your garage door possibly destroy your internet connection?

Arduino Board Limiters

Arduino board has limiters in place that prevent you from drawing too much power through the board (and frying it). Every time the garage door opened, the servos were drawing all the current, not leaving enough for the Arduino and Ethernet shield to properly function.

I tested my theory with a few external power supplies. When I verified it fixed the problem, I wired in the battery pack you can see in the video.

That was it! I had the working prototype.

Assembling the IoT House

I showed it to my team at PubNub over video chat. They loved it, but seemed a little concerned about how to assemble it. After all, there were about 20 wooden pieces that fit like a puzzle, and then another 20 wires.

There was also a new plan. Now we had a deadline; an upcoming IoT conference in San Francisco. In addition, I wouldn’t be going with the house. It was going right to our CEO Todd who was attending the show.

I started to second guess my original plan of shipping the house to be assembled on spot.

My co-worker at ATX Hackerspace picked up an awesome Pelican case to carry his function generator and other crazy electronic gizmos safely to his clients this same day. He gave me quick demo and ensured that this was the way to go. I plopped the assembled house on top of the case and verified it would fit inside. Later that day I drove over to Fry’s and got one myself.

I glued the house together and decided I was going to ship it in as few pieces as possible. I glued the house walls together, cut out the styrofoam, and fit the house snugly inside the Pelican case.

Then I threw it off a table, kicked it, and tossed it down stairs.

I figured that I would subject the house to the worse torture possible while I could still fix it. Who knows what kind of abuse it will need to endure in shipping?

The house survived with minor injury.

I decided it was time to show this thing off. Test it in a live environment.

Showcasing the IoT House

I took it to HackTX, a hackathon hosted at the University of Texas here in Austin and run by my new pal Taylor. My other good pals Swift and Jon happened to be in town too.

I found a seat next to the students and set up the house. I repeatability assured the other contestants that I wasn’t going to be competing for any of the prizes.

There was a problem. I was connected to the UT campus internet, but their security settings prevented the network from being rebroadcast. I couldn’t share the WiFi from my Macbook to the Arduino. I learned after the fact that there is some way around this, but didn’t look to far into it.

Instead, I decided it was time to make this thing wireless. I did 30 minutes of research and decided I was going to replace the Arduino Uno and the WiFi chip with the newer Arduino Yún board. In addition to the WiFi chip, Yún has a second processor that runs Linux.

What better time to get this thing set up then at a hackathon? My roommate Nick showed up to the hackathon, so we both jumped in my hatchback, rolled down the windows, and cruised to a Radio Shack in South Austin. I called to confirm they had the chip, it wasn’t available at every Radioshack.

We didn’t support Yún at the time so I used our REST API documentation to write my own client. I really wanted JSON support and getting it to work with Arduino was difficult.  It took me the entire hackathon, but by the end…

It was complete.

I bought an external battery pack and a WiFi hotspot. I chiseled little spots out of the Pelican case to fit them in, and configured the Arduino to automatically connect to the hotspot.

The I went to Harbor Freight and bought a toolkit, extra tools, a soldering iron, etc. I rounded up extra servos, LEDs, wires, and wrote a debugging guide in case something went wrong with the house. I also recorded a video about how to take the house out of the case and set it up.

Then I dropped it off at FedEx. Overnight shipping to California.

The worst wasn’t over. Now it was time to wait for the call from our CEO Todd so I could walk him through setting it up.

I didn’t get a call, but instead a couple emails.  One at 6:43am said:

“Awake?”

I wasn’t.

“If so, call me. Starting set up now.”

Another arrive at 8:20am. I was awake for this one. It read:

“All works!”

I fell back asleep.

Wrapping Up

Working on this project was incredibly difficult yet also very fulfilling. I don’t have any formal electrical engineering experience, I’m a web developer by trade. I haven’t learned this much this fast since graduating college.

I was working extremely long days to meet the deadline. I would spend the entire morning just shopping for the right components, screws, glue, or paper. Then I would work, sometimes until 3 or 4am, getting everything together.

Thankfully Arduino makes things simple and I had a great network of people who helped me each step along the way. Alex, in particular was extremely helpful with electronics and another member of the space, Riley, spent on late Friday supplying me with every tool and component I needed during assembly like a surgeon’s assistant.

The IoT house is on display at the ground level office at 725 Folsom in San Francisco. It will also be displayed at upcoming IoT conferences which will be announced on our blog. If you would like me to give a talk about building IoT house at your conference, you can reach me at ian@pubnub.com.

Now to convince PubNub to get me a drone…

How to build remote configuration for Arduino devices

Arduino-Remote-ConfigurationA ‘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 [Atmel 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.

IoT Resources

5 IoT challenges for connected car dev

Growth in adoption of connected cars has exploded as of late, and is showing no signs of slowing down, especially the vehicle-to-infrastructure and vehicle-to-retail segments. As adoption grows exponentially, the challenges in how we develop these apps emerge as well.

One of the biggest challenges to consider will be connectivity, and how we connect and network the millions of connected cars on the road. How can we ensure that data gets from Point A to Point B reliably? How can we ensure that data transfer is secure? And how do we deal with power, battery, and bandwidth constraints?

connected car

1. Signaling

At the core of a connected car solution is bidirectional data streaming between connected cars, servers, and client applications. Connected car revolves around keeping low-powered, low-cost sockets open to send and receive data. This data can include navigation, traffic, tracking, vehicle health and state (Presence); pretty much anything you want to do with connected car.

Signaling is easy in the lab, but challenging in the wild. There are an infinite amount of speed bumps (pun intended) for connected cars, from tunnels to bad network connectivity, so reliable connectivity is paramount. Data needs to be cached, replicated, and most importantly sent in realtime between connected cars, servers, and clients.

2. Security

Then there’s security, and we all know the importance of that when it comes to connected car (and the Internet of Things in general). Data encryption (AES and SSL), authentication, and data channel access control are the major IoT data security components.

NHTSA-Connected-Cars

In looking at data channel access control, having fine-grain publish and subscribe permissions down to individual channel or user is a powerful tool for IoT security. It enables developers to create, restrict, and close open channels between client apps, connected car, and servers. With connected car, IoT developers can build point-to-point applications, where data streams bidirectionally between devices. Having the ability to grant and revoke access to user connection is just another security layer on top of AES and SSL encryption.

3. Power and Battery Consumption

How will we balance the maintaining of open sockets and ensuring high performance while minimizing power and battery consumption? As with other mobile applications, for the connected car, power and battery consumption considerations are essential.

M2M publish/subscribe messaging protocols like MQTT are built for just this, to ensure delivery in bandwidth, high latency, and unreliable environments. MQTT specializes in messaging for always-on, low-powered devices, a perfect fit for connected car developers.

4. Presence

Connected devices are expensive, so we need a way to keep tabs on our connected cars, whether it be for fleet and freight management, taxi dispatch, or geolocation. ‘Presence’ functionality is a way to monitor individual or groups of IoT devices in realtime, and has found adoption across the connected car space. Developers can build custom vehicle states, and monitor those in realtime as they go online/offline, change state, etc.

connected car

Take fleet management for example. When delivery trucks are out on route, their capacity status is reflected in realtime with a presence system. For taxi and dispatch, the dispatch system knows when a taxi is available or when its currently full. And with geolocation, location data is updated by the millisecond, which can also be applied to taxi dispatch and freight management.

5. Bandwidth Consumption

Just like power and battery, bandwidth consumption is the fifth connected car challenge we face today. For bidirectional communication, we need open socket connections, but we can’t have them using massive loads of bandwidth. Leveraging M2M messaging protocols like the aforementioned MQTT lets us do just that.

Building the connected car on a data messaging system with low overhead, we can keep socket connections open with limited bandwidth consumption. Rather than hitting the servers once multiple times per second, keeping an open socket allows data to stream bidirectionally without requiring requests to the server.

Solution Kit for Connected Cars

The PubNub Connected Car Solution Kit makes it easy to reliably send and receive data streams from your connected car, facilitating dispatch, fleet management applications and personalized auto management apps. PubNub provides the realtime data stream infrastructure that can bring connected car projects from prototype to production without scalability issues.

Finger on the IoT Pulse: ‘Presence’ Functionality

We talk a lot about connecting, networking, and securing the Internet of Things, and the billions of devices spread across the globe. Another essential piece of the IoT puzzle is monitoring those devices, specifically with what we call presence. 

Presence functionality gives IoT developers a way to monitor individual or groups of IoT devices in realtime. Whenever the state of the device changes, the change is reflected in realtime to a dashboard, with an alert, or any other way you want to display your tracking.

Internet-Of-Things-Presence

What Can Presence Monitor?

As soon as you start streaming large volumes of data, or signaling and trigger actions to devices, you need to know what devices are connected. So what kinds of device states can you monitor with presence functionality? Pretty much anything you want! With Presence functionality, you can build out custom device states including:

  • Online/offline status
  • Device health
  • Capacity for fleet management
  • Total device count in field
  • Battery/location status
  • Machine status (eg. currently working on X task, driver driving/offline)
  • Temperature and weather data from IoT sensors

With presence data, you can also log a history of device connectivity for audits and analytics. It’s not just about having realtime insight into your devices, but also tracking and logging performance, health, and other key metrics.

Why Is It Important?

Devices may get expensive: IoT devices can be expensive, so keeping tabs on your investment is essential. Device health presence monitoring gives you up to the millisecond health reports for device temperature, connectivity, battery life, etc, ensuring you that your device is 100% operational, all the time. And if any issues arise, you’ll know immediately that maintenance is required.

Devices may be imperative to operations/business: If IoT devices are at the core of business and operations, monitoring their health and status is paramount. Whether it’s agriculture readings, security sensors, or delivery fleet management, up to the millisecond device status can make or break a business.

Device Analytics: Accurate and up to date statistics and analytics is important to any IoT application or business. Presence functionality can store, retrieve, and playback collected analytics, for example, to give a history of device connectivity or health for audits.

Machine-to-Machine and IoT Use Cases for Presence

As we know, connected devices come in all shapes and sizes. And as IoT devices get smarter, more connected, more secure, and faster, they’re use in the field is skyrocketing across the globe. And as we add more devices into the field, realtime presence functionality is just as important as our device networks and IoT security.

Agriculture: As with other connected technologies, the Internet of Things has found heavy adoption in the agricultural industry. Sensors and monitoring devices for temperature, irrigation, weather patterns, and harvest management give farmers a realtime, accurate data stream, giving them full control over their agriculture system. As a result, keeping tabs on their vast system of IoT devices with presence functionality is key.

Figure-1_Rosphere-537x300

Connected Car/Shipping & Freight: Smart cars are shifting IoT boundaries and constitutes a disruptive and transformative environment. Connected car represents a large number of IoT use cases for automobiles including taxi, fleet management, shipping and freight, and delivery service. Connected cars require a secure and reliable connection to counter the various roadblocks that arise in the wild, such as constantly changing cell and network towers and dropped connections.

For taxi, shipping, freight, and delivery management, custom presence functionality is a vital component of the business, providing realtime custom vehicle and device states, such as vehicle and cargo capacity, location data, and device health.

2a818e001e8179cd0a0888b8dba99809

Home Automation: We’re well aware that our homes are getting smart. It seems today, every appliance has an IP address. It’s safe to say that the smart home market is prepared to take the world by storm. Especially for applications that enable users to control their homes remotely, presence functionality is essential. In the smart home, presence gives users a realtime view of their devices status (lights on, doors locked, water leak, thermostat, fridge temperature, etc). And that’s the basis of a solid home automation solution.

Internet-of-Things

Presence on the PubNub Data Stream Network

PubNub Channel Presence is one of the core features of the PubNub Data Stream Network. It enables developers to add user and device detection to their web, mobile, and IoT applications, giving realtime instant detection and notification of user/device status. Built on the global PubNub Data Stream Network, no matter where the devices are located, you can get an accurate and reliable reading on any custom device state you want.

For a quick tutorial on using Presence for IoT devices, whether it’s a network of 1000 connected devices or a single Arduino, check out our blog post: Realtime IoT Monitoring for Devices with PubNub Presence.

MQTT: M2M messaging for low-powered IoT devices

mqttMessage Queuing Telemetry Transport (MQTT) is a publish/subscribe messaging protocol for constrained, low-powered embedded Internet of Things devices. Think of it as the M2M (machine-to-machine) messaging protocol for low-bandwidth, high-latency, and unreliable network environments. This gives IoT developers a solid communication option when specifically working with embedded devices, which are expected to perform in “the wild,” while still needing to remain small, light, and have a high performance battery life.

Design and History Behind MQTT

MQTT was first developed in 1999, but has seen a massive explosion in growth and adoption with the surge of the Internet of Things. We now need a way to communicate, signal, and connect between low powered smart devices, and that’s where MQTT comes in. Built as a low-overhead protocol with strong considerations towards bandwidth and CPU limitations, MQTT has found its place in the embedded environment.

SmartDevice

In terms of design, MQTT is a publish/subscribe M2M protocol for embedded devices. It enables clients to connect as a publisher, subscriber, or both, and connect to a broker that handles message passing. There is plenty of documentation and open source client implementations if you wish to dive further into the protocol itself.

The Core of MQTT is the Topic

The ‘topic’ is at the core of using MQTT as an M2M communication avenue for embedded devices. It’s a simple idea, and it’s not unique to MQTT. However, the MQTT protocol harnesses the ‘topic’ fairly well. The ‘topic’ does several things, it’s most important being to ensure that a message is delivered to the correct subscribers. MQTT treats the ‘topic’ as a file path. Overall, think of the ‘topic’ as a simple communication filter, which makes the path application very powerful.

topic = "user/path/topic"

You could be interested in a particular higher level of the path or the leaf element. Without explicitly saying so, MQTT filters messages based on where you subscribe in the tree path. A simple idea, that can be used very effectively.

Technical Specifications of MQTT

Looking a little deeper into the technical aspects of MQTT, the M2M protocol runs on the top of a TCP/IP networking stack. When a client connects for publish/subscribe, MQTT begins the handshaking process. The MQTT header is two bytes, and the first byte is constant. In the first byte, you specify the type of message being sent, as well as the QoS level, retain, and DUP flags. The second byte is the remaining length field. There is more information you can glean from the MQTT specification if you are interested.

Building MQTT on a Data Stream Network

With PubNub now supporting MQTT over our realtime, global data stream network, we wanted to give an overview of the protocol and why you might or might not use it from our perspective. We just went through some of the inner workings, features, and the value the protocol. We’ll now take a look at why you might want to use MQTT with PubNub, or PubNub native exclusively.

EmbeddedWatchPubNubTo utilize PubNub, our gateway is mqtt.pubnub.com and we’ll handle all the broker services and provide you access to our network. First, you publish to a topic (at PubNub we call them channels). Anyone who is subscribed to that topic will receive the message that was published.

If you want to read more and see a more in-depth tutorial, check out our blog post on using MQTT with the PubNub Data Stream Network here.

You may be wondering what the advantage is of using PubNub Native over MQTT?

from Pubnub import Pubnub
 
def callback(message, channel):
    print(message, channel)
 
pubnub = Pubnub('demo', 'demo')
pubnub.subscribe('my_channel', callback=callback)
- See more at: http://www.pubnub.com/blog/what-is-mqtt-use-cases/#sthash.Fm9tmkN5.dpuf

MQTT targets low-powered embedded device environments where resources are scarce. PubNub solves the problems of large-scale connectivity for realtime apps and IoT devices. If you’ve already deployed MQTT-based infrastructure, it makes sense to take advantage of this new PubNub gateway to facilitate scaling and maintenance of your embedded device connectivity layer.

If MQTT is not part of your current infrastructure, you might consider leveraging the PubNub Realtime Data Stream Network directly along with PubNub’s numerous IoT SDKs for all of your Internet of Things connectivity. To start, we provide over 50 client SDKs to use, extensive PubNub documentation and our blog where we showcase useful tutorials with open source code, demos, and other write ups on all things realtime technology.

MQTT does have many open source client implementations and documentation, and is a great publish/subscribe messaging protocol for low-powered devices. The protocol has a small footprint and has some great MQTT use cases.

import paho.mqtt.client as mqtt
 
def on_message(client, userdata, message):
print(msg.topic, str(msg.payload))
 
def on_connect(client, userdata, flags, rc):
client.subscribe('my_topic')
 
client = mqtt.Client()
client.on_message = on_message
client.on_connect = on_connect
client.connect('mqtt.pubnub.com', 1883)
client.loop_forever()

Arduino + MQTT = Two Peas in a Pod

There are several Arduino-MQTT implementations and resources available today, and the two go hand in hand for developers working on embedded device projects. As a user, if you are looking for a very small publish/subscribe protocol, MQTT may be for you. If you need more features, or need to scale to hundreds or thousands of connected devices, that’s where PubNub comes in. The transition from MQTT to PubNub in both code and ideology is a quick, exciting process.

Happy Hacking!