Tag Archives: Realtime Data

Building a realtime temperature sensor with Atmel and PubNub


PubNub’s Bhavana Srinivas demonstrates how to build a realtime temperature sensor with PubNub and Atmel.


With the buzzword being Internet of Things (IoT), PubNub recently wanted to build something simple, yet powerful, that could extend beyond the hackerspace and be applied to the real world. It had to combine software and hardware, and allow people at home to build it and try it themselves.

Arduino came to mind, but seeing as though the team has already written a great deal of realtime tutorials using the Arduino board, they sought out to try something a bit different. Instead, the group decided upon employing Atmel | SMART SAM D21 Xplained Pro and PubNub to devise a realtime temperature sensor.

Project Overview

The Atmel temperature sensor monitors temperatures and streams the data to a live-updating dashboard, in realtime, anywhere in the world. The temperature sensor measures the ambient temperature and publishes it as a data stream to a channel via the PubNub Data Stream Network. A web browser that subscribes to this channel displays the data stream on a live visualization dashboard.

The Concept

demofunctionality

  • The Atmel I/O1 Xplained Pro sensor measures the ambient temperature.
  • This connects to the Wi-Fi using the ATWINC1500 module.
  • The PubNub code running on the Atmel chip enabled the team to publish the temperature in realtime to anyone subscribing to the same channel as a data stream.
  • Through the PubNub Developer Console, you can receive this stream of information from as many sensors as you like in realtime.

What Will You Need?

Hardware

components-1024x576

Software

  • Windows PC
  • To get your unique pub/sub keys, you’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Dashboard. PubNub’s free Sandbox tier should give you all the bandwidth you need to build and test your messaging app with the web messaging API.
  • Install Atmel Studio 6.2
  • Install updates to Atmel Studio as suggested during installation
  • Install terminal software like putty or teraterm

A prerequisite is that you upgrade the firmware for SAMD21 using the .bat file provided with the PubNub Atmel example before you run this demo. Make sure no other software like putty or teraterm is using the com port). Close Atmel Studio and the putty terminal. The firmware upgrade is successful if you see a PASS sign on the terminal after running the code.

Connecting the Hardware, the Right Way

atmel1-1024x576

  • Connect WINC1500 XPRO board to SAMD21 XPRO connector EXT1
  • Connect I/O1 XPRO board to SAMD21 XPRO connector EXT2
  • Connect OLED1 XPRO board to SAMD21 XPRO connector EXT3
  • Connect SAMD21 XPRO to a free USB port on your PC (make sure no other USB port on your PC is in use)
  • Connect the power to the port that says “DEBUG USB”

The Software

Open the PubNub example: pubnubAtmel/PubNub_EXAMPLE.atsln (included in the code download) in Atmel Studio and you will see the following page. Make sure you choose the debugger/programmer and interface as shown below.

opening-1024x576

Include the following lines in pubnubAtmel/src/main.h:

123
#define TEST_MODE_SSID “Enter-your-SSID” (choose THE Wi-Fi access point you want the chip to connect to)
#define TEST_MODE_PASSWORD “Enter-the password-for-the-SSID” (enter the password for the same Wi-Fi connection)
#define TEST_MODE_WITHOUT_PROVISION

In pubnubAtmel/src/main.c, add the channel name and pub, sub keys.

channel-1

Build (F7 / Build -> build solution), run(continue/ green arrow/ F5/ debug -> continue).

build

Open PubNub Developer Console, use the same channel name and pub,sub keys as in the code and SUBSCRIBE.If all is well, you should see a constant stream of messages in the following format: {“columns”:[[“temperature”,”55.00″]]}

fullsetup

From there, the PubNub crew was able to collect and stream temperature data in realtime. But what’s next, you ask? Well, they needed to do something with that data, right? Visualize it!

Visualizing the Data Stream

xplained_pro_demo_gif

Bhavana and the PubNub bunch didn’t just want to display raw data off the sensor as a live-updating number; instead, their partner-in-crime Tomomi built the beautiful temperature visualization, which mocks nursery or greenhouse monitor (a typical realworld use case for realtime temperature sensors).

The interface runs in the browser, and the technology behind is quite simple, using PubNub JavaScript APIs to subscribe the data sent from the Atmel chip. It’s simple, lightweight, built entirely in JavaScript, and accessible from anywhere in the world with any kind of device – mobile phones, tablets, and any smart device, as long as you have a web browser. The main purpose behind this is to present information in most efficient manner without losing its accuracy.

In this scenario, the UI shows the current temperature, also a simple line graph, updating in realtime so that you can tell the relative changes of the temperature, raising and dropping. This particular data is simple, but when you have multiple, more complicated data, data visualization plays more crucial role.

Go Conquer IoT

This demo is read-only and reads the ambient temperature, but in reality, you want to develop products that lets your users monitor and control, i.e, bidirectional communication between devices. For instance, if you have a smart A/C, not only monitoring the current room temperature, but you need to make it controllable from a remote devices.

“With the power of PubNub APIs, you can achieve this with no hassle. I hope I am leaving you guys with enough excitement to try this demo out, and also build cooler ones,” Bhavana concludes.

In the meantime, be sure to follow our friends at PubNub and Bhavana Srinivas on Twitter!

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.