This is a companion to http://karmadust.com/internet-of-things-with-ios-node-js-and-mqtt/
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
Clone the repo
git clone git@bitbucket.org:mmick66/mqttiosexample.git
cd /broker
npm install # mainly Mosca
cd ../
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
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:
- Start the broker
pm2 start broker/broker.js
- Start the http server
http-server ./web
-
Launch the iOS Simulator, press Connect, select Online from the tabs and press Send
-
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).