See Official Readme for more informations.
I've made this fork to extend MQTT Publish/Subscribe capability with Geo Location filtering for a University Project.
By setting a subscription on a specific subpath of a topic, it must be possible to receive all of messages sent on a defined range.
-
Creating and connecting an MQTT client with default options:
var configuration = new MqttConfiguration(); var client = await MqttClient.CreateAsync("192.168.1.10", configuration); var sessionState = await client.ConnectAsync (new `MqttClientCredentials`(clientId: "foo"));
The ConnectAsync method returns once the CONNACK packet has been received from the Server.
The session state value contains information about if the session has been re used or cleared
-
Creating and connecting an MQTT client specifying configuration and clean session:
var configuration = new MqttConfiguration { BufferSize = 128 * 1024, Port = 1883, KeepAliveSecs = 10, WaitTimeoutSecs = 2, MaximumQualityOfService = MqttQualityOfService.AtMostOnce, AllowWildcardsInTopicFilters = true, AllowLocationSubscription = true // Addition to enable Geo Location filtering }; var client = await MqttClient.CreateAsync("192.168.1.10", configuration); var sessionState = await client.ConnectAsync (new `MqttClientCredentials`(clientId: "foo"), cleanSession: true);
-
Subscribing and unsubscribing to normal topics has not changed:
await client.SubscribeAsync("foo/bar/topic1", MqttQualityOfService.AtMostOnce); //QoS0 await client.SubscribeAsync("foo/bar/topic2", MqttQualityOfService.AtLeastOnce); //QoS1 await client.SubscribeAsync("foo/bar/topic3", MqttQualityOfService.ExactlyOnce); //QoS2
The SubscribeAsync method returns once the SUBACK packet has been received from the Server
await client.UnsubscribeAsync("foo/bar/topic1"); await client.UnsubscribeAsync("foo/bar/topic2"); await client.UnsubscribeAsync("foo/bar/topic3");
The UnsubscribeAsync method returns once the UNSUBACK packet has been received from the Server
-
Subscribing to geo location topics is done in the following way:
var topic = "topics/loc/ll=xx.xx,yy.yy&s=circle&r=15&u=(m|km)&t=(timestamp)"; client.SubscribeAsync(topic, MqttQualityOfService.AtMostOnce); //QoS0
- The first part of the topic must be "topics/loc/";
- The separator for the parameters is the "&";
- The ll (LatLon) parameter must be followed by the double value of the latitude and the second one by the longitude value separated by a comma ",";
- The s (shape) parameter must be one of the following values (circle) (for now is the only supported, sorry)
- The u (unit) parameter must be one of the following values (m, km);
- The t (timestamp) parameter must be the timestamp of the current time
For more specific information about the MQTT protocol, please see the latest Oasis spec.