-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MQTTClient.jl Extension (#9)
* Implement MQTTClient.jl Extension + update code formatting + add/update docs + add tests + get MQTTClient working * update documentation * fix tests and MQTTClient version * fix documentation error * fix tests for mqtt client on windows * Format files using JuliaFormatter (#10)
- Loading branch information
1 parent
5728eb2
commit 9aa452a
Showing
14 changed files
with
384 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
style = "blue" | ||
|
||
margin = 120 | ||
remove_extra_newlines = true | ||
format_docstrings = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MQTT" | ||
uuid = "ebefff21-3b8f-497c-a71a-d17835ab79ba" | ||
authors = ["Nicholas Shindler <[email protected]> and contributors"] | ||
version = "0.0.2-DEV" | ||
version = "0.1.0" | ||
|
||
[deps] | ||
|
||
|
@@ -14,10 +14,19 @@ AWSCRTExt = "AWSCRT" | |
MQTTClientExt = "MQTTClient" | ||
|
||
[compat] | ||
AWSCRT = "^0.3" | ||
Aqua = "^0.8" | ||
MQTTClient = "^0.3.1" | ||
Test = "^0" | ||
Sockets = "^0" | ||
julia = "1.9" | ||
|
||
[extras] | ||
AWSCRT = "df31ea59-17a4-4ebd-9d69-4f45266dc2c7" | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
MQTTClient = "985f35cc-2c3d-4943-b8c1-f0931d5f0959" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" | ||
|
||
[targets] | ||
test = ["Test"] | ||
test = ["Aqua", "AWSCRT", "MQTTClient", "Test", "Sockets"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,53 @@ | ||
module AWSCRTExt | ||
|
||
import AWSCRT, MQTT | ||
using AWSCRT: AWSCRT | ||
using MQTT: MQTT | ||
|
||
struct MQTT.MQTTConnection <: MQTT.AbstractConnection | ||
struct AWSCRTConfig <: MQTT.AbstractConnection | ||
connection::AWSCRT.MQTTConnection | ||
endpoint::String | ||
port::Int | ||
id::String | ||
connect_kwargs::Dict{Symbol,Any} | ||
end | ||
|
||
MQTT.MQTTConnection(connection, endpoint, port, id; connect_kwargs = Dict()) = | ||
MQTT.MQTTConnection(connection, endpoint, port, id, connect_kwargs) | ||
function MQTT.MQTTConnection(connection, endpoint, port, id; connect_kwargs=Dict()) | ||
return AWSCRTConfig(connection, endpoint, port, id, connect_kwargs) | ||
end | ||
|
||
function MQTT._resolve(async_object) | ||
fetch(async_object) | ||
return fetch(async_object) | ||
end | ||
|
||
function MQTT._connect(c::MQTT.MQTTConnection) | ||
function MQTT._connect(c::AWSCRTConfig) | ||
return AWSCRT.connect(c.connection, c.endpoint, c.port, c.id; c.connect_kwargs...) | ||
end | ||
|
||
function MQTT._subscribe(callback, c::MQTT.MQTTConnection, topic, qos) | ||
task, id = AWSCRT.subscribe(c.connection, topic, qos = AWSCRT.aws_mqtt_qos(Int(qos)), _adapt_on_message(callback)) | ||
function MQTT._subscribe(callback::AWSCRT.OnMessage, c::AWSCRTConfig, topic, qos) | ||
task, id = AWSCRT.subscribe(c.connection, topic; qos=AWSCRT.aws_mqtt_qos(Int(qos)), callback) | ||
return task | ||
end | ||
|
||
function MQTT._publish(c::MQTT.MQTTConnection, topic, payload, qos, retain) | ||
task, id = AWSCRT.publish(c.connection, topic, payload, qos = AWSCRT.aws_mqtt_qos(Int(qos)), retain = retain) | ||
function MQTT._publish(c::AWSCRTConfig, topic, payload, qos, retain) | ||
task, id = AWSCRT.publish(c.connection, topic, payload; qos=AWSCRT.aws_mqtt_qos(Int(qos)), retain=retain) | ||
return task | ||
end | ||
|
||
function MQTT._unsubscribe(c::MQTT.MQTTConnection, topic) | ||
function MQTT._unsubscribe(c::AWSCRTConfig, topic) | ||
task, id = AWSCRT.unsubscribe(c.connection, topic) | ||
return task | ||
end | ||
|
||
function MQTT._disconnect(c::MQTT.MQTTConnection) | ||
function MQTT._disconnect(c::AWSCRTConfig) | ||
return AWSCRT.disconnect(c.connection) | ||
end | ||
|
||
function _adapt_on_message(cb::MQTT.OnMessage) | ||
return function _awscrt_on_message(topic, payload, dup, qos, retain) | ||
return cb(topic, payload) | ||
end | ||
end | ||
# function _adapt_on_message(cb::MQTT.OnMessage) | ||
# return function essage(topic, payload, dup, qos, retain) | ||
# return cb(topic, payload) | ||
# end | ||
# end | ||
|
||
MQTT.OnMessage = AWSCRT.OnMessage | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
module MQTTClientExt | ||
|
||
using MQTTClient, MQTT | ||
using MQTTClient: MQTTClient | ||
using MQTT: MQTT | ||
|
||
struct MQTT.MQTTConnection <: MQTT.AbstractConnection | ||
struct MQTTClientConfig <: MQTT.AbstractConnection | ||
client::MQTTClient.Client | ||
connection::MQTTClient.MQTTConnection | ||
connection::MQTTClient.Connection | ||
end | ||
function MQTT.MQTTConnection(configuration::MQTTClient.Configuration) | ||
return MQTTClientConfig(configuration.client, configuration.connection) | ||
end | ||
MQTT.MQTTConnection(client::MQTTClient.Client, connection::MQTTClient.Connection) = MQTTClientConfig(client, connection) | ||
|
||
function MQTT._resolve(async_object) | ||
MQTTClient.resolve(async_object) | ||
return MQTTClient.resolve(async_object) | ||
end | ||
|
||
function MQTT._connect(c::MQTT.MQTTConnection) | ||
MQTTClient.connect_asyc(c.client, c.connection) | ||
function MQTT._connect(c::MQTTClientConfig) | ||
return MQTTClient.connect_async(c.client, c.connection) | ||
end | ||
|
||
function MQTT._subscribe(callback, c::MQTT.MQTTConnection, topic, qos::MQTT.QOS) | ||
MQTTClient.subscribe_async(c.client, topic, on_msg, qos = MQTTClient.QOS(UInt8(qos))) | ||
function MQTT._subscribe(callback::MQTT.OnMessage, c::MQTTClientConfig, topic::AbstractString, qos::MQTT.QOS) | ||
return MQTTClient.subscribe_async(c.client, topic, callback; qos=MQTTClient.QOS(UInt8(qos))) | ||
end | ||
|
||
function MQTT._publish(c::MQTT.MQTTConnection, topic, payload, qos::MQTT.QOS, retain) | ||
publish_async(c.client, topic, payload, qos = MQTTClient.QOS(UInt8(qos)), retain = retain) | ||
function MQTT._publish(c::MQTTClientConfig, topic::AbstractString, payload, qos::MQTT.QOS, retain) | ||
return MQTTClient.publish_async(c.client, topic, payload; qos=MQTTClient.QOS(UInt8(qos)), retain=retain) | ||
end | ||
|
||
function MQTT._unsubscribe(c::MQTT.MQTTConnection, topic) | ||
unsubscribe_async(c.client, topic) | ||
function MQTT._unsubscribe(c::MQTTClientConfig, topic::AbstractString) | ||
return MQTTClient.unsubscribe_async(c.client, topic) | ||
end | ||
|
||
function MQTT._disconnect(c::MQTT.MQTTConnection) | ||
disconnect(c.client) | ||
function MQTT._disconnect(c::MQTTClientConfig) | ||
return MQTTClient.disconnect(c.client) | ||
end | ||
|
||
end # module |
Oops, something went wrong.
9aa452a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
First version.
what more can you ask for.
9aa452a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error while trying to register: Register Failed
@NickMcSweeney, it looks like you are not a publicly listed member/owner in the parent organization (JuliaMessaging).
If you are a member/owner, you will need to change your membership to public. See GitHub Help
9aa452a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
First version.
what more can you ask for.
9aa452a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/108037
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: