update runtest
This commit is contained in:
@@ -147,7 +147,7 @@ function mqttClientInstance_v2(
|
|||||||
mqttBrokerAddress::String,
|
mqttBrokerAddress::String,
|
||||||
subtopic::Vector{String},
|
subtopic::Vector{String},
|
||||||
msgReceiveChannel, # NamedTuple of channels i.e. msgReceiveChannel = (ch1=Channel(8), ch2=Channel(8))
|
msgReceiveChannel, # NamedTuple of channels i.e. msgReceiveChannel = (ch1=Channel(8), ch2=Channel(8))
|
||||||
keepaliveChannel::Channel, # user needs to specify because it has to be accessible by user-defined onMsgCallback()
|
keepaliveChannel::Channel, # used for checkMqttConnection(). user needs to specify because it has to be accessible by user-defined onMsgCallback()
|
||||||
onMsgCallback::Function
|
onMsgCallback::Function
|
||||||
;
|
;
|
||||||
mqttBrokerPort::Integer=1883,
|
mqttBrokerPort::Integer=1883,
|
||||||
@@ -426,7 +426,7 @@ end
|
|||||||
-----
|
-----
|
||||||
```jldoctest
|
```jldoctest
|
||||||
julia> using Revise
|
julia> using Revise
|
||||||
julia> using GeneralUtils, Dates, JSON3, MQTTClient
|
julia> using GeneralUtils, Dates, JSON3
|
||||||
julia> GeneralUtils.checkMqttConnection!(mqttInstance, 5)
|
julia> GeneralUtils.checkMqttConnection!(mqttInstance, 5)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +1,36 @@
|
|||||||
using Revise
|
using Revise
|
||||||
using GeneralUtils
|
using GeneralUtils, MQTTClient, JSON3
|
||||||
|
|
||||||
|
mqttMsgReceiveTopic = ["/receivetopic_1", "/receivetopic_2"]
|
||||||
|
mqttMsgReceiveChannel = (ch1=Channel(8), ch2=Channel(32))
|
||||||
|
keepaliveChannel = Channel(8)
|
||||||
|
function onMsgCallback(topic, payload)
|
||||||
|
jobj = JSON3.read(String(payload))
|
||||||
|
incomingMqttMsg = copy(jobj) # convert json object into julia dictionary recursively
|
||||||
|
|
||||||
|
if occursin("topic_1", topic)
|
||||||
# text = "TODAY thought: what to do plan: wake up and going out action: 1. wake up 2. eat 3. sleep"
|
put!(mqttMsgReceiveChannel[:ch1], incomingMqttMsg)
|
||||||
|
elseif occursin("topic_2", topic)
|
||||||
# sample_keywords = ["thought", "plan", "action"]
|
put!(mqttMsgReceiveChannel[:ch2], incomingMqttMsg)
|
||||||
|
elseif occursin("keepalive", topic)
|
||||||
|
put!(keepaliveChannel, incomingMqttMsg)
|
||||||
# resultdict = GeneralUtils.textToDict(text, sample_keywords; rightmarker=":", symbolkey=true)
|
else
|
||||||
|
println("undefined condition ", @__FILE__, " ", @__LINE__)
|
||||||
|
end
|
||||||
# println(resultdict)
|
end
|
||||||
|
mqttInstance = GeneralUtils.mqttClientInstance_v2(
|
||||||
|
"mqtt.yiem.cc",
|
||||||
storedata = Channel(8)
|
mqttMsgReceiveTopic,
|
||||||
keepalive = Channel(8)
|
mqttMsgReceiveChannel,
|
||||||
|
keepaliveChannel,
|
||||||
function onMsgCallback_1(topic, payload)
|
onMsgCallback
|
||||||
jobj = JSON3.read(String(payload))
|
)
|
||||||
incomingMqttMsg = copy(jobj) # convert json object into julia dictionary recursively
|
|
||||||
|
|
||||||
topic = split(topic, "/")
|
|
||||||
if "keepalive" ∈ _topic
|
|
||||||
put!(keepaliveChannel, incomingMqttMsg)
|
|
||||||
elseif "testingprompt" ∈ topic
|
|
||||||
# @show incomingMqttMsg
|
|
||||||
put!(storedata, incomingMqttMsg)
|
|
||||||
else
|
|
||||||
@show "undefined condition"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
mqttInstance = GeneralUtils.mqttClientInstance(
|
|
||||||
"mqtt.yiem.cc",
|
|
||||||
1883,
|
|
||||||
["/testingprompt"],
|
|
||||||
storedata,
|
|
||||||
keepalive,
|
|
||||||
onMsgCallback_1
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
_ = GeneralUtils.checkMqttConnection!(mqttInstance)
|
_ = GeneralUtils.checkMqttConnection!(mqttInstance)
|
||||||
|
|
||||||
|
|
||||||
println("555")
|
println("GeneralUtils test done")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user