Mosquitto library usage with iOS - ios

I am trying to use the MQTT protocol and am an amateur with this. I tried the objective-C code over Mosquitto library using MQTTKit (https://github.com/jmesnil/MQTTKit).
I am able to use it to publish messages to some test servers and things are working fine but still I have some basic questions, not so clear to me:
Does Mosquitto library include web sockets too underneath?
Is it possible to create a connection, subscribe to a topic and then server can also publish messages to device with realtime behavior? In other words, can we use it for real time communication between server and client (the iOS device in this case) bidirectional?

The mosquitto library does not support websockets, it is mqtt only.
Yes, mqtt is a bidirectional protocol. I believe there are difficulties with keeping a long term socket open on iOS that mean it isn't as straightforward to support as you might like. I'm not familiar with iOS at all though.

1.the mosquitto library of javascript has support websocket. you can go http://mosquitto.org/download/ to download.
2.mosquitto support MQTT protocol. When the connection was established, the mosquitto will send PINGREQ message for keep heartbeat.(the keep alive time please see MQTT protocol). the MQTT protocol is Publish / Subscribe (PubSub) model.So the server(broker) is central. Client subscribe topic, other client can receive message, and clietn can publish message to the another topic.That's all, you only need to set appropriate topic.

Related

Framework for communicating between iOS and MacOS

I'm looking to build a pair of apps that work in a similar way to iTunes and the Remote app for iOS... Is there a framework for connecting iOS and MacOS over wifi?
Bluetooth is something I'd like to avoid and there's no need for a web service, I'm just looking to control my Mac app remotely from the phone.
Thanks in advance.
Id say the most ideal way to accomplish this is via the Bonjour protocol.
Here is a great article on the subject, http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/.
Good thing with using Bonjour in iOS is it also works via Bluetooth.
Hope this helps !
here is an example project which exchange the data between iphone and iMAC with WiFi connectivity.
https://github.com/boobalaninfo/Bonjour-iOS-MAC-Apps
Use bonjour to search for devices. Then use CocoaAsyncSocket to send and receive data. It works like a charm.
Little info about AsyncSock:
GCDAsyncSocket and AsyncSocket are TCP/IP socket networking libraries.
Here are the key features available in both:
Native objective-c, fully self-contained in one class. No need to muck
around with sockets or streams. This class handles everything for you.
Full delegate support Errors, connections, read completions, write
completions, progress, and disconnections all result in a call to your
delegate method.
Queued non-blocking reads and writes, with optional timeouts. You tell
it what to read or write, and it handles everything for you. Queueing,
buffering, and searching for termination sequences within the stream -
all handled for you automatically.
Automatic socket acceptance. Spin up a server socket, tell it to
accept connections, and it will call you with new instances of itself
for each connection.
Support for TCP streams over IPv4 and IPv6. Automatically connect to
IPv4 or IPv6 hosts. Automatically accept incoming connections over
both IPv4 and IPv6 with a single instance of this class. No more
worrying about multiple sockets.
Support for TLS / SSL Secure your socket with ease using just a single
method call. Available for both client and server sockets.

Gsm800 mqtt library

I have sim800 module ,i want to control relay from webserver so i need mqtt library and sample code for arduino uno please help to me,What is AT command for publish and subscribe the tag in sim800 using arduino uno
I think it is very unlikely that your SIM800 module will have an AT command for MQTT.
There are a couple of MQTT libraries for Arduino:
AdaFruit: https://github.com/adafruit/Adafruit_MQTT_Library
PubSubClient by Nick O'Leary: http://pubsubclient.knolleary.net/
Both of these libraries should work with any library than implements the Client interface. So it should be possible to create a TCP client that talks to the GSM module.
If the SIM800 supports the GSM library then that implements the Client interface:
https://www.arduino.cc/en/Reference/GSM
If you are using the hardware serial port in the Arduino, you might be better using a Leonardo than a Uno, because you can use the USB to programme the Arduino, and the hardware serial to talk to the GSM module.
MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog, ElementzGithubRepository,ElementzOnlineCart
Functionalities:
Auto connect
Automatically connect to TCP and to MQTT server.
connect function
This function can be used to connect your client to MQTT broker.
Use only if you do not use Auto connect functionality.
Optionally you can use username, password, WILL topic and WILL Message.
OnConnect CallBack function
This call back function is called when MQTT connection is established.
You can call subscription and publish functions inside it (according to your need).
publish function
This function can be used to publish messages to different topics.
You can select QoS levels and RETAIN flag according to your need.
subscribe function
This function can be used to subscribe messages from different topics.
OnMessage CallBack function
This callback function is called when messages are received from subscribed topics
Topic, TopicLength, Message, MessageLength are the arguments of OnMessage callback function.
Inside this, you can write your custom code.
unsubscribe function
This function can be used to unsubscribe from a previously subscribed topic.
disconnect function
This function can be used to disconnect your client from MQTT broker.
Keep Alive
You can specify your KeepAlive duration while initializing.
Ping requests are sent and received automatically.
You can try using Paho Arduino client library. It features full fledged MQTT library with support to MQTT 3.1, MQTT 3.1.1 & SSL/TLS.

Connect to XMPP over websocket on iOS?

I need to connect to an XMPP server over websocket on iOS (ws://chat.something.com:1234/websocket). I am using XMPPFramework, but I cannot find a way to make it connect over websocket.
I found this answer https://stackoverflow.com/a/23114564/310121 that suggests that XMPPFramework doesn't support this. As far as I can tell, that seems to be true.
So is there any way to connect to an XMPP server over websocket on iOS without writing your own library or extending XMPPFramework (or some alternative library) to support this?
XMPPFramework uses TCP sockets. It has not provided any API's or provision for websockets.
In order to connect with your server using websockets, you will have to alter XMPP Library's code.
I had the same issue, and i resolved it by replacing XMPPStream class of XMPPFramework (that deals with the actual TCP socket connection) with custom stream class, and used SocketRocket library to connect over websocket with my server.

How to model MQTT broker to enable clients to subscribe to their messages alone?

I am new to MQTT protocol. I tested the MQTT broker which facilitates the publishing from my android phone and subscription of my IOT actuators(Motors). But I am confused, as how to enable actuators to work only from a particular publisher. In otherwords, I want to control my MotorA from my PhoneA and MotorB from PhoneB and so on... I don't know how to get started outside the localhost(LAN) to make my broker work with the help of internet.
I am using Mosquitto broker and ESP8266 as client. Please share your views on how to get started with Mosquitto broker hosted on internet.
Hosted MQTT (e.g. https://www.cloudmqtt.com/) is no different than your local Mosquitto broker except that's in the cloud.
As for how to route publishers you can do that either based on an attribute of the published message e.g. something like motorId or you can publish to different queues. Hence, phone A could publish to queue motor-a and phone B could publish to queue motor-b. The application on the ESP8266 would subscribe to both and act accordingly.

How to Find Latency of Other Connected Device via TCP Socket in IOS

is sending a message to the device which is connected via TCP Socket and calculate the time it takes to reply is the right approach?
The most common implementation for checking networking latency is based on ICMP packages and is called ping.
There is a nice and easy sample available from Apple.
Please note that even though the sample is provided for OSX, it should build and work fine on iOS as well.
Here are some additions I just found: splinter.com.au/how-to-ping-a-server-in-objective-c-iphone
I would go with ping as that way you would not have to build the "echoing" part yourself, that part is done by the remote system/network-stack.

Resources