Closed altayeng closed 2 years ago
First of all, you should make sure your broker is working. Then try to use the connection function:
mqtt = CocoaMQTT(clientID: "mqttdashboard", host: "broker.mqttdashboard.com", port: 8000)
mqtt!.username = ""
mqtt!.password = ""
mqtt!.willMessage = CocoaMQTTMessage(topic: "your topic", string: "dieout")
mqtt!.keepAlive = 60
mqtt!.delegate = self
If the connection is accept, you will get the delegate from mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck). After that you can use mqtt.subscribe("your topic", qos: CocoaMQTTQoS.qos1) to make new subscription
func mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck) {
if ack == .accept {
mqtt.subscribe("your topic", qos: CocoaMQTTQoS.qos1)
}
}
Cannot find 'mqtt' in scope
I want to make simple MQTT Subscribe app for iOS. User press button and data's will show in the screen. So i decided to install CocoaMQTT. Before to design main screen, i'll connect to my mqtt with viewcontroller.swift for show datas in terminal menu at XCode. Here is my code:
`
import UIKit import CocoaMQTT
class ViewController: UIViewController { var mqtt: CocoaMQTT?
} `
After i build this code, nothing happening. Meanwhile, mqtt.delegate is give me a error. How can i connect to my mqtt and sub it? Thanks for help.