JavaScript Objective-C HTML Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
broker Updated the client so that it uses the JSON formatter for a stricter … Aug 19, 2015
ios Updated the client so that it uses the JSON formatter for a stricter … Aug 19, 2015
web Formatting Aug 11, 2015
.gitignore Updated the client so that it uses the JSON formatter for a stricter … Aug 19, 2015
README.md

README.md

MQTT Example using iOS, Mosca and Paho

This is a companion to http://karmadust.com/internet-of-things-with-ios-node-js-and-mqtt/

Prerequisites

I use PM2 to run Node.js applications as I feel that it offers better control and logs that forever.

npm install pm2 -g

Install http-server to serve the index.html page that contains the Paho.js client

npm install http-server -g

Installation of Dependencies

Clone the repo

git clone git@bitbucket.org:mmick66/mqttiosexample.git

Update the Node.js dependencies

cd /broker
npm install # mainly Mosca
cd ../

Update the iOS Pod dependencies

In the /ios sub-folder:

cd /ios
pod install
cd ../

If pod seems to run forever you can try the following:

pod repo remove master
pod setup
pod install --verbose # see what is happening

Running the system

First make sure that a MongoDB Instance is running locally at port 27017. If not then run

mkdir -p mongo/db
mkdir mongo/logs
touch mongo/logs/log.txt
mongod --dbpath ./mongo/db --logpath ./mongo/logs/log.txt --fork

Then, from the root folder:

  1. Start the broker
pm2 start broker/broker.js
  1. Start the http server
http-server ./web
  1. Load http://localhost:8080/

  2. Launch the iOS Simulator, press Connect, select Online from the tabs and press Send

  3. Navigate to the webpage at http://0.0.0.0:8080/, click connect and subscribe to the client id you have set on the iPhone (defaults to 101 on both iOS and Web).