An iOS app designed to turn home devices/lights on and off using MQTT messaging protocol
An iOS app designed to turn home devices/lights on and off using MQTT messaging protocol
Here I am demonstrating how MQTT works in ios. What is basic concepts of Internet of Thing(IoT) and its protocols. Etc…
MQTT protocol is created based on publish and subscriber paradigm. A client that published the messages, called “Publisher” to
the other client, called “Subscriber” who receive the message.
MQTT is asynchronous where HTTP is synchronous so it does not block the client while it waits for the message.
It does not require that client(subscriber) and the publisher are connected at the same time.
Dispatching messages to MQTT clients (subscibers), so basically MQTT Broker receives the messages from Publisher and send it to
the subscriber. When it dispatches the messages it uses the topic to filter the subscriber. The topic is a string and it is possible
to combine topics creating topic levels.
A topic a virtual channel that connects publisher and subscriber. This topic is managed by MQTT broker. Through this virtual channel
publishers are decoupled from subscribers, MQTT clients (publisher and subscriber) do not have to know each other to exchange the data.
That’s why MQTT is highly scalable without a dependency between message producer (Publisher) and message consumer ( subscriber ).
IoT promises to connect all the devices together and enable them to exchange the information. All the information is gathered and analysed to improve our life.
Generally speaking, Internet of things is an environment, or an ecosystem, where smart objects (including of course smartphones and so on) connect each other.
It affects across different sectors:
(1). Transportation
(2) healthcare
(3) smart cities
(4) agriculture
(5) Retail
(6) manufacturing
Well, we know HTTP protocol that makes possible to browse the net, opens web pages. But is this protocol still useful for IoT ?
Well, the answer is yes. But there are other protocol which are more efficient in low power devices.
Below are the most important IoT protocols used IoT eco-system:
it is machine to machine(M2M) oriented protocol. The architecture is very simple, based on client-server architecture. The client is generally a sensor which publishes (known as “Publisher”) the message/information to the server (“Broker”) which receives the information and dispatch it to the other client (known as “subscriber”). The underlying communication is based on “TCP” architecture.
Generally speaking, MQTT protocol uses many to many paradigm and broker decouples publisher from subscriber and acts as a message router. Eclipse has released open source implementation of MQTT called Mosquitto.
This is a web transfer protocol, very much similar to HTTP protocol. It uses document transfer paradigm.
It uses HTTP based protocol.
Mosquito is an way developed by Eclipse team.
brew install mosquitto
// do a link
ln -sfv /usr/local/opt/mosquitto/*.plist ~/Library/LaunchAgents
// start it now
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
mosquitto_sub -t topic/state
mosquitto_pub -t topic/state -m "Hello World"
The subscriber will get the update what is sending by Publisher.