Skip to content

test.mosquitto.org Certificate .. #18

@valoni

Description

@valoni

i did a simple test (which work with MQTTnet but do not work with emitter - can you make it working)
--------------- code ----------------------

using System;
using System.Text;
using System.Threading;

using Emitter;
using Emitter.Messages;

using System.Security.Cryptography.X509Certificates;

namespace EmitterMQTTMossquitto
{
    class Program
    {
        static void Main(string[] args)
        {
            MqttClient client = null;
            string clientId;
 
            X509Certificate caCert = new X509Certificate(Encoding.UTF8.GetBytes(GetCertificate));
   
            // connect to the Mosquito test server
            client = new MqttClient("test.mosquitto.org", 8883, true, caCert, null, MqttSslProtocols.TLSv1_2);

            // use a unique id as client id, each time we start the application
            clientId = Guid.NewGuid().ToString();

            Console.WriteLine("Connecting to Mosquito test server...");

            client.Connect(clientId);

            Console.WriteLine("Connected to Mosquito test server");

            while (true)
            {
                // send random temperature value to Gauge demo in Mosquito test server, see http://test.mosquitto.org/gauge/
                client.Publish("temp/random", GetRandomTemperature(), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);

                // the Mosquito test server has a local process that updates every 15 seconds, so we just follow that
                Thread.Sleep(15000);
            }

        }

        private static byte[] GetRandomTemperature()
        {
            // generate random value
            Random randomProvider = new Random();
            var randomTemperature = randomProvider.NextDouble() * 10;

            // convert to string formatted NN.NN
            var temperatureAsString = randomTemperature.ToString("N2");

            Console.WriteLine($"Temperature: {temperatureAsString}");

            return Encoding.UTF8.GetBytes(temperatureAsString);
        }

        // Mosquito test server CA certificate
        // from http://test.mosquitto.org/
        // X509 
        static string GetCertificate =
@"-----BEGIN CERTIFICATE-----
MIIC8DCCAlmgAwIBAgIJAOD63PlXjJi8MA0GCSqGSIb3DQEBBQUAMIGQMQswCQYD
VQQGEwJHQjEXMBUGA1UECAwOVW5pdGVkIEtpbmdkb20xDjAMBgNVBAcMBURlcmJ5
MRIwEAYDVQQKDAlNb3NxdWl0dG8xCzAJBgNVBAsMAkNBMRYwFAYDVQQDDA1tb3Nx
dWl0dG8ub3JnMR8wHQYJKoZIhvcNAQkBFhByb2dlckBhdGNob28ub3JnMB4XDTEy
MDYyOTIyMTE1OVoXDTIyMDYyNzIyMTE1OVowgZAxCzAJBgNVBAYTAkdCMRcwFQYD
VQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwGA1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1v
c3F1aXR0bzELMAkGA1UECwwCQ0ExFjAUBgNVBAMMDW1vc3F1aXR0by5vcmcxHzAd
BgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hvby5vcmcwgZ8wDQYJKoZIhvcNAQEBBQAD
gY0AMIGJAoGBAMYkLmX7SqOT/jJCZoQ1NWdCrr/pq47m3xxyXcI+FLEmwbE3R9vM
rE6sRbP2S89pfrCt7iuITXPKycpUcIU0mtcT1OqxGBV2lb6RaOT2gC5pxyGaFJ+h
A+GIbdYKO3JprPxSBoRponZJvDGEZuM3N7p3S/lRoi7G5wG5mvUmaE5RAgMBAAGj
UDBOMB0GA1UdDgQWBBTad2QneVztIPQzRRGj6ZHKqJTv5jAfBgNVHSMEGDAWgBTa
d2QneVztIPQzRRGj6ZHKqJTv5jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUA
A4GBAAqw1rK4NlRUCUBLhEFUQasjP7xfFqlVbE2cRy0Rs4o3KS0JwzQVBwG85xge
REyPOFdGdhBY2P1FNRy0MDr6xr+D2ZOwxs63dG1nnAnWZg7qwoLgpZ4fESPD3PkA
1ZgKJc2zbSQ9fCPxt2W3mdVav66c6fsb7els2W2Iz7gERJSX
-----END CERTIFICATE-----";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions