-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not receive messages #55
Comments
Do you call |
yes, i have tryed calling it didn't work |
it says that I'm connected and i can subscribe but no call back function works |
Ah, just noticed. You configure callback functions after connect, but you should do it before. |
So, did it help? |
I'm trying to use the sample code, and I am getting: So I get the connection, but it immediately disconnects and never receives any messages. ` moscapsule_init()
1496321558: New client connected from 192.168.1.106 as cid (c1, k60). 1496321558: Client cid disconnected. |
Same problem occurred to me. Have you fixed it? How to deal with it? Appreciate your help. |
@AlexIzh came to this issue in search of same problem and found your suggestion to initialise callback before connection solved my problem. Thanks. It worked for me. |
Same problem occurred to me. Have you fixed it? How to deal with it. |
You need to call setting of onConnectCallback and onMessageCallback before MQTT.newConnection. Its at the time of newConnection that callbacks are set in my understanding. |
@shobhitka i tried it but stil not working |
Can you paste your current code here ? |
|
I can't see how this code block is called. But, as the code above is written, the MQTTConfig and MQTT connection objects only live in the scope of this code block. Once this code block returns, these objects will go out of scope be torn down. I'd double check that your objects are staying in scope after the connection. |
@smartAkash, as @bjpetit mentioned, this looks like maybe the issue, otherwise the sequence of initialisation looks okay. |
import UIKit class dataHubView: UIViewController{
} I have a very similar issue with mine everything connects and subscribes but as soon as its done it disconnects 2018-05-16 18:01:52.266177-0700 Centurion[7956:3105281] [MOSQUITTO] DEBUG Client iOS sending CONNECT |
@TayyibFZ Thanks for shared your code i checked and tested now it is connected but have problem of receiving msg whatever i subscribed not getting msg.....you can see my below code please help...
|
@TayyibFZ, the reason this code disconnects right away is because the mqttClient (and mqttConfig) object only exists in the context of the viewDidLoad() method because they are declared in that method. Once viewDidLoad() completes this object will be torn down and the connection will be closed. These objects, which you want to stay around, should be declared outside of viewDidLoad. You can run the rest of the code you have in that method, but you should declare mqttConfig and mqttClient in a spot where they will stick around, for example, either declare them in the ViewController object or globally. |
@bjpetit Hi i have used separate that function is out side of viewDidLoad() it is connecting but not receiving msg whatever subscribed channels you can see my code above in comments.... |
I did a little bit of tinkering and finally got everything to work hank you very much @bjpetit. Also @smartAkash no entirely sure but try using your callbacks inside the viewDidLoad() and subscribing and connecting to your server thru a push button that fixed the problem with mine. |
@TayyibFZ, glad to hear things are coming together. @smartAkash, from the code block you posted, the calls look to be correct. And the logs show the connection and the subscribe. However, it looks like a disconnect is called right after the subscribe completes. So your connection is being closed down before any messages can come in. |
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)
}
it does not go in onMessageCallback...
The text was updated successfully, but these errors were encountered: