Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- private static string TopicDevice2Service;
- private static MqttClient client;
- public static void Main(string[] args)
- {
- const string ioTHubName = "myhubname";
- // Azure IoT gateway (MQTT broker)
- const string gatewayHost = "azure-devices.net";
- const int gatewayMqttPort = 8883;
- const string deviceId = "my_device";
- var username = string.Format("{0}/{1}/api-version=2016-11-14", ioTHubName, deviceId);
- var password =
- "SharedAccessSignature sr=myhubname.azure-devices.net&sig=g%2BFmmJxxxxxxE%3D&se=1520101215&skn=iothubowner";
- TopicDevice2Service = string.Format("devices/{0}/messages/events", deviceId);
- try
- {
- client = new MqttClient(gatewayHost, gatewayMqttPort, true, MqttSslProtocols.TLSv1_0, (sender, certificate, chain, errors) => true, null);
- client.Connect(deviceId, username, password);
- while (true)
- {
- client.Publish(TopicDevice2Service, Encoding.UTF8.GetBytes("telemetric_data"));
- System.Threading.Thread.Sleep(2000);
- }
- }
- catch (Exception ex)
- {
- Console.Write(ex.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement