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

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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); }