Skip to content

Instantly share code, notes, and snippets.

@bertt
Last active May 26, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertt/e7f30456a44e4e138ebf784bcddefad9 to your computer and use it in GitHub Desktop.
Save bertt/e7f30456a44e4e138ebf784bcddefad9 to your computer and use it in GitHub Desktop.
Gost and MQTT in C#
using System;
using System.Text;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace MqttClient_Net
{
class Program
{
static void Main()
{
var server = "gost.geodan.nl";
var topic = "Datastreams(1)/Observations";
var message = "{\"phenomenonTime\": \"2016 - 05 - 09T11: 04:15.790Z\", \"result\": 20 }";
Console.WriteLine("Gost - MQTT Client");
var client = new MqttClient(server);
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
var clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
Console.WriteLine("Listening....");
// subscribe
client.Subscribe(new[] { topic },new[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
// and publish something...
client.Publish("GOST/"+topic, Encoding.Default.GetBytes(message));
}
private static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
var str = Encoding.Default.GetString(e.Message);
Console.WriteLine("result: " + str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment