CocoaMQTT | MQTT 5.0 client library for iOS and macOS written in Swift | iOS library
kandi X-RAY | CocoaMQTT Summary
kandi X-RAY | CocoaMQTT Summary
MQTT v3.1.1 and v5.0 client library for iOS/macOS/tvOS written with Swift 5.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CocoaMQTT
CocoaMQTT Key Features
CocoaMQTT Examples and Code Snippets
Community Discussions
Trending Discussions on CocoaMQTT
QUESTION
I'm writing a small iOS app to send MQTT messages to a broker which is hosted on a Raspberry Pi companion computer on my quadcopter. In the iOS app primary view, the app will connect to MQTT Broker (check), send messages associated with several buttons (check), and monitor various quadcopter telemetries such as mode, distance, and lat/long. The iPhone app will display the drones position and the user's position (check) on a map.
The part I'm having issues with currently is having the app maintain a continuous subscription to a topic and then update several variables in the code. Currently, the code below contains the subscription line and "did receive message" code inside of of a button view which only works momentarily when that button is pressed.
I've tried pasting this code in various places within the content view with no success; admittedly I'm a novice coder and Swift/iOS is very new to me. Ideally, the app would continually monitor certain topics and update several variables to equal the message when certain topics are posted to by the drone.
...ANSWER
Answered 2020-Oct-11 at 07:31this is my first answer in StackOverflow and I'm a novice too. I was having the same problem, but I can solve it by declaring the "didConnectAck" for the mqttClient; the subscription remains. Just add the following missing lines to your code:
QUESTION
I have singleton class
...ANSWER
Answered 2017-Mar-15 at 12:07Atomic properties won't help you here. They are intended to sync on assignment of the property as a whole and not of the internals (e.g. they do not sync insertion/removal of elements to the array). They almost only ensure correct retain/release/autorelease calls in order to keep your program from crashing / leaking.
What you would need is DispatchSemaphore or something similar (or maybe more native stuff, posix pthread_mutex
stuff) to ensure mutual exclusive access.
QUESTION
I am making one iOS app communicating with Mqtt broker, mainly to publish message. But when I try to connect with broker using CocoaMQTT library it's always giving me error in connection.
I am trying with CocoaMQTT latest version and also 1.1.3 version. But both are failing in connection and giving me error
...(Error Domain=kCFStreamErrorDomainNetDB Code=8 "nodename nor servname provided, or not known" UserInfo={NSLocalizedDescription=nodename nor servname provided, or not known})
ANSWER
Answered 2019-Jul-11 at 08:03As shown in the CocoaMQTT doc, the host
entry in the init
method should be just the hostname, not a URI:
QUESTION
I have produced an app that connects to a raspberry pi's own wifi network and sends a message to give some data to it. I was using the cocoamqtt Library found here but I couldn't find a way to know when the client connects successfully or not so I move to the Moscapsule Library found here. I could easily connect to my pi with the cocoamqtt library, but whenever I try to connect to the pi with the Moscapsule library it just says 'Received DISCONNECT from iDevice' as soon as it makes a connection.
Here's my code:
...ANSWER
Answered 2019-Aug-13 at 12:41I'm going to go out on a limb here since I've never used Swift.
The only reference to the mqtt client object client
is as a local variable in the connect()
method.
Once this method returns the client
object will go out of scope so will become eligible for Garbage Collection. I would assume that the client
object has a destructor that calls disconnect before it is actually destroyed, hence the immediate disconnect.
The fix is to make sure there is a reference to the client
object that lives as long as you need it to.
QUESTION
I'm trying to set up a connection using CocoaMQTT. The following example is provided on the GitHub page:
https://github.com/emqx/CocoaMQTT/blob/master/Example/Example/ViewController.swift
They are using a view controller 'self' as the delegate (see lines 53/63/74). However, when I try to use the view controller as the delegate, I get the error:
...ANSWER
Answered 2019-Aug-02 at 11:58Thanks @Vollan for suggesting adding the extension at the bottom of the file. I probably should've noticed that. My bad.
QUESTION
I completed a few months ago a project with CocoaMQTT. Now I want to do a new project and I created the files like the one before. Now I get this error-codes. When I click the button to update the Code, I get new error-codes. Got someone the same problem or know a solution?
...ANSWER
Answered 2018-Oct-15 at 11:52You are mixing Swift 3 and Swift 4 in your project. Because Swift 3 and Swift 4 are not source-compatible, this can not work. You need to either use Swift 3 for everything, or Swift 4 for everything.
For CocoaMQTT there is a Swift 4.2 version available since Oct 12, 2018.
SwiftyTimer looks abandoned, and there is no Swift 4 version of it yet (Oct 2018). It has been used by CocoaMQTT previously, but they have dropped that dependency with the new version. So there should be no problem once you upgrade CocoaMQTT, unless you are using SwiftyTimer yourself.
You will need to support Swift 4 eventually (if not now, then in 1 year maybe). Maybe you can get away with staying with Swift 3 for now..
QUESTION
i have a problem with my mqttconfiguration. Connection works fine. Every time I send a message, switch to another ViewController, come back and push again the sending button, no message received at my raspberry. So the problem is, when I switch over multiple ViewController I can't send messages anymore. I don't find my mistake in my code:
Swiftfile for MQTT-Config:
...ANSWER
Answered 2018-Oct-07 at 00:04It seems that you have tried to set up your MQTT client class as a singleton, but then code looks a little off.
Use
QUESTION
I have a Raspberry Pi with a temperature sensor, that has a python script which constantly publishes the temperature using MQTT, and I have set the interval for every 1sec. In the iOS app I am making I have an MQTTManager class which has an mqttClient that subscribes to its topic and receives the string with the temperature. In the main view of my app I want to display the temperature and have it constantly updated, with the same (or close to the same) speed as the python script is sending it. The idea I have so far is to have the text of a UILabel be updated with the message string from the mqtt client message. I am not sure how update the label text correctly, with every sent publish event. I know I need to set up some kind of event handler for this message but I am not sure how to go about it. Any help will be appreciated.
UPDATE: With the code that I have so far. This is my mqttManager:
...ANSWER
Answered 2018-Feb-11 at 08:38I think you might solve it with a simple Notification
.
First you should add an observer where you want to update such label, doing so:
QUESTION
I am going to update my customised sample based on Build a home assistant mobile application with Watson and IoT Platform services
I did:
carthage update --platform iOS
- did the
pod install
- Using the autofix for the API Changes of the Watson Conversation Parameter inside xCode
- Asking a question about: How to handle a concrete situation with a parameter, here on Stack Overflow
And now I got a linker error and I do not now is the error related to the update of the API or is it related to a newer xCode version, or the RestKit?
In this code I get the message:
d: framework not found RestKit clang: error: linker command failed with exit code 1 (use -v to see invocation)'
...ANSWER
Answered 2018-Jan-20 at 18:02If you are using the latest release of the Watson Swift SDK, it no longer builds RestKit as a separate framework, but instead links it directly into each service. So you should be able to just remove the RestKit framework from your project.
In your particular case, you need to select the Home Assistant Project in Xcode and then the Home Assistant target.
In Build Phases, open "Link Binary with Libraries" item and delete RestKit.framework.
Then in the "Run Script" phase, delete RestKit.framework from the input files list.
With these two changes your app should build.
QUESTION
I have class named MQTTController with shared instance and a private init method
...ANSWER
Answered 2017-Feb-24 at 07:37The error message told you what needs to be done, you need to call super.init() in your init.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CocoaMQTT
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page