flightonary / moscapsule Goto Github PK
View Code? Open in Web Editor NEWMQTT Client for iOS written in Swift
License: MIT License
MQTT Client for iOS written in Swift
License: MIT License
Why isn't the podspec for this product officially published in the Cocoapods Trunk?
You have serialQueue
in the your code and method addRequestToQueue
. But serialQueue
isn't used anywhere and method addRequestToQueue
calls closure in the current queue and doesn't use serialQueue
. Why? I have a lot of issues because it. Did you do it because some special issue or not? If not, I can create pull request with this
I am not able to find any callback for onDilevered callback for the messages sent by us.
I've successfully established the connection and I can simulate a chat sending messages back and forth on a specific topic (e.g. chat/room/1
) between my iOS Simulator and Web Service.
However, I now want my iOS to subscribe using a wild card to chat/room/*
, but it doesn't work as a wild card.
My code:
mqttClient.subscribe("chat/room/*", qos: 2)
To be clear, after my iOS Simulator subscribed to chat/room/*
:
chat/room/1
or chat/room/2
chat/room/*
Hello everyone,
We are developing an application which needs to consume AWS IoT service based on a MQTT protocol deviation. We are currently facing issues to get connected with MQTT broker provided by AWS IoT cloud server.
Following is the environment:
iOS Version: 11.4
Programming language: Swift 4
Library for MQTT: Moscapsule
Steps followed:
1.Set initial config clientid, host, port
2.Set User Authentication.
using the above step my code works fine , when I Connect mqttClient with WEB Socket . I get response from
1 . On Connection CallBack .
2. On Publish CallBack .
3. On Subscribe CallBack.
4. On Message CallBack.
Problems faced:
When trying to Connect with TCP Socket , I didn't get any response .
Any help in this context is highly appreciable.
Thanks in advance.
Please consider Carthage support for easy implementation.
Keep up the good work.
I want subscribe some message by mqtt
but the program didn’t do this block
mqttConfig.onMessageCallback = { mqttMessage in
// write received message to log
NSLog("MQTT Message received: payload=(mqttMessage.payloadString)")
}
until I add dispatch_main() after mqttClient.publishString , it can work.
But it let the program only do onMessageCallback , how to stop it?
——————————————————————————
If I didn’t add dispatch_main()
the message is show above
2016-04-13 09:23:07.381 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending CONNECT
false
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0)
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending PUBLISH (d0, q0, r1, m2, 'topic123', ... (7 bytes))
2016-04-13 09:23:07.382 myprogram[26583:2388414] [MOSQUITTO] DEBUG Client cid sending DISCONNECT
It didn’t print any callback message.
What is the problem?
ps. I didn't write mqttClient.disconnect() in my code.
Does it have any example?
ps. sorry for my poor English, if you have any question, please tell me, thanks!
The question is similar to this website http://social.gseosem.com/stackoverflow/how-to-create-a-persistent-mqtt-connection-to-mosquitto-with-moscapsule/
Hello,
Is there any possibility to use this library with username password login?
Thanks,
Markus
Can I use this Client with Mosca?
IMHO, MQTTMessage should be a value type instead of being a reference type.
If you can create a swift3 branch, I can pr
Consider of swift4 comptible?
I'm trying to create some NSTimer
for dealing with timeout in connection and message receiving but the timer is never called. I presume that's because some thread issues but I'm not sure.
I saw the mosquitto_loop_
and MQTTReconnOpts stuff but not sure how and if it is possible to change those data to get some timeout functionality.
Bellow same sample code:
@objc private func createConnection() {
timeout = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(timeout(_:)), userInfo: ["foo":"bar"], repeats: false)
mqttClient = MQTT.newConnection(mqttConfig)
timeout?.invalidate()
}
var mqttClient: MQTTClient? = nil
let mqttConfig = MQTTConfig(clientId: "Sasa", host: "192.168.0.11", port: 1883, keepAlive: 60)
override func viewDidLoad() {
super.viewDidLoad()
mqttClient = MQTT.newConnection(mqttConfig)
print( "\(mqttClient?.isConnected)")
mqttClient?.subscribe("ios/test", qos: 0)
DispatchQueue.main.async {
self.mqttConfig.onMessageCallback = { msg in
print("asdasda \(msg.payloadString!)")
sleep(1)
}
self.mqttConfig.onConnectCallback = { rtrn in
print(rtrn)
}
}
}
it does not go in onMessageCallback...
Hi, I have simple code with example from README.
I try to get any message from broker after subscribe, when I click on button. But instead of receive any data I have subscribe and DISCONNECT, could you please help with this issue ?
Bellow code from xCode and console log after button click
import UIKit
import Moscapsule
@IBAction func goButtonPresed(sender: AnyObject) {
self.sendMQTT()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func sendMQTT () {
let topic = "dallas/led"
let message = "1"
// set MQTT Client Configuration
let mqttConfig = MQTTConfig(clientId: "esp2", host: "m12.cloudmqtt.com", port: 10661, keepAlive: 60)
mqttConfig.mqttAuthOpts = MQTTAuthOpts(username: "USERNAME", password: "PASSWORD")
mqttConfig.onPublishCallback = { messageId in
NSLog("published (mid=\(messageId))")
}
mqttConfig.onMessageCallback = { mqttMessage in
NSLog("MQTT Message received: payload=\(mqttMessage.payloadString!)")
}
// create new MQTT Connection
let mqttClient = MQTT.newConnection(mqttConfig)
// publish and subscribe
mqttClient.publishString(message, topic: topic, qos: 1, retain: true)
mqttClient.subscribe("dallas/temp", qos: 1)
}
}
and below console log after button click:
2016-05-07 00:42:01.359 mqtt2[58997:1526453] [MOSQUITTO] DEBUG Client esp2 sending CONNECT
2016-05-07 00:42:01.360 mqtt2[58997:1526453] [MOSQUITTO] DEBUG Client esp2 sending PUBLISH (d0, q1, r1, m1, 'dallas/led', ... (1 bytes))
2016-05-07 00:42:01.360 mqtt2[58997:1526453] [MOSQUITTO] DEBUG Client esp2 sending SUBSCRIBE (Mid: 2, Topic: dallas/temp, QoS: 1)
2016-05-07 00:42:01.361 mqtt2[58997:1526453] [MOSQUITTO] DEBUG Client esp2 sending DISCONNECT
As I understand disconnect was called after deinit(), but how I can setup stable connect via button click without self disconnect and receive massage from broker until I will call disconnect() func via click on another button for example ?
A lot of thanks for any help.
Moscapsule library use OpenSSL. I look this library and library page says
Architectures
iOS with architectures: armv7, armv7s, arm64 + simulator (i386, x86_64) OSX with architectures: i386, x86_64
Iphone 6 and other some iphone models use Apple A8 processor and this processor architecture is ARMv8-A. So when i use Moscapsule i have any problem about iphone models ?
When I use Xcode7.3 archive, this error occurs,
error: Invalid bitcode version (Producer: '800.0.38.0_0' Reader: '703.0.31_0')
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I try to set my target's enable bitcode from yes to no, but it does not work for me
I have a CA server certificate, using the same certificate i am able to PUBLISH the message in android using paho lib, I am not able to receive the message PUBLISHED by my iOS app using the moscapsule lib. the log shows "mosq_success", but i am not able to receive the message on the other end. The code is below -
`
func initMQTTByMoscapsule() -> Void {
mosquitto_lib_cleanup()
moscapsule_init()
let mqttConfig = MQTTConfig(clientId: clientID + String(ProcessInfo().processIdentifier), host: host, port: 8883, keepAlive: 60)
let mqttAuth = MQTTAuthOpts.init(username: userName, password: password)
mqttConfig.mqttAuthOpts = mqttAuth
let resourcePath = Bundle.main.url(forResource: "authoritycert", withExtension: "crt");
mqttConfig.mqttServerCert = MQTTServerCert(cafile: nil, capath: resourcePath?.absoluteString)
let mqttClient1 = MQTT.newConnection(mqttConfig)
mqttClient1.connectTo(host: host, port: 8883, keepAlive: 60) { (MosqResult) in
print("\n\n\n Return Code is \(MosqResult)")
if mqttClient1.isConnected {
print("\n\n\n Dude its is connected \n\n")
}
mqttClient1.publish(string: "test-blind-10", topic: topicToSub, qos: 0, retain: false, requestCompletion: { (resultMessage, resultcode) in
print("\n\n\n The PUBLISH result - \(resultMessage) \n\n")
})
}
mqttConfig.onPublishCallback = { messageID in
print("\n\n\n Return Code is \(messageID.description) on publish")
}
//mqttClient.subscribe("subscribe/topic", qos: 2)
mqttConfig.onConnectCallback = { returnCode in
print("\n\n\n Return Code is \(returnCode.description) (on Connect)")
}
`
and the resulting log is below
`[38695:1102928] [MOSQUITTO] DEBUG Client Smart***&Client38695 sending CONNECT
2018-10-24 10:27:34.845393+0530 CC[38695:1104304] [MOSQUITTO] DEBUG Client Smart***&Client38695 sending CONNECT
Return Code is mosq_success
2018-10-24 10:27:36.975967+0530 CC[38695:1102928] [MOSQUITTO] DEBUG Client Smart***&Client38695 sending PUBLISH (d0, q0, r0, m1, 'a**&-r**&-topic', ... (13 bytes))
The PUBLISH result - mosq_success
2018-10-24 10:27:38.375126+0530 CC[38695:1104304] [MOSQUITTO] DEBUG Client Smart***&Client38695 sending DISCONNECT`
still i am not receiving the message in the other end.
We have install the pod successfully as shown in document part. But it always give the error that open ssl.h file not found.So i would request you to please resolve the issue .
Hi I'm trying to connect Connect to my MQTT server with SSL Certificate authentication it worked fine. After I subcribed the Topic the connection getting disconnected. This is my code
moscapsule_init()
**let mqttConfig = MQTTConfig(clientId: "shantha", host: "aws.amazonaws.com", port:poer, keepAlive: 60)
let path = Bundle.main.path(forResource: "ca", ofType: "pem")
let path1 = Bundle.main.path(forResource: "client", ofType: "crt")
let key = Bundle.main.path(forResource: "client", ofType: "key")
mqttConfig.mqttServerCert = MQTTServerCert(cafile: path, capath: nil)
mqttConfig.mqttClientCert = MQTTClientCert(certfile: path1!, keyfile: key!, keyfile_passwd: nil)
mqttConfig.mqttTlsOpts = MQTTTlsOpts(tls_insecure: false, cert_reqs: CertReqs.ssl_verify_peer, tls_version: "tlsv1", ciphers: nil)
mqttConfig.onConnectCallback = { returnCode in
if returnCode == ReturnCode.success {
print("connected")
// something to do in case of successful connection
}
else {
// error handling for connection failure
}
}
mqttConfig.onMessageCallback = { mqttMessage in
if mqttMessage.topic == "topic" {
NSLog("MQTT Message received: payload=\(mqttMessage.payloadString)")
} else {
// something to do in case of other topics
}
}
let mqttClient = MQTT.newConnection(mqttConfig)
mqttClient.connectTo(host: "aws.amazonaws.com", port: 7926, keepAlive: 60)
let deadlineTime = DispatchTime.now() + .seconds(20)
DispatchQueue.main.asyncAfter(deadline: deadlineTime, execute: {
mqttClient.subscribe("topic", qos: 2, requestCompletion: nil)
})**
Im geting connection keep disconnecting can please help me with this issue.
Thanks,
Hi !
Is there an option to deactivate logging ?
this library doesn't work with tls connection through ipv6 network.
it happens because this library has the next code:
/*#ifdef WITH_TLS
if(mosq->tls_cafile || mosq->tls_capath || mosq->tls_psk){
hints.ai_family = PF_INET;
}else
#endif
{
hints.ai_family = PF_UNSPEC;
}
But PF_INET allows ipv4 only, can we use PF_UNSPEC for all connections? Because PF_UNSPEC allows both ipv4 and ipv6.
Currently, if you want to use tls connection in ipv6 only network, then getaddrinfo
will return error. But if you change ai_family
to PF_INET6
, PF_UNSPEC
or you will not setup it, then connection will work properly.
P.S. you will get reject from apple team if you use this library for connections with tls until this issue solved
I am seeing 400+ warnings when using this with Xcode 7.2 and iOS 9.2,
"/Pods/Moscapsule/mosquitto/lib/logging_mosq.c:36:21: Implicit conversion loses integer precision: 'unsigned long' to 'int'"
I'm actively using this library and I often use "disconnect" and "connect" and creating new instances of moscapsule. Very often I get zombie thread, because of pthread_join
has UB and thread freezes. How can I debug and fix this problem?
For reproducing don't need to make any special things, just connect to broker, send disconnect, create another one moscapsule entity, repeat steps and so on.
What is the best way to import this in an existing project? Could you add instructions to the read me please?
This an awesome library and it would be great to have a CocoaPods distro to make installation easier.
Running Xcode 8.2.1 and getting following compiler error:
IOS/MyApp/Moscapsule/mosquitto/lib/mosquitto_internal.h:27:12: 'openssl/ssl.h' file not found when I try to build the Mocapsule error
Any ideas why? I don't see the file ssl.h.
How to use willMessage using Moscapsule. I am unable to find any method related to will message.
My program can do PUBLISH, PUBRIC, PUBERL, PUBCOMP now
The message print in Log is show below
MyProgram[5194:1180483] [MOSQUITTO] DEBUG Client cid received PUBLISH (d0, q2, r0, m8, 'Test/6', ... (145 bytes))
2016-04-22 09:42:55.109 MyProgram[5194:1180483] [MOSQUITTO] DEBUG Client cid sending PUBREC (Mid: 8)
2016-04-22 09:42:55.117 MyProgram[5194:1180483] [MOSQUITTO] DEBUG Client cid received PUBREL (Mid: 8)
2016-04-22 09:42:55.117 MyProgram[5194:1180483] [MOSQUITTO] DEBUG Client cid sending PUBCOMP (Mid: 8)
2016-04-22 09:43:25.627
But my program never do this block
self.mqttConfig.onMessageCallback = { mqttMessage in
NSLog(“MQTT Message received: payload=(mqttMessage.payloadString)")
}
So I can’t get the mqttMessage.
How to receive mqttMessage?
Thank you!
ps. Sorry for my poor English. If you have any question, please tell me.
My question is similar to this website.
http://stackoverflow.com/questions/36289214/how-to-receive-message-of-subscribed-topic-with-moscapsule
There is a pull request by @cemaleker that fixes this issue. #71
I want some Example code
There are some issues about unavailable methods. Specificially:
"'advance' is unavailable: call the 'advancedBy(n)' method on the index"
in the Moscapsule.swift file
What about these managers? Do you have plans to add supporting their to this library?
File: mosquitto.c
Row: 73
Message:
Signed integer overflow: 1521456818 * 1000 cannot be represented in type 'long'
Code:
srand((unsigned int)(tv.tv_sec*1000 + tv.tv_usec/1000));
Xcode pause execution on every start if running on iPad2 device or simulator (iOS 9.3).
No warnings if running on 64bit device or simulator.
Hi All,
I want to Publish a message to AWS broker where payload should be configured using google protocol buffer. Is it possible to publish such message using MQTT?
Thank you!
Mahesh
Hello, so I realize if i set the client Id to a certain value, it is used within the queue name on the broker such as
Queue mqtt-subscription-{name here}qos1
Where does this get set within the code? Id like to be able to define my own queue names.
Which OpenSSL version should be cloned?
Hi, I have a question regarding auto reconnection. What if I don't need this feature? I tried to set new MQTTReconnOpts
instance with max parameters, but this struct doesn't contain initializers.
So, how I can change reconnection settings?
'Moscapsule-Swift.h' this file is not found. I'm running on lastest xcode, and also there are 14 issues in the framework, does it matter to the project running?
I've tried to init and update the git submodule but unfortunately the console says:
Please make sure you have the correct access rights
and the repository exists.
Clone of '[email protected]:krzyzanowskim/OpenSSL.git' into submodule path 'submodules/OpenSSL' failed
My fault. Problems with SSH Key.
Good evening,
For the needs of my application, I would need to receive messages in the format string, only I do not find how to retrieve a message after a subscribe, could someone explain to me how to do?
I thank you in advance.
cordially
Please create an example project demonstrating the functionality of the library.
My broker support only sslv3 with http://emqtt.io/.
When I use the protocol sslv3 in my code, It give me:
[MOSQUITTO] ERROR Error: Unable to create TLS context.
Autoreconnect stops when I
Or sometimes it just stops after disconnection with MOSQ_ERRNO.
Then I set mqttReconnOpts=nil and call reconnect() in onDisConnectCallback,
but connection is never made after Disconnect_Requested, so I changed it to disconnect() and reconnect(), this is power consumptive so I changed it to trigger disconnect()/reconnect() with a watchdog timer instead of in onDisConnectCallback. This works in most of time but once or twice a day, I get infinite Disconnect_Requested.
Finally, renew MQTTClient instance in onDisConnectCallback and watchdog timer emulate reconnection, but the session is of course lost.
I'm using
pod 'Moscapsule', :git => 'https://github.com/flightonary/Moscapsule.git'
pod 'OpenSSL-Universal', '~> 1.0.1.18'
on iOS 10.
Any suggestion?
Hello everyone,
We are developing an application which needs to consume AWS IoT service based on a MQTT protocol deviation. We are currently facing issues to get connected with MQTT broker provided by AWS IoT cloud server.
Following is the environment:
Steps followed:
1.Set initial config clientid, host, port
2.Set client certificate with private key, providing .pem file path (e.g. cert.pem, privateKey.pem)
3.Set server certificate which is root certificate .pem file path (e.g. rootCA.pem)
4.Set tls opts with tsl_insecure: false, cert_reqs: SSL_VERIFY_PEER, tls version: tlsv1.2, ciphers: nil
Problems faced:
1.When trying to connect to server/broker gives error “unable to create TLS_Context”.
2.With setting tls cert_reqs: SSL_VERIFY_NONE, gives connection status success with subcribe and publish sucess, but doesn’t reflect on server or broker.
Any help in this context is highly appreciable.
Thanks in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.