Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMcSweeney committed Jun 19, 2023
1 parent eb1c7d9 commit 4fbd469
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ Also based on testing, for simple/low load networks it is slower to run it threa

## Getting started
To use this library you need to follow at least these steps:
1. Define an `on_msg` callback function.
2. Create an instance of the `Client` struct and pass it your `on_msg` function.
1. Define an `on_msg` callback function for a given topic.
2. Create an instance of the `Client` struct.
3. Call the connect method with your `Client` instance.
4. Exchange data with the broker through publish, subscribe and unsubscribe.
4. Exchange data with the broker through publish, subscribe and unsubscribe. When subscribing, pass your `on_msg` function for that topic.
5. Disconnect from the broker. (Not strictly necessary, if you don't want to resume the session but considered good form and less likely to crash).

#### Basic example
Expand All @@ -100,13 +100,13 @@ function on_msg(topic, payload)
end

#Instantiate a client.
client = Client(on_msg)
connect(client, broker)
client = Client()
connect(client, broker, 1883)
#Set retain to true so we can receive a message from the broker once we subscribe
#to this topic.
publish(client, "jlExample", "Hello World!", retain=true)
#Subscribe to the topic we sent a retained message to.
subscribe(client, ("jlExample", QOS_1))
subscribe(client, "jlExample", on_msg, qos=QOS_1))
#Unsubscribe from the topic
unsubscribe(client, "jlExample")
#Disconnect from the broker. Not strictly needed as the broker will also
Expand All @@ -127,15 +127,19 @@ The client struct is used to store state for an MQTT connection. All callbacks,
* **on_unsubscribe**::Function:

##### Constructors
All constructors take the `on_message` callback as an argument.

```julia
Client(on_msg::Function)
Client()
```

Specify a custom ping_timeout
```julia
Client(on_msg::Function, ping_timeout::UInt64)
Client(ping_timeout::UInt64 = 10)
```

Use the wrapping function. this is equivalent to using the Client constructor; but with more specific syntax.
```julia
MQTTConnection()
```

## Message struct
Expand Down Expand Up @@ -265,26 +269,28 @@ Subscribes the `Client` instance, provided as a parameter, to the specified topi
#### Arguments
**Required arguments:**
* **client**::Client: The connected client to subscribe on. TODO phrasing?
* **topics**::Tuple{String, QOS}...: A variable amount of tuples that each have a String and a QOS constant.
* **topic**::String: The name of the topic.
* **on_msg**::Function: the callback function for that topic.
* **qos**::QOS: the named argument to set the QOS, defaults to QOS_0.

#### Call example
This example subscribes to the topic "test" with QOS_2 and "test2" with QOS_0.
```julia
subscribe(c, ("test", QOS_2), ("test2", QOS_0))
subscribe(c, "test", ((t,p)->do_a_thing(p)), qos=QOS_2))
```

#### Synchronous subscribe
This method waits until the subscribe message has been successfully sent and acknowledged. TODO add return documentation

```julia
function subscribe(client, topics::Tuple{String, QOS}...)
subscribe(c, "test", on_msg, qos=QOS_2))
```

#### Asynchronous subscribe
This method doesn't wait and returns a `Future` object. You may choose to wait on this object. This future completes once the subscribe message has been successfully sent and acknowledged. TODO change future data documentation

```julia
function subscribe_async(client, topics::Tuple{String, QOS}...)
function subscribe_async(c, "test", on_msg, qos=QOS_2))
```

## Unsubscribe
Expand Down

2 comments on commit 4fbd469

@NickMcSweeney
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/85877

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:

git tag -a v0.1.0 -m "<description of version>" 4fbd469b8c2929c57817c3190cd98d059d4fcfb4
git push origin v0.1.0

Please sign in to comment.