SlideShare a Scribd company logo
1 of 12
Download to read offline
Streaming Geo
Coordinates from
MongoDB to your
iPhone App with
PubNub using
WebSocket SDK!
by Stephen Blum
Not long ago we partnered with a high-
standards online engineering broker (an
online listing service where you can post
engineering projects). The partnership
involved joint PR and blogging, however a
new opportunity/idea was presented. This
particular idea stemmed from a
commission listed on the broker’s website
which listed requirements for building an
integrated Real-time Map Service. We took
the opportunity and built a Ruby GEM with
a sprinkle of documentation and HTML5.

Continue through the slides for a quick start
guide to build an integrated real-time map
service.
For those of you who need a quick mini-guide to getting your MongoDB installed and running with
data sync streaming directly to your mobile app, you can follow this guide:
MongoDB Pipe GitHub Repository. It will show you how to download/install MongoDB and the
MongoPipe GEM.

Real-time Data Stream of Geo Coordinates

Lat/Long from MongoDB replicated to your iPhone App

The commission at the online workplace was posted as a $3,025 bounty. Rather than taking the
commission for ourselves, which involves building and delivering the solution in a private exchange,
we instead reviewed the specifications and requirements and we developed an open source
implementation that you can download and run for your live app today! MIT License, so you can use
this however you desire. We even created a GEM for you and made it easy to get started:
gem install mongopipe
Downloading the GEM is the first step in the process and next we’ll walk you through more details.
Actually now may be the time for you to watch the short video (next slide), so feel free to jump into
that now if you want a very brief demonstration and usage covering these points:

1.  Installing the Ruby gem and

2.  Executing the commands to setup MongoDB and

3.  Running the Pipe Daemon.

4.  Launching the Map Viewer.

5.  Finally inserting lat/long coords into MongoDB.

6.  Result is live-animated points on a map displayed on the iPhone.
The video will show usage of the MongoPubNubPipe gem. Source code is available via GitHub if you
want to see everything - MongoDB Pipe GitHub Repository
MongoPubNubPipe::Connect.new(...)	
MongoDB Geo Coordinates

This becomes the new interface that is available with mongopipe gem:



Usage of MongoPubNubPipe is available in later slides.
The video demonstrates an implementation of the connection between MongoDB and a mobile
device (an iPhone in this case). This application code and gem library will provide you a way to easily
add a live always-on map connection which allows you to send lat/long signals directly to the device
displaying the map with the specific Lat/Long DB written into MongoDB. This will cause the device
to draw an animated dot onto the screen of the device in real-time.

The dot that animates is triggered by simply writing to your MongoDB collection directly either
through the mongo console or through your RoR/Ruby Server Code. For example here is a MongoDB
Console Command that will cause a DB write, creating a Document, which then triggers the sync
with the consumer iPhone device that is rendering the map in real-time.
db.collection_name.insert({ latlon : [ 1.5, 2.0 ] })
gem install mongopipe	
Once you’ve written a Lat/Long coordinate into MongoDB collection, the process begins instantly
synchronizing with any connected iPhone. We where able to include several feature requests and
here follows the requirements:

When a new Lat/Lon document is inserted into MongoDB, stream the Lat/Lon data to a mobile
device is push data.

Use a Ruby or Node.JS Service to stream the data out of MongoDB as it is written in real-time.

Simple enough, yes, though it requires moving pieces. We simplified the process and built two
modules: one in Ruby and one in HTML5. We’ll walk through the methods for getting you started and how
to hook into the stream on your iPhone App. You can fast-track the tutorial and go strait to the
GitHub Repository or gem install mongopipe package for ruby.

GitHub Repository

MongoDB Pipe GitHub Repository
How it Works

MongoPipe is a new tool powered
by PubNub that streams your
MongoDB Documents from your
MongoDB Collection directly to your
iPhone App in less than 0.25 seconds
(real-time) using the PubNub Real-time
Network. Your iPhone app opens an
always-on TCP Socket Connection to
PubNub while a dispatch process runs
on your MongoDB server via Tailable
Cursors to catch inserted documents.
The data is streamed and brokered via
PubNub Network directly to your
iPhone App in real-time.
mongod	
require 'rubygems'	
require 'mongopipe'	
	
## ------------------------------------------------------
## Pipe MongoDB for Inserts	
## ------------------------------------------------------
MongoPubNubPipe::Connect.new(	
:puts_usage => true,	
:publish_key => 'demo',	
:subscribe_key => 'demo',	
:db => 'test',	
:collection => 'cap_collection',	
:callback => lambda{ |doc|	
## Optional Callback Called on Doc Insert	
## Remove :callback if you don't need it.	
puts(doc)	
}	
).pipe()	
MongoDB Tailable Cursors

The ruby GEM mongopipe utilizes the tailable
cursor interface provided by MongoDB
Core. Document Data is then piped directly
through the PubNub Network which uses a
direct broadcast synchronization socket
with the mobile app.

Next we’ll show you what the process is to
get the mongopipe running on your Ruby
Server.

Make sure MongoDB is running

Next open a text editor and copy/paste the following
monogopipe example.













Save this to a file pipe.rb for example then execute it.
Ruby pipe.rb
Step 1: Open Your Browser to Show PubNub Pipe Console	
This will connect directly to MongoDB and print usage guide on next steps. The video covers only a
demonstration of this process. Here is a sample output of what may be provided via the puts(doc) output:
> Open http://www.pubnub.com/console?channel=test.cap_collection	
Step 2: Open Demo Map on Your Phone	
> Open http://goo.gl/HAqAv#test.cap_collection	
Step 3: Insert Test Data	
> ./mongo	
> Use test	
> db.cap_collection.insert({ latlon : [ 1.5, 2.0 ] })
Remaining Details

This blog entry was intended to give you a quick
skim over the details on how the mongopipe ruby
gem works and what is involved in coordinating
the embeddable mobile HTML5 animated map.

If you have any more questions please
tweet @PubNub directly.

You may be curious about the connectivity
mechanism between your iPhone App and your
MongoDB Sever. Checkout the PubNub
WebSocket Reference below to see the
transport mechanism utilized.

Thank you for reading!
PubNub WebSocket Reference

The MongoDB Pipe uses the PubNub Network WebSocket interface which provides an always-on
socket connection to your iPhone app. The PubNub Network WebSocket acts as a broadcast
receiver and syncs directly to your mobile device in real-time from your MongoDB server via
MongoPipe.

Following is an example of how the Map app implements the socket:
// Create Socket Connection	
var socket = new WebSocket(	
'wss://pubsub.pubnub.com/PUBLISH_KEY/SUBSCRIBE_KEY/CHANNEL'	
);	
	
// Set Message Receiver Function	
socket.onmessage = receiver;	
	
// Receiver Function Prints Data Result	
function receiver(evt) { console.log(evt.data); }

More Related Content

Similar to Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK

Microservices in Golang
Microservices in GolangMicroservices in Golang
Microservices in GolangMo'ath Qasim
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentationscandiweb
 
Pwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventPwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventAhmed Kaludi
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentDevenPhillips
 
What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfShaiAlmog1
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGrant Goodale
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoJosh Justice
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partnerDesignveloper
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)alloy020
 
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectIntro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectLauren Hayward Schaefer
 
iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008rmzdotno
 
PhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementPhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementTrieu Nguyen
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Bruce Pentreath
 
Hybrid Apps in a Snap
Hybrid Apps in a SnapHybrid Apps in a Snap
Hybrid Apps in a SnapPaulina Gallo
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapRamesh Nair
 

Similar to Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK (20)

Microservices in Golang
Microservices in GolangMicroservices in Golang
Microservices in Golang
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentation
 
Meteor
MeteorMeteor
Meteor
 
Pwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA eventPwa is the future. The Presentation I gave at PWA event
Pwa is the future. The Presentation I gave at PWA event
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API Development
 
What is Codename One - Transcript.pdf
What is Codename One - Transcript.pdfWhat is Codename One - Transcript.pdf
What is Codename One - Transcript.pdf
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
 
Building an App for Mobile and Web with Expo
Building an App for Mobile and Web with ExpoBuilding an App for Mobile and Web with Expo
Building an App for Mobile and Web with Expo
 
Get started with meteor | designveloper software agency meteor prime partner
Get started with meteor | designveloper software agency   meteor prime partnerGet started with meteor | designveloper software agency   meteor prime partner
Get started with meteor | designveloper software agency meteor prime partner
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnectIntro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
Intro to IBM Bluemix DevOps Services, an open lab for IBM InterConnect
 
iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008iLabs Toolbox Javashare 2008
iLabs Toolbox Javashare 2008
 
HealthyCodeMay2014
HealthyCodeMay2014HealthyCodeMay2014
HealthyCodeMay2014
 
PhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developementPhoneGap Framework for smartphone app developement
PhoneGap Framework for smartphone app developement
 
Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3
 
Mdb dn 2017_16_iot
Mdb dn 2017_16_iotMdb dn 2017_16_iot
Mdb dn 2017_16_iot
 
Hybrid Apps in a Snap
Hybrid Apps in a SnapHybrid Apps in a Snap
Hybrid Apps in a Snap
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
 
Hack Rio/OS
Hack Rio/OSHack Rio/OS
Hack Rio/OS
 

More from PubNub

Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsPubNub
 
Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT StackPubNub
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?PubNub
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad DestroyerPubNub
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box PubNub
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubPubNub
 

More from PubNub (6)

Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.js
 
Defining the IoT Stack
Defining the IoT StackDefining the IoT Stack
Defining the IoT Stack
 
What the heck is a realtime app?
What the heck is a realtime app?What the heck is a realtime app?
What the heck is a realtime app?
 
TrackPad Destroyer
TrackPad DestroyerTrackPad Destroyer
TrackPad Destroyer
 
Real-Time Stats for Candy Box
Real-Time Stats for Candy Box  Real-Time Stats for Candy Box
Real-Time Stats for Candy Box
 
Lightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNubLightweight Multiplayer HTML5 Games with PubNub
Lightweight Multiplayer HTML5 Games with PubNub
 

Recently uploaded

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK

  • 1. Streaming Geo Coordinates from MongoDB to your iPhone App with PubNub using WebSocket SDK! by Stephen Blum
  • 2. Not long ago we partnered with a high- standards online engineering broker (an online listing service where you can post engineering projects). The partnership involved joint PR and blogging, however a new opportunity/idea was presented. This particular idea stemmed from a commission listed on the broker’s website which listed requirements for building an integrated Real-time Map Service. We took the opportunity and built a Ruby GEM with a sprinkle of documentation and HTML5. Continue through the slides for a quick start guide to build an integrated real-time map service.
  • 3. For those of you who need a quick mini-guide to getting your MongoDB installed and running with data sync streaming directly to your mobile app, you can follow this guide: MongoDB Pipe GitHub Repository. It will show you how to download/install MongoDB and the MongoPipe GEM. Real-time Data Stream of Geo Coordinates Lat/Long from MongoDB replicated to your iPhone App The commission at the online workplace was posted as a $3,025 bounty. Rather than taking the commission for ourselves, which involves building and delivering the solution in a private exchange, we instead reviewed the specifications and requirements and we developed an open source implementation that you can download and run for your live app today! MIT License, so you can use this however you desire. We even created a GEM for you and made it easy to get started: gem install mongopipe
  • 4. Downloading the GEM is the first step in the process and next we’ll walk you through more details. Actually now may be the time for you to watch the short video (next slide), so feel free to jump into that now if you want a very brief demonstration and usage covering these points: 1.  Installing the Ruby gem and 2.  Executing the commands to setup MongoDB and 3.  Running the Pipe Daemon. 4.  Launching the Map Viewer. 5.  Finally inserting lat/long coords into MongoDB. 6.  Result is live-animated points on a map displayed on the iPhone. The video will show usage of the MongoPubNubPipe gem. Source code is available via GitHub if you want to see everything - MongoDB Pipe GitHub Repository
  • 5. MongoPubNubPipe::Connect.new(...) MongoDB Geo Coordinates This becomes the new interface that is available with mongopipe gem: Usage of MongoPubNubPipe is available in later slides.
  • 6. The video demonstrates an implementation of the connection between MongoDB and a mobile device (an iPhone in this case). This application code and gem library will provide you a way to easily add a live always-on map connection which allows you to send lat/long signals directly to the device displaying the map with the specific Lat/Long DB written into MongoDB. This will cause the device to draw an animated dot onto the screen of the device in real-time. The dot that animates is triggered by simply writing to your MongoDB collection directly either through the mongo console or through your RoR/Ruby Server Code. For example here is a MongoDB Console Command that will cause a DB write, creating a Document, which then triggers the sync with the consumer iPhone device that is rendering the map in real-time. db.collection_name.insert({ latlon : [ 1.5, 2.0 ] })
  • 7. gem install mongopipe Once you’ve written a Lat/Long coordinate into MongoDB collection, the process begins instantly synchronizing with any connected iPhone. We where able to include several feature requests and here follows the requirements: When a new Lat/Lon document is inserted into MongoDB, stream the Lat/Lon data to a mobile device is push data. Use a Ruby or Node.JS Service to stream the data out of MongoDB as it is written in real-time. Simple enough, yes, though it requires moving pieces. We simplified the process and built two modules: one in Ruby and one in HTML5. We’ll walk through the methods for getting you started and how to hook into the stream on your iPhone App. You can fast-track the tutorial and go strait to the GitHub Repository or gem install mongopipe package for ruby. GitHub Repository MongoDB Pipe GitHub Repository
  • 8. How it Works MongoPipe is a new tool powered by PubNub that streams your MongoDB Documents from your MongoDB Collection directly to your iPhone App in less than 0.25 seconds (real-time) using the PubNub Real-time Network. Your iPhone app opens an always-on TCP Socket Connection to PubNub while a dispatch process runs on your MongoDB server via Tailable Cursors to catch inserted documents. The data is streamed and brokered via PubNub Network directly to your iPhone App in real-time.
  • 9. mongod require 'rubygems' require 'mongopipe' ## ------------------------------------------------------ ## Pipe MongoDB for Inserts ## ------------------------------------------------------ MongoPubNubPipe::Connect.new( :puts_usage => true, :publish_key => 'demo', :subscribe_key => 'demo', :db => 'test', :collection => 'cap_collection', :callback => lambda{ |doc| ## Optional Callback Called on Doc Insert ## Remove :callback if you don't need it. puts(doc) } ).pipe() MongoDB Tailable Cursors The ruby GEM mongopipe utilizes the tailable cursor interface provided by MongoDB Core. Document Data is then piped directly through the PubNub Network which uses a direct broadcast synchronization socket with the mobile app. Next we’ll show you what the process is to get the mongopipe running on your Ruby Server. Make sure MongoDB is running Next open a text editor and copy/paste the following monogopipe example. Save this to a file pipe.rb for example then execute it. Ruby pipe.rb
  • 10. Step 1: Open Your Browser to Show PubNub Pipe Console This will connect directly to MongoDB and print usage guide on next steps. The video covers only a demonstration of this process. Here is a sample output of what may be provided via the puts(doc) output: > Open http://www.pubnub.com/console?channel=test.cap_collection Step 2: Open Demo Map on Your Phone > Open http://goo.gl/HAqAv#test.cap_collection Step 3: Insert Test Data > ./mongo > Use test > db.cap_collection.insert({ latlon : [ 1.5, 2.0 ] })
  • 11. Remaining Details This blog entry was intended to give you a quick skim over the details on how the mongopipe ruby gem works and what is involved in coordinating the embeddable mobile HTML5 animated map. If you have any more questions please tweet @PubNub directly. You may be curious about the connectivity mechanism between your iPhone App and your MongoDB Sever. Checkout the PubNub WebSocket Reference below to see the transport mechanism utilized. Thank you for reading!
  • 12. PubNub WebSocket Reference The MongoDB Pipe uses the PubNub Network WebSocket interface which provides an always-on socket connection to your iPhone app. The PubNub Network WebSocket acts as a broadcast receiver and syncs directly to your mobile device in real-time from your MongoDB server via MongoPipe. Following is an example of how the Map app implements the socket: // Create Socket Connection var socket = new WebSocket( 'wss://pubsub.pubnub.com/PUBLISH_KEY/SUBSCRIBE_KEY/CHANNEL' ); // Set Message Receiver Function socket.onmessage = receiver; // Receiver Function Prints Data Result function receiver(evt) { console.log(evt.data); }