remove userHander()

This commit is contained in:
ton
2023-10-06 20:07:48 +07:00
parent fe4da2b555
commit e6f7d0bf5e
5 changed files with 986 additions and 25 deletions

View File

@@ -241,12 +241,12 @@ end
"""
mqtt communication loop, call this function manually
"""
function mqttRun(client::mqttClient, userMsgHandler::Function)
function mqttRun(client::mqttClient)
mqttLoop!(client)
mqttCheckConnection!(client)
mqttReconnect!(client)
mqttSubOnConnect!(client)
mqttOnmessage!(client, userMsgHandler)
return mqttOnmessage!(client)
end
@@ -260,9 +260,9 @@ end
end
"""
function mqttOnmessage!(client::mqttClient, userMsgHandler::Function)
function mqttOnmessage!(client::mqttClient)
nmessages = Base.n_avail(get_messages_channel())
nmessages == 0 && return 0
nmessages == 0 && return nothing
timepass = (Dates.now() - client.boottime).value / 1000.0
@@ -280,9 +280,8 @@ function mqttOnmessage!(client::mqttClient, userMsgHandler::Function)
topic = pkg.topic
# sptoptic = split(topic, "/")
payload = vecToDict(pkg.payload) # payload in Dict format
# Do something with the message
userMsgHandler(topic, payload) # user defined function in user space. How to handle msg
return payload
end
end
end
@@ -348,21 +347,8 @@ function respond(client::mqttClient, respond_msg::Dict, request_msg::Dict; pubto
end
"""
Store details about mqtt and connected-Clients1
Example of mqtt_member_dict which store details about mqtt and connected-Client
"""
mqtt_member_dict = Dict(
:firstClient=> Dict( # masterController itself for internal communication
@@ -429,8 +415,6 @@ mqtt_member_dict = Dict(
)
""" operate on mqtt_member_dict
Connect all clients to relevent server
"""
@@ -536,7 +520,7 @@ end
""" operate on mqtt_member_dict
"""
# What to do if there is a message
function mqttOnmessage!(mqttMemberDict, netpieCommDict::Dict, workDict::Dict)
function mqttOnmessage!(mqttMemberDict::Dict, netpieCommDict::Dict, workDict::Dict)
nmessages = Base.n_avail(get_messages_channel())
nmessages == 0 && return 0
@@ -604,7 +588,7 @@ end
""" operate on mqtt_member_dict
network run
"""
function mqttLoop!(mqttMemberDict; timeout=100)
function mqttLoop!(mqttMemberDict::Dict; timeout=100)
for (k, v) in mqttMemberDict
member = mqttMemberDict[k]
loop(member[:mqttClient], timeout=timeout)