2019-09-10

tcl.mqttc v0.6

因為 paho.mqtt.c 有一個新的版本 1.3.1,所以我做了 tcl.mqttc 相關的更新,同時將版本設成 v0.6。

不過我只有測試 tcp 部份,使用 ActiveMQ 測試 MQTT 3.1,以及使用 EMQX 測試 MQTT 3.1 以及 5 的部份。

我忘記是不是有在這個部落格貼過了,下面是 MQTT 3.1 測試 Subscribe 與 Publish 功能的測試程式:
package require Thread
package require mqttc
catch {console show}

set ::gThread [thread::create {thread::wait} ]
set result 0

proc subscribe { } {
    thread::send -async $::gThread {
        package require mqttc

        mqttc client "tcp://localhost:1883" "USERTest1" 1 -cleansession 1
        client subscribe  "MQTT Examples" 1
        while 1 {
            if {[catch {set result [client  receive]}]} {
                puts "Receive error!!!"
                break
            }
            if {[llength $result] > 0} {
                puts "[lindex $result 0] - [lindex $result 1]"
                if {![string compare -nocase [lindex $result 1] "Exit"]} {
                    break
                }
            }
        }
        client unsubscribe  "MQTT Examples"
        client close
    } ::result
}

subscribe
puts "started test..."

after 250

mqttc client "tcp://localhost:1883" "USERTest2" 1 -timeout 1000
client publishMessage "MQTT Examples" "Hello MQTT!" 1 0
client publishMessage "MQTT Examples" "Exit" 1 0
client close

vwait ::result

沒有留言: